@@ -24,6 +24,10 @@ static Navigator::ActionDef navigation_actions[] = {
2424 {" right_by_char" , &Navigator::RightByChar},
2525 {" left_by_syllable" , &Navigator::LeftBySyllable},
2626 {" right_by_syllable" , &Navigator::RightBySyllable},
27+ {" left_by_char_no_loop" , &Navigator::LeftByCharNoLoop},
28+ {" right_by_char_no_loop" , &Navigator::RightByCharNoLoop},
29+ {" left_by_syllable_no_loop" , &Navigator::LeftBySyllableNoLoop},
30+ {" right_by_syllable_no_loop" , &Navigator::RightBySyllableNoLoop},
2731 {" home" , &Navigator::Home},
2832 {" end" , &Navigator::End},
2933 Navigator::kActionNoop };
@@ -89,7 +93,14 @@ void Navigator::OnSelect(Context* ctx) {
8993bool Navigator::LeftBySyllable (Context* ctx) {
9094 BeginMove (ctx);
9195 size_t confirmed_pos = ctx->composition ().GetConfirmedPosition ();
92- JumpLeft (ctx, confirmed_pos) || GoHome (ctx);
96+ JumpLeft (ctx, confirmed_pos, true ) || GoHome (ctx);
97+ return true ;
98+ }
99+
100+ bool Navigator::LeftBySyllableNoLoop (Context* ctx) {
101+ BeginMove (ctx);
102+ size_t confirmed_pos = ctx->composition ().GetConfirmedPosition ();
103+ JumpLeft (ctx, confirmed_pos, false );
93104 return true ;
94105}
95106
@@ -99,13 +110,19 @@ bool Navigator::LeftByChar(Context* ctx) {
99110 return true ;
100111}
101112
113+ bool Navigator::LeftByCharNoLoop (Context* ctx) {
114+ BeginMove (ctx);
115+ MoveLeft (ctx);
116+ return true ;
117+ }
118+
102119bool Navigator::Rewind (Context* ctx) {
103120 BeginMove (ctx);
104121 // take a jump leftwards when there are multiple spans,
105122 // but not from the middle of a span.
106123 if (spans_.Count () > 1 && spans_.HasVertex (ctx->caret_pos ())) {
107124 size_t confirmed_pos = ctx->composition ().GetConfirmedPosition ();
108- JumpLeft (ctx, confirmed_pos);
125+ JumpLeft (ctx, confirmed_pos, true );
109126 } else {
110127 MoveLeft (ctx);
111128 }
@@ -116,7 +133,7 @@ bool Navigator::Forward(Context* ctx) {
116133 BeginMove (ctx);
117134 if (spans_.Count () > 1 && spans_.HasVertex (ctx->caret_pos ())) {
118135 size_t confirmed_pos = ctx->composition ().GetConfirmedPosition ();
119- JumpRight (ctx, confirmed_pos);
136+ JumpRight (ctx, confirmed_pos, true );
120137 } else {
121138 MoveRight (ctx);
122139 }
@@ -126,7 +143,13 @@ bool Navigator::Forward(Context* ctx) {
126143bool Navigator::RightBySyllable (Context* ctx) {
127144 BeginMove (ctx);
128145 size_t confirmed_pos = ctx->composition ().GetConfirmedPosition ();
129- JumpRight (ctx, confirmed_pos) || GoToEnd (ctx);
146+ JumpRight (ctx, confirmed_pos, true ) || GoToEnd (ctx);
147+ return true ;
148+ }
149+
150+ bool Navigator::RightBySyllableNoLoop (Context* ctx) {
151+ BeginMove (ctx);
152+ JumpRight (ctx, 0 , false );
130153 return true ;
131154}
132155
@@ -136,6 +159,12 @@ bool Navigator::RightByChar(Context* ctx) {
136159 return true ;
137160}
138161
162+ bool Navigator::RightByCharNoLoop (Context* ctx) {
163+ BeginMove (ctx);
164+ MoveRight (ctx);
165+ return true ;
166+ }
167+
139168bool Navigator::Home (Context* ctx) {
140169 BeginMove (ctx);
141170 GoHome (ctx);
@@ -164,11 +193,11 @@ void Navigator::BeginMove(Context* ctx) {
164193 }
165194}
166195
167- bool Navigator::JumpLeft (Context* ctx, size_t start_pos) {
196+ bool Navigator::JumpLeft (Context* ctx, size_t start_pos, bool loop ) {
168197 DLOG (INFO) << " jump left." ;
169198 size_t caret_pos = ctx->caret_pos ();
170- if (caret_pos <= start_pos) {
171- caret_pos = ctx->input ().length (); // rewind
199+ if (loop && caret_pos <= start_pos) {
200+ caret_pos = ctx->input ().length ();
172201 }
173202 size_t stop = spans_.PreviousStop (caret_pos);
174203 if (stop < start_pos) {
@@ -181,11 +210,11 @@ bool Navigator::JumpLeft(Context* ctx, size_t start_pos) {
181210 return false ;
182211}
183212
184- bool Navigator::JumpRight (Context* ctx, size_t start_pos) {
213+ bool Navigator::JumpRight (Context* ctx, size_t start_pos, bool loop ) {
185214 DLOG (INFO) << " jump right." ;
186215 size_t caret_pos = ctx->caret_pos ();
187- if (caret_pos == ctx->input ().length ()) {
188- caret_pos = start_pos; // rewind
216+ if (loop && caret_pos == ctx->input ().length ()) {
217+ caret_pos = start_pos;
189218 }
190219 size_t stop = spans_.NextStop (caret_pos);
191220 if (stop != caret_pos) {
0 commit comments