-
Notifications
You must be signed in to change notification settings - Fork 46
feat: add g_ motion (move to last non-blank character) #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -541,6 +541,24 @@ testVim('g0_g$', function(cm, vim, helpers) { | |
| is(!/\.$/.test(cm.getValue())); | ||
|
|
||
| },{ lineNumbers: false, lineWrapping:true, value: 'This line is long to test movement of g$ and g0 over wrapped lines.' }); | ||
| testVim('g_', function(cm, vim, helpers) { | ||
| // Test basic g_ on line with trailing spaces | ||
| cm.setCursor(0, 0); | ||
| helpers.doKeys('g', '_'); | ||
| helpers.assertCursorAt(0, 2); | ||
| // Test g_ on line without trailing spaces | ||
| cm.setCursor(1, 0); | ||
| helpers.doKeys('g', '_'); | ||
| helpers.assertCursorAt(1, 2); | ||
| // Test g_ with count (2g_ goes to last non-whitespace of next line) | ||
| cm.setCursor(0, 0); | ||
| helpers.doKeys('2', 'g', '_'); | ||
| helpers.assertCursorAt(1, 2); | ||
| // Test dg_ deletes to last non-whitespace (preserving trailing spaces) | ||
| cm.setCursor(0, 0); | ||
| helpers.doKeys('d', 'g', '_'); | ||
| eq(' \nfoo', cm.getValue()); | ||
| }, { value: 'foo \nfoo' }); | ||
|
Comment on lines
+544
to
+561
|
||
| testVim('}', function(cm, vim, helpers) { | ||
| cm.setCursor(0, 0); | ||
| helpers.doKeys('}'); | ||
|
|
||
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.
moveToLastNonWhiteSpaceCharactercomputesline = head.line + motionArgs.repeat - 1and immediately callscm.getLine(line)without clipping the line number to the document bounds. With a large count (e.g.100g_near EOF) this can produce an out-of-rangelineand return aPoswith an invalid line, which then flows into operator selections (dg_, etc.) without being clipped and can break selection logic. Clamp the target line to[cm.firstLine(), cm.lastLine()](or usecm.clipPos(new Pos(line, 0)).line) before callinggetLineand before returning thePos.