44
55from .commands import Command , MotionCommand , KillCommand
66from . import input as _input
7+ from .types import ViFindDirection
78
89
910# ============================================================================
@@ -166,8 +167,8 @@ class vi_find_char(Command):
166167 """Start forward find (f). Waits for target character."""
167168 def do (self ) -> None :
168169 r = self .reader
169- r .pending_find_direction = "forward"
170- r .pending_find_inclusive = True
170+ r .vi_find . pending_direction = ViFindDirection . FORWARD
171+ r .vi_find . pending_inclusive = True
171172 trans = _input .KeymapTranslator (
172173 _find_char_keymap ,
173174 invalid_cls = "vi-find-cancel" ,
@@ -180,8 +181,8 @@ class vi_find_char_back(Command):
180181 """Start backward find (F). Waits for target character."""
181182 def do (self ) -> None :
182183 r = self .reader
183- r .pending_find_direction = "backward"
184- r .pending_find_inclusive = True
184+ r .vi_find . pending_direction = ViFindDirection . BACKWARD
185+ r .vi_find . pending_inclusive = True
185186 trans = _input .KeymapTranslator (
186187 _find_char_keymap ,
187188 invalid_cls = "vi-find-cancel" ,
@@ -194,8 +195,8 @@ class vi_till_char(Command):
194195 """Start forward till (t). Waits for target character."""
195196 def do (self ) -> None :
196197 r = self .reader
197- r .pending_find_direction = "forward"
198- r .pending_find_inclusive = False
198+ r .vi_find . pending_direction = ViFindDirection . FORWARD
199+ r .vi_find . pending_inclusive = False
199200 trans = _input .KeymapTranslator (
200201 _find_char_keymap ,
201202 invalid_cls = "vi-find-cancel" ,
@@ -208,8 +209,8 @@ class vi_till_char_back(Command):
208209 """Start backward till (T). Waits for target character."""
209210 def do (self ) -> None :
210211 r = self .reader
211- r .pending_find_direction = "backward"
212- r .pending_find_inclusive = False
212+ r .vi_find . pending_direction = ViFindDirection . BACKWARD
213+ r .vi_find . pending_inclusive = False
213214 trans = _input .KeymapTranslator (
214215 _find_char_keymap ,
215216 invalid_cls = "vi-find-cancel" ,
@@ -228,21 +229,21 @@ def do(self) -> None:
228229 if not char :
229230 return
230231
231- direction = r .pending_find_direction
232- inclusive = r .pending_find_inclusive
232+ direction = r .vi_find . pending_direction
233+ inclusive = r .vi_find . pending_inclusive
233234
234235 # Store for repeat with ; and ,
235- r .last_find_char = char
236- r .last_find_direction = direction
237- r .last_find_inclusive = inclusive
236+ r .vi_find . last_char = char
237+ r .vi_find . last_direction = direction
238+ r .vi_find . last_inclusive = inclusive
238239
239- r .pending_find_direction = None
240+ r .vi_find . pending_direction = None
240241 self ._execute_find (char , direction , inclusive )
241242
242- def _execute_find (self , char : str , direction : str | None , inclusive : bool ) -> None :
243+ def _execute_find (self , char : str , direction : ViFindDirection | None , inclusive : bool ) -> None :
243244 r = self .reader
244245 for _ in range (r .get_arg ()):
245- if direction == "forward" :
246+ if direction == ViFindDirection . FORWARD :
246247 new_pos = r .find_char_forward (char )
247248 if new_pos is not None :
248249 if not inclusive :
@@ -263,7 +264,7 @@ class vi_find_cancel(Command):
263264 def do (self ) -> None :
264265 r = self .reader
265266 r .pop_input_trans ()
266- r .pending_find_direction = None
267+ r .vi_find . pending_direction = None
267268
268269
269270# ============================================================================
@@ -274,15 +275,15 @@ class vi_repeat_find(MotionCommand):
274275 """Repeat last f/F/t/T in the same direction (;)."""
275276 def do (self ) -> None :
276277 r = self .reader
277- if r .last_find_char is None :
278+ if r .vi_find . last_char is None :
278279 return
279280
280- char = r .last_find_char
281- direction = r .last_find_direction
282- inclusive = r .last_find_inclusive
281+ char = r .vi_find . last_char
282+ direction = r .vi_find . last_direction
283+ inclusive = r .vi_find . last_inclusive
283284
284285 for _ in range (r .get_arg ()):
285- if direction == "forward" :
286+ if direction == ViFindDirection . FORWARD :
286287 new_pos = r .find_char_forward (char )
287288 if new_pos is not None :
288289 if not inclusive :
@@ -302,15 +303,17 @@ class vi_repeat_find_opposite(MotionCommand):
302303 """Repeat last f/F/t/T in opposite direction (,)."""
303304 def do (self ) -> None :
304305 r = self .reader
305- if r .last_find_char is None :
306+ if r .vi_find . last_char is None :
306307 return
307308
308- char = r .last_find_char
309- direction = "backward" if r .last_find_direction == "forward" else "forward"
310- inclusive = r .last_find_inclusive
309+ char = r .vi_find .last_char
310+ direction = (ViFindDirection .BACKWARD
311+ if r .vi_find .last_direction == ViFindDirection .FORWARD
312+ else ViFindDirection .FORWARD )
313+ inclusive = r .vi_find .last_inclusive
311314
312315 for _ in range (r .get_arg ()):
313- if direction == "forward" :
316+ if direction == ViFindDirection . FORWARD :
314317 new_pos = r .find_char_forward (char )
315318 if new_pos is not None :
316319 if not inclusive :
0 commit comments