From 7949bfc4903bfdda645ad780dd839ab191dc7f84 Mon Sep 17 00:00:00 2001 From: Whiskas101 Date: Wed, 25 Jun 2025 13:55:41 +0530 Subject: [PATCH 1/3] modified Visual line behaviour to mimic Vim's behaviour --- src/actions/motion.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/actions/motion.ts b/src/actions/motion.ts index 2eacb33aa34..eec5b1920e7 100755 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -1901,6 +1901,7 @@ export abstract class MoveInsideCharacter extends ExpandingSelection { firstIteration: boolean, lastIteration: boolean, ): Promise { + console.log("MoveInsideCharacter's execAction initiated"); const closingChar = PairMatcher.pairings[this.charToMatch].match; const [selStart, selEnd] = sorted(vimState.cursorStartPosition, position); @@ -1968,6 +1969,21 @@ export abstract class MoveInsideCharacter extends ExpandingSelection { vimState.recordedState.operatorPositionDiff = openPos.subtract(selStart); } + // Adjust for VisualLine mode: exclude the line containing the closing brace + // moves the cursor back to just within the brackets, accurately mirroring what + // Vim does for Vi{ Vi( Vi[ etc. + if ( + !this.includeSurrounding && + vimState.currentMode === Mode.VisualLine && + closePos.line > openPos.line + ) { + const adjustedLine = closePos.line - 1; + if (adjustedLine >= 0) { + const lineText = vimState.document.lineAt(adjustedLine).text; + closePos = new Position(adjustedLine, lineText.length); + } + } + // TODO: setting the cursor manually like this shouldn't be necessary (probably a Cursor, not Position, should be passed to `exec`) vimState.cursorStartPosition = openPos; return { From e308f3ff70f510ad7232a8d5641a2a20f76ef5be Mon Sep 17 00:00:00 2001 From: Whiskas101 Date: Wed, 25 Jun 2025 14:06:22 +0530 Subject: [PATCH 2/3] removed uneccessary log --- src/actions/motion.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/actions/motion.ts b/src/actions/motion.ts index eec5b1920e7..c3cb9c38f7f 100755 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -1901,7 +1901,6 @@ export abstract class MoveInsideCharacter extends ExpandingSelection { firstIteration: boolean, lastIteration: boolean, ): Promise { - console.log("MoveInsideCharacter's execAction initiated"); const closingChar = PairMatcher.pairings[this.charToMatch].match; const [selStart, selEnd] = sorted(vimState.cursorStartPosition, position); From e37233040609cd91644aef6dfdf73d6864e3911e Mon Sep 17 00:00:00 2001 From: Whiskas101 Date: Tue, 1 Jul 2025 16:25:41 +0530 Subject: [PATCH 3/3] removed debug stuff on test --- test/mode/modeVisualLine.test.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/mode/modeVisualLine.test.ts b/test/mode/modeVisualLine.test.ts index 767783acf4f..afb2268aac9 100644 --- a/test/mode/modeVisualLine.test.ts +++ b/test/mode/modeVisualLine.test.ts @@ -3,7 +3,7 @@ import * as assert from 'assert'; import { getAndUpdateModeHandler } from '../../extension'; import { Mode } from '../../src/mode/mode'; import { ModeHandler } from '../../src/mode/modeHandler'; -import { newTest } from '../testSimplifier'; +import { newTest, newTestOnly } from '../testSimplifier'; import { assertEqualLines, setupWorkspace } from './../testUtils'; suite('Mode Visual Line', () => { @@ -585,4 +585,26 @@ suite('Mode Visual Line', () => { }); } }); + + suite('Vi{ should not select the ending brace, if it is on a new line.', () => { + test('Vi{ selection content test', async () => { + // Insert the full block using insert mode simulation + await modeHandler.handleMultipleKeyEvents('i{\nsome text on new line\n}'.split('')); + + // Back to normal mode + await modeHandler.handleKeyEvent(''); + + // Move cursor to start of "some text..." + await modeHandler.handleMultipleKeyEvents(['g', 'g', 'j', 'l', 'l', 'l', 'l']); + + // Simulate Vi{ + await modeHandler.handleMultipleKeyEvents(['V', 'i', '{']); + + const doc = modeHandler.vimState.editor.document; + const sel = modeHandler.vimState.editor.selection; + const selectedText = doc.getText(sel); + + assert.strictEqual(selectedText, ' some text on new line'); + }); + }); });