Skip to content

Commit 025c9fa

Browse files
committed
adjust logic
1 parent dd85854 commit 025c9fa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lsptoolshost/autoInsert/onAutoInsert.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,18 @@ export function registerOnAutoInsert(languageServer: RoslynLanguageServer, langu
5757
// Regular expression to match all whitespace characters except the newline character
5858
let changeTrimmed = change.text.replace(/[^\S\n]+/g, '');
5959

60+
// If the change is empty after removing whitespace, we don't need to process it.
61+
if (changeTrimmed.length === 0) {
62+
return;
63+
}
64+
6065
// When hitting enter between braces, we can end up with two new lines added (one to move the cursor down to an empty line,
61-
// and another to move the close brace to a new line below that). We still want to trigger on auto insert here, so if we
62-
// have a whitespace only edit (meaning its new lines only) with multiple characters, we reduce it to a single newline.
63-
if (changeTrimmed.length > 1 && changeTrimmed.trim() === '') {
64-
changeTrimmed = [...new Set(changeTrimmed)].join('');
66+
// and another to move the close brace to a new line below that). We want to detect that edit as a single new line trigger.
67+
//
68+
// Since we already removed all whitespace except new lines above, we can just trim the string to remove new lines as well
69+
// and check if there is anything left. If not, we know the change is just whitespace and new lines and can set the trigger to the new line character.
70+
if (changeTrimmed.trim() === '') {
71+
changeTrimmed = '\n';
6572
}
6673

6774
if (!vsTriggerCharacters.includes(changeTrimmed)) {

0 commit comments

Comments
 (0)