@@ -38,9 +38,9 @@ class Movement {
38
38
39
39
// Run a movement. This is the core movement method, all movements happen here. For convenience, the
40
40
// following three argument forms are supported:
41
- // @ runMovement "forward word"
42
- // @ runMovement ["forward", "word"]
43
- // @ runMovement "forward", "word"
41
+ // runMovement( "forward word")
42
+ // runMovement( ["forward", "word"])
43
+ // runMovement( "forward", "word")
44
44
//
45
45
// The granularities are word, "character", "line", "lineboundary", "sentence" and "paragraph". In addition,
46
46
// we implement the pseudo granularity "vimword", which implements vim-like word movement (e.g. "w").
@@ -56,10 +56,10 @@ class Movement {
56
56
// character-by-character.
57
57
if ( ( granularity === vimword ) && ( direction === forward ) ) {
58
58
while ( this . nextCharacterIsWordCharacter ( ) )
59
- if ( ! this . runMovements ( [ forward , character ] ) )
59
+ if ( this . extendByOneCharacter ( forward ) === 0 )
60
60
return ;
61
61
while ( this . getNextForwardCharacter ( ) && ! this . nextCharacterIsWordCharacter ( ) )
62
- if ( ! this . runMovements ( [ forward , character ] ) )
62
+ if ( this . extendByOneCharacter ( forward ) === 0 )
63
63
return ;
64
64
} else if ( granularity === vimword ) {
65
65
this . selection . modify ( this . alterMethod , backward , word ) ;
@@ -68,42 +68,16 @@ class Movement {
68
68
// As above, we implement this character-by-character to get consistent behavior on Windows and Linux.
69
69
if ( ( granularity === word ) && ( direction === forward ) ) {
70
70
while ( this . getNextForwardCharacter ( ) && ! this . nextCharacterIsWordCharacter ( ) )
71
- if ( ! this . runMovements ( [ forward , character ] ) )
71
+ if ( this . extendByOneCharacter ( forward ) === 0 )
72
72
return ;
73
73
while ( this . nextCharacterIsWordCharacter ( ) )
74
- if ( ! this . runMovements ( [ forward , character ] ) )
74
+ if ( this . extendByOneCharacter ( forward ) === 0 )
75
75
return ;
76
76
} else {
77
77
return this . selection . modify ( this . alterMethod , direction , granularity ) ;
78
78
}
79
79
}
80
80
81
- // Return a simple comparable value which depends on various aspects of the selection. This is used to
82
- // detect, after a movement, whether the selection has changed.
83
- hashSelection ( ) {
84
- const range = this . selection . getRangeAt ( 0 ) ;
85
- return [ this . selection . toString ( ) . length ,
86
- range . anchorOffset ,
87
- range . focusOffset ,
88
- this . selection . extentOffset ,
89
- this . selection . baseOffset ] . join ( "/" ) ;
90
- }
91
-
92
- // Call a function; return true if the selection changed, false otherwise.
93
- selectionChanged ( func ) {
94
- const before = this . hashSelection ( ) ;
95
- func ( ) ;
96
- return this . hashSelection ( ) !== before ;
97
- }
98
-
99
- // Run a sequence of movements, stopping if a movement fails to change the selection.
100
- runMovements ( ...movements ) {
101
- for ( var movement of movements )
102
- if ( ! this . selectionChanged ( ( ) => this . runMovement ( movement ) ) )
103
- return false ;
104
- return true ;
105
- }
106
-
107
81
// Swap the anchor node/offset and the focus node/offset. This allows us to work with both ends of the
108
82
// selection, and implements "o" for visual mode.
109
83
reverseSelection ( ) {
0 commit comments