From 23cf01a5aba11403d788898c09241d562f2f2294 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sun, 21 Apr 2024 23:30:42 +0300 Subject: [PATCH] fix: fix jsx attribute shortcut replace range fixes #195 --- typescript/src/completions/jsxAttributes.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/typescript/src/completions/jsxAttributes.ts b/typescript/src/completions/jsxAttributes.ts index 976b821..3eceb5b 100644 --- a/typescript/src/completions/jsxAttributes.ts +++ b/typescript/src/completions/jsxAttributes.ts @@ -11,6 +11,7 @@ export default ( sourceFile: ts.SourceFile, jsxCompletionsMap: Configuration['jsxCompletionsMap'], ): ts.CompletionEntry[] => { + const originalNode = node // ++ patch with jsxCompletionsMap // -- don't // { if (locals.includes(entry.name)) { const insertText = `${entry.name}={${entry.name}}` - const additionalSuggestions = { + const pos = attrib ? attrib.end - attrib.getWidth() : 0 + const additionalSuggestions: ts.CompletionEntry = { ...entry, name: insertText, insertText, + replacementSpan: attrib + ? { + start: pos, + length: attrib.end - pos, + } + : undefined, } return enableJsxAttributesShortcuts === 'after' ? [entry, additionalSuggestions] : [additionalSuggestions, entry] }