Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sodium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frans Klaver
sodium
Commits
7956618c
Commit
7956618c
authored
2 years ago
by
Ktoks
Browse files
Options
Downloads
Patches
Plain Diff
Added e, w, $ functionality; added 0 stub
parent
184ab145
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caret/movement.rs
+58
-15
58 additions, 15 deletions
src/caret/movement.rs
src/core/exec.rs
+31
-8
31 additions, 8 deletions
src/core/exec.rs
with
89 additions
and
23 deletions
src/caret/movement.rs
+
58
−
15
View file @
7956618c
...
...
@@ -48,7 +48,6 @@ impl Editor {
}
}
}
// }
}
/// Get the position before a given position, i.e. a generalisation .before(). Includes
...
...
@@ -90,7 +89,18 @@ impl Editor {
pub
fn
right_unbounded
(
&
self
,
n
:
usize
)
->
(
isize
,
isize
)
{
((
self
.x
()
+
n
)
as
isize
,
self
.y
()
as
isize
)
}
/// Get the position of the first word right of the cursor (horizontally bounded)
#[inline]
pub
fn
next_word
(
&
self
,
n
:
usize
,
tight
:
bool
)
->
(
usize
,
usize
)
{
let
next_n
=
self
.next_word_forward
(
n
);
self
.bound_hor
((
self
.x
()
+
(
next_n
),
self
.y
()),
tight
)
}
/// Get the position of the first word end right of the cursor (horizontally bounded)
#[inline]
pub
fn
next_word_end
(
&
self
,
n
:
usize
,
tight
:
bool
)
->
(
usize
,
usize
)
{
let
next_n
=
self
.next_word_end_forward
(
n
);
self
.bound_hor
((
self
.x
()
+
(
next_n
),
self
.y
()),
tight
)
}
/// Get the position of the character left to the cursor (horizontally bounded)
#[inline]
pub
fn
left
(
&
self
,
n
:
usize
)
->
(
usize
,
usize
)
{
...
...
@@ -180,27 +190,60 @@ impl Editor {
None
}
/// Get next WORD forward
/// Get
end of
next WORD forward
/// "A WORD consists of a sequence of non-blank characters, separated with
/// whitespace. An empty line is also considered to be a WORD."
pub
fn
_next_word_forward
(
&
self
,
n
:
usize
)
->
Option
<
usize
>
{
let
mut
dn
=
0
;
let
mut
x
=
self
.x
();
pub
fn
next_word_forward
(
&
self
,
n_opt
:
usize
)
->
usize
{
let
mut
word_count
:
usize
=
0
;
let
x
:
usize
=
self
.x
();
let
mut
has_ws
=
false
;
for
(
i
,
c
h
)
in
self
.buffers
.current_buffer
()[
self
.y
()]
for
(
i
,
c
urrent_char
)
in
self
.buffers
.current_buffer
()[
self
.y
()]
.chars
()
.skip
(
x
)
.enumerate
()
{
if
ch
.is_whitespace
()
{
dn
+=
1
;
if
dn
==
n
{
x
+=
i
+
1
;
return
Some
(
x
);
{
if
current_char
.is_whitespace
()
{
has_ws
=
true
;
}
else
if
has_ws
&&
!
current_char
.is_whitespace
()
{
word_count
+=
1
;
if
word_count
<
n_opt
-
1
{
has_ws
=
false
;
}
else
{
return
i
;
}
}
}
0
}
None
/// Get beginning of next WORD forward
/// "A WORD consists of a sequence of non-blank characters, separated with
/// whitespace. An empty line is also considered to be a WORD."
pub
fn
next_word_end_forward
(
&
self
,
n_opt
:
usize
)
->
usize
{
let
mut
word_count
:
usize
=
0
;
let
x
:
usize
=
self
.x
();
let
mut
word_char
:
bool
=
true
;
let
mut
last
:
usize
=
0
;
for
(
i
,
current_char
)
in
self
.buffers
.current_buffer
()[
self
.y
()]
.chars
()
.skip
(
x
)
.enumerate
()
{
// if a word_char
if
!
current_char
.is_whitespace
()
{
word_char
=
true
;
last
=
i
;
word_count
+=
1
;
}
else
if
current_char
.is_whitespace
()
{
if
word_char
&&
word_count
>
n_opt
{
return
i
-
1
;
}
word_char
=
false
;
}
}
last
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/core/exec.rs
+
31
−
8
View file @
7956618c
...
...
@@ -103,6 +103,16 @@ impl Editor {
self
.goto
(
right
);
mov
=
true
;
}
(
Command
(
Normal
),
Char
(
'w'
))
=>
{
let
next_word
=
self
.next_word
(
n
,
true
);
self
.goto
(
next_word
);
mov
=
true
;
}
(
Command
(
Normal
),
Char
(
'e'
))
=>
{
let
next_word
=
self
.next_word_end
(
n
,
true
);
self
.goto
(
next_word
);
mov
=
true
;
}
(
Command
(
Normal
),
Char
(
'J'
))
=>
{
let
down
=
self
.down
(
15
*
n
);
self
.goto
(
down
);
...
...
@@ -130,7 +140,20 @@ impl Editor {
mov
=
true
;
}
}
(
Command
(
Normal
),
Char
(
'$'
))
=>
{
if
self
.buffers
.current_buffer
()[
self
.y
()]
.len
()
!=
0
{
let
ln_end
=
(
self
.buffers
.current_buffer
()[
self
.y
()]
.len
()
-
1
,
self
.y
());
self
.goto
(
ln_end
);
mov
=
true
;
}
}
(
Command
(
Normal
),
Char
(
'H'
))
=>
{
println!
(
"H pressed"
);
self
.cursor_mut
()
.x
=
0
;
mov
=
true
;
}
(
Command
(
Normal
),
Char
(
'0'
))
=>
{
println!
(
"0 pressed"
);
self
.cursor_mut
()
.x
=
0
;
mov
=
true
;
}
...
...
@@ -230,14 +253,14 @@ impl Editor {
mov
=
true
;
}
}
(
Command
(
Normal
),
Char
(
'W'
))
=>
{
let
pos
=
self
.
_
next_word_forward
(
n
);
if
let
Some
(
p
)
=
pos
{
let
y
=
self
.y
();
self
.goto
((
p
,
y
));
mov
=
true
;
}
}
//
(Command(Normal), Char('W')) => {
//
let pos = self.next_word_forward(n);
//
if let Some(p) = pos {
//
let y = self.y();
//
self.goto((p, y));
//
mov = true;
//
}
//
}
(
Command
(
Normal
),
Char
(
';'
))
=>
{
self
.cursor_mut
()
.mode
=
Mode
::
Primitive
(
PrimitiveMode
::
Prompt
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment