@@ -951,8 +951,16 @@ def keyPressEvent(self, event: QKeyEvent) -> None:
951951 """
952952 self ._lastActive = time ()
953953
954- if CONFIG .vimMode :
955- self ._handleVimKeyPress (event )
954+ if CONFIG .vimMode and self ._vim .mode != nwVimMode .INSERT :
955+ # Process Vim modes
956+ if self ._handleVimNormalModeModeSwitching (event ):
957+ return
958+
959+ if self ._vim .mode in (nwVimMode .VISUAL , nwVimMode .VLINE ):
960+ self ._handleVimVisualMode (event )
961+ else :
962+ self ._handleVimNormalMode (event )
963+
956964 return
957965
958966 if self .docSearch .anyFocus () and event .key () in self .ENTER_KEYS :
@@ -2004,7 +2012,7 @@ def _handleVimNormalMode(self, event: QKeyEvent) -> None:
20042012 self .setTextCursor (cursor )
20052013 self ._vim .resetCommand ()
20062014
2007- if command == "db" :
2015+ elif command == "db" :
20082016 cursor .beginEditBlock ()
20092017 cursor .movePosition (QtMovePreviousWord , QtKeepAnchor )
20102018 self ._vim .yankToInternal (cursor .selectedText ())
@@ -2013,7 +2021,7 @@ def _handleVimNormalMode(self, event: QKeyEvent) -> None:
20132021 self .setTextCursor (cursor )
20142022 self ._vim .resetCommand ()
20152023
2016- if command == "de" :
2024+ elif command == "de" :
20172025 cursor .beginEditBlock ()
20182026 # Extend selection to end of current/next word
20192027 origPos = cursor .position ()
@@ -2029,7 +2037,7 @@ def _handleVimNormalMode(self, event: QKeyEvent) -> None:
20292037 self .setTextCursor (cursor )
20302038 self ._vim .resetCommand ()
20312039
2032- if command == "d$" :
2040+ elif command == "d$" :
20332041 cursor .beginEditBlock ()
20342042 cursor .movePosition (QtMoveEndOfLine , QtKeepAnchor )
20352043 self ._vim .yankToInternal (cursor .selectedText ())
@@ -2038,7 +2046,7 @@ def _handleVimNormalMode(self, event: QKeyEvent) -> None:
20382046 self .setTextCursor (cursor )
20392047 self ._vim .resetCommand ()
20402048
2041- if command == "yw" :
2049+ elif command == "yw" :
20422050 cursor .beginEditBlock ()
20432051 cursor .movePosition (QtMoveNextWord , QtKeepAnchor )
20442052 self ._vim .yankToInternal (cursor .selectedText ())
@@ -2057,7 +2065,7 @@ def _handleVimNormalMode(self, event: QKeyEvent) -> None:
20572065 self .setTextCursor (cursor )
20582066 self ._vim .resetCommand ()
20592067
2060- if command == "yy" :
2068+ elif command == "yy" :
20612069 cursor .select (QtSelectLine )
20622070 self ._vim .yankToInternal (cursor .selectedText ())
20632071 cursor .clearSelection ()
@@ -2230,25 +2238,6 @@ def _handleVimVisualMode(self, event: QKeyEvent) -> None:
22302238 cursor .movePosition (QtMoveEnd , QtKeepAnchor )
22312239 self .setTextCursor (cursor )
22322240
2233- def _handleVimKeyPress (self , event : QKeyEvent ) -> None :
2234- """Handle key events for Vim mode.
2235- If vim mode is not enabled, typing behaves as normal.
2236- """
2237- # --- INSERT mode, bypass ---
2238- if self ._vim .mode == nwVimMode .INSERT :
2239- super ().keyPressEvent (event )
2240- return # Normal typing
2241-
2242- if self ._handleVimNormalModeModeSwitching (event ):
2243- return
2244-
2245- if self ._vim .mode in (nwVimMode .VISUAL , nwVimMode .VLINE ):
2246- self ._handleVimVisualMode (event )
2247- else :
2248- self ._handleVimNormalMode (event )
2249-
2250- return
2251-
22522241 ##
22532242 # Internal Functions
22542243 ##
0 commit comments