Skip to content

Commit

Permalink
Merge pull request #67 from usernamehw/cursor_inside_parenthesis
Browse files Browse the repository at this point in the history
Move cursor inside parenthesis for function-like values
  • Loading branch information
aeschli authored Feb 7, 2018
2 parents 618646b + 3239a2b commit 953c51d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/services/cssCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 953c51d

Please sign in to comment.