Fix caret mode w
and e
movements
#4632
Merged
+16
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fix SyntaxError on Selection.modify() due to invalid granularity parameter 'vimword' due to missing return statements
Fix 'w' and 'e' not working in Caret Mode
w
ande
in caret mode #3772b
works on caret mode butw
does not. #4615Since forward movements for 'word' and 'vimword' use char-by-char custom logic which extends the selection range, we need to collapse the selection to the end, if we're in Caret Mode instead of Visual Mode.
Also removed dead code section for 'backward vimword', as there is no binding that ever uses that and the implemented logic is equal to 'backward word' ('b' key).
Bug analysis regarding the SyntaxError (commit c0c6f49):
Selection.modify()
:SyntaxError
and instead will fail / return silently when an invalidgranularity
is givenword
andvimword
forward word
is triggered withe
to jump forward to the end of a wordbackward word
is triggered byb
to jump back to the start of a wordforward vimword
is triggered withw
to jump forward right before the start of the next word (therefore including non-word characters after the original word's end)backward vimword
, but there is a code section that handles that case (and does the same asbackward word
) (P.S.: I've removed this section in the follow-up commit that fixes caret mode behavior)return
statements in several places incontent_scripts/mode_visual.js
in functionMovement.runMovement
lead to theSyntaxError
vimword
functionality runs properlyforward vimword
advances char-by-char and thus doesn't rely onmodify
'sgranularity
parameterbackward vimword
has no binding, but would work fine, since it replaces thegranularity
value byword
when handing it over as a parameter toSelection.modify()
return
statements after their work is doneelse
section at the very end being called for thevimword
cases which have already been handledImplementation notes regarding the SyntaxError
return
statements to thevimword
code sectionsreturn
statements to the remainingif else
blocks to avoid this problem in case the function gets extended in the futurevimword
andword
since they look confusingly similar at the first glanceelse
sections and have the code as consecutiveif() { doSomething(); return; }
blocks, since each block is meant toreturn
when done.modify()
despite the function not having a return type, so I moved thereturn
to a separate line instead