Skip to content

Commit

Permalink
Fix: handle escaped pipes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi389111 committed Apr 28, 2023
1 parent 1179ae9 commit 25812d2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,17 @@ export const activate = (context: vscode.ExtensionContext): void => {
}

const REGEX_LINE = /^([ \t]*>)*[ \t]*\|[^\r\n]*$/mg;
const REGEX_COLUMN = /\|((\\.)|[^\\|])*(?=\|)/g;
const cursor = editor.selection.active;
const textLine = editor.document.lineAt(cursor.line).text;
const cursorColumn = (
textLine.match(REGEX_LINE)
&& textLine.substring(cursor.character).includes('|')
)
? (textLine.substring(0, cursor.character).match(/\|/g) || []).length - 1
: -1;
const cursorColumn = Array.from(textLine.matchAll(REGEX_COLUMN))
.findIndex(match =>
match.index! < cursor.character
&& cursor.character <= match.index! + match[0].length
);
const options: vscode.DecorationOptions[][] = decorationTypes.map(_ => []);
const cursorOpt: vscode.DecorationOptions[] = [];
Array.from(editor.document.getText().matchAll(REGEX_LINE)).forEach(matchLine => {
const REGEX_COLUMN = /\|[^|\r\n]*(?=\|)/g;
Array.from(matchLine[0].matchAll(REGEX_COLUMN)).forEach((matchColumn, index) => {
// `match.index` returned by `matchAll()` must exist.
// ref. https://github.com/microsoft/TypeScript/issues/36788
Expand Down

0 comments on commit 25812d2

Please sign in to comment.