From 3239a2bdcf43a4f56b2f3645cb4642e433c3ffe3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 6 Feb 2018 20:51:02 +0300 Subject: [PATCH] Move cursor inside parenthesis for function-like values --- src/services/cssCompletion.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/services/cssCompletion.ts b/src/services/cssCompletion.ts index 4b646bc9..59f7ab23 100644 --- a/src/services/cssCompletion.ts +++ b/src/services/cssCompletion.ts @@ -489,7 +489,7 @@ export class CSSCompletion { protected getImageProposals(entry: languageFacts.IEntry, existingNode: nodes.Node, result: CompletionList): CompletionList { for (let image in languageFacts.imageFunctions) { - let insertText = image.replace(/\(\)$/, "($1)"); + let insertText = moveCursorInsideParenthesis(image); result.items.push({ label: image, documentation: languageFacts.imageFunctions[image], @@ -503,7 +503,7 @@ export class CSSCompletion { protected getTimingFunctionProposals(entry: languageFacts.IEntry, existingNode: nodes.Node, result: CompletionList): CompletionList { for (let timing in languageFacts.transitionTimingFunctions) { - let insertText = timing.replace(/\(\)$/, "($1)"); + let insertText = moveCursorInsideParenthesis(timing); result.items.push({ label: timing, documentation: languageFacts.transitionTimingFunctions[timing], @@ -517,7 +517,7 @@ export class CSSCompletion { protected getBasicShapeProposals(entry: languageFacts.IEntry, existingNode: nodes.Node, result: CompletionList): CompletionList { for (let shape in languageFacts.basicShapeFunctions) { - let insertText = shape.replace(/\(\)$/, "($1)"); + let insertText = moveCursorInsideParenthesis(shape); result.items.push({ label: shape, documentation: languageFacts.basicShapeFunctions[shape], @@ -584,11 +584,13 @@ export class CSSCompletion { for (let entry of languageFacts.getPseudoClasses()) { if (entry.browsers.onCodeComplete) { + let insertText = moveCursorInsideParenthesis(entry.name); let item: CompletionItem = { label: entry.name, - textEdit: TextEdit.replace(this.getCompletionRange(existingNode), entry.name), + textEdit: TextEdit.replace(this.getCompletionRange(existingNode), insertText), documentation: languageFacts.getEntryDescription(entry), - kind: CompletionItemKind.Function + kind: CompletionItemKind.Function, + insertTextFormat: entry.name !== insertText ? SnippetFormat : void 0 }; if (strings.startsWith(entry.name, ':-')) { item.sortText = 'x'; @@ -598,11 +600,13 @@ export class CSSCompletion { } for (let entry of languageFacts.getPseudoElements()) { if (entry.browsers.onCodeComplete) { + let insertText = moveCursorInsideParenthesis(entry.name); let item: CompletionItem = { label: entry.name, - textEdit: TextEdit.replace(this.getCompletionRange(existingNode), entry.name), + textEdit: TextEdit.replace(this.getCompletionRange(existingNode), insertText), documentation: languageFacts.getEntryDescription(entry), - kind: CompletionItemKind.Function + kind: CompletionItemKind.Function, + insertTextFormat: entry.name !== insertText ? SnippetFormat : void 0 }; if (strings.startsWith(entry.name, '::-')) { item.sortText = 'x'; @@ -816,6 +820,10 @@ class Set { } } +function moveCursorInsideParenthesis(text: string): string { + return text.replace(/\(\)$/, "($1)"); +} + function collectValues(styleSheet: nodes.Stylesheet, declaration: nodes.Declaration): Set { const fullPropertyName = declaration.getFullPropertyName(); const entries: Set = new Set();