Skip to content
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

Fix going into visual mode when filling out snippets with adjacent placeholders etc #9239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

semicube
Copy link
Contributor

@semicube semicube commented Sep 3, 2024

What this PR does / why we need it:

Fixes going into visual mode on certain placeholders when you fill out vscode user snippets. Particularly this occurs when the placeholders are placed adjacent to each other (not seperated by a character, see Issue #9236), or when the snippet starts from a placeholder (see Issues #5969, #7068).

Note on the fix:

I noticed that in each of these placeholder cases where the cursor goes into visual mode, isSnippetSelectionChange() inside ModeHandler.handleSelectionChange() returns false even though it is a snippet selection.

Modifying isSnippetSelectionChange() to only consider the previous cursors that represent a selection (c.start and c.stop are not equal) when comparing with e.selections, seems to have fixed the issue.

Which issue(s) this PR fixes

Fixes #9236, #7068, #6465, #5969

Special notes for your reviewer:

@HenryTSZ
Copy link
Contributor

HenryTSZ commented Sep 9, 2024

add test case for this

test('handles snippet', async () => {
await modeHandler.handleKeyEvent('i');
await vscode.commands.executeCommand('editor.action.insertSnippet', {
snippet: '${3:foo} ${1:bar} ${2:baz}',
});
await modeHandler.handleMultipleKeyEvents(['(', 'o', 'n', 'e']);
await vscode.commands.executeCommand('jumpToNextSnippetPlaceholder');
await modeHandler.handleMultipleKeyEvents(['<', 't', 'w', 'o']);
await vscode.commands.executeCommand('jumpToNextSnippetPlaceholder');
await modeHandler.handleKeyEvent('`');
assertEqualLines(['`foo` (one) <two>']);
assert.strictEqual(modeHandler.currentMode, Mode.Insert);
});

append after this

    test('handles snippet when filling out snippets with adjacent placeholder', async () => {
      await modeHandler.handleKeyEvent('i');
      await vscode.commands.executeCommand('editor.action.insertSnippet', {
        snippet: '${3:foo} ${1:bar}${2:baz}',
      });
      await modeHandler.handleMultipleKeyEvents(['o', 'n', 'e']);
      await vscode.commands.executeCommand('jumpToNextSnippetPlaceholder');
      assertEqualLines(['foo onebaz']);
      assert.strictEqual(modeHandler.currentMode, Mode.Insert);
    });

    test('handles snippet with multiple cursors and start with a placeholder', async () => {
      await modeHandler.handleKeyEvent('i');
      await vscode.commands.executeCommand('editor.action.insertSnippet', {
        snippet: '${1:bar} ${2:baz} $1',
      });
      assertEqualLines(['bar baz bar']);
      assert.strictEqual(modeHandler.currentMode, Mode.Insert);
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vim unexpectedly turns into visual mode for adjacent snippet placeholders
2 participants