-
Notifications
You must be signed in to change notification settings - Fork 250
use onDidChangeCursorPosition for keeping cursor in line #770
Conversation
This PR also fixes #2, as far as I can tell. Yay for fixing the longest-outstanding issue of vim-mode. 8-) |
This is terrific! It's nice when the fix also deletes code scattered all over the place. Minor conflicts with #591. Both should be merged. |
fixes #579 |
924f680
to
faf009d
Compare
@@ -654,6 +662,16 @@ class VimState | |||
text = @getRegister(name)?.text | |||
@editor.insertText(text) if text? | |||
|
|||
ensureCursorIsWithinLine: (cursor) => | |||
return if @processing or @mode is 'visual' or @mode is 'insert' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit about why this @processing
variable is needed? Without looking into this too deeply, I would think that we could just return unless @mode is 'normal'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some motions, esp. with counts, invoke several Atom motions, each notifies us about cursor movement, and they all can happen in normal mode. We don't want to interfere until that's done.
But since it needs explanation, it could be written clearer or better; suggestions welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But 'not "normal"' should be OK instead of two comparisons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's in the new commit, which also adds more @processing
8-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to interfere until that's done.
I see. I think this is a fine solution actually.
Very good idea. |
Ok great! Congratulations on closing issue #2. |
use onDidChangeCursorPosition for keeping cursor in line
Currently, motions would individually ensure that cursor doesn't end up after the last character of a line. This fails in a number of circumstances, e.g. with mouse clicks to move/add a cursor, and with specs that
setCursorBufferPosition
to put the cursor where it should never be.This PR reacts to any cursor movement with TextEditor's
onDidChangeCursorPosition
and any cursor addition withonDidAddCursor
and makes sure the cursor never goes where it doesn't belong.The PR also fixes some tests that expected the cursor after the last character in command mode, and removes some outdated spec comments.