Skip to content

Commit 91dd39d

Browse files
authored
Merge pull request #125 from docs/lucascosti/fix-copier-bug
Fix copier bug for article frontmatter versioning
2 parents 277e6e6 + 8744c23 commit 91dd39d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

copier.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,31 @@ function copyMain() {
2525
startSelection = endSelection = editor.document.offsetAt(editor.selection.anchor);
2626
// Get the position of the start of the reusable
2727
// Do this by parsing each character from the cursor leftwards
28-
// until reaching "{"
29-
for (let parseCharacter = ""; parseCharacter != "{"; startSelection--) {
28+
// until reaching "{" (for variables/reusables), or quotes or
29+
// a colon (:) for article feature flag versioning
30+
for (let parseCharacter = ""; !parseCharacter.match(/{|'|"|:/); startSelection--) {
3031
let startPosition = editor.document.positionAt(startSelection);
3132
let stopPosition = editor.document.positionAt(startSelection+1);
3233
let textRange = new vscode.Range(startPosition, stopPosition);
3334
parseCharacter = editor.document.getText(textRange);
34-
// console.log('startSelection = ' + startSelection + '; parseCharacter = ' + parseCharacter);
35+
// console.log('startSelection = ' + startSelection + '; parseCharacter = ' + parseCharacter);
36+
// If it's an article feature flag versioning, move rightwards one or two.
37+
if (parseCharacter.match(/'|"/)) { startSelection++; }
38+
else if (parseCharacter.match(/:/)) { startSelection = startSelection + 2; }
3539
moveLeftBy = endSelection - startSelection;
3640
// console.log('move left by = ' + moveLeftBy);
3741
}
3842
// Get the position of the end of the reusable by parsing forwards
39-
for (let parseCharacter = ""; parseCharacter != "}"; endSelection++) {
43+
// until reaching "}" (for variables/reusables), or quotes or
44+
// a line end for article feature flag versioning
45+
for (let parseCharacter = ""; !parseCharacter.match(/}|'|"|\n/); endSelection++) {
4046
let startPosition = editor.document.positionAt(endSelection);
4147
let stopPosition = editor.document.positionAt(endSelection+1);
4248
let textRange = new vscode.Range(startPosition, stopPosition);
4349
parseCharacter = editor.document.getText(textRange);
4450
// console.log('endSelection = ' + endSelection + '; parseCharacter = ' + parseCharacter);
51+
// If it's an article feature flag versioning, move leftwards one.
52+
if (parseCharacter.match(/'|"|\n/)) { endSelection--; }
4553
moveRightBy = endSelection - startSelection;
4654
// console.log('move left by = ' + moveRightBy);
4755
}
@@ -58,11 +66,11 @@ function copyMain() {
5866
by: "character",
5967
value: moveRightBy,
6068
select: true
61-
})
69+
})
6270

6371
}
6472
else {
65-
vscode.window.showInformationMessage("Open reusales extension: cursor is not within a reusable or variable");
73+
vscode.window.showInformationMessage("Cursor is not within a reusable, variable, or feature flag.");
6674
}
6775

6876
}

0 commit comments

Comments
 (0)