From 702c2b3ecffb67e0ce8c86bf26fb008f5e695ab8 Mon Sep 17 00:00:00 2001 From: yizhenl3 Date: Mon, 1 May 2023 01:40:00 -0500 Subject: [PATCH 1/2] enable tags with hyphens --- src/consts.ts | 4 ++-- src/todo/decorators/tag.ts | 32 ++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/consts.ts b/src/consts.ts index 67f7c7f..849ec6c 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -65,8 +65,8 @@ const Consts = { archive: new RegExp ( `^(?![^\\S\\n]*(?!--|––|——)(?:[-❍❑■⬜□☐▪▫–—≡→›✘xX✔✓☑+]|\\[[ xX+-]?\\])\\s[^\\n]*)([^\\S\\n]*${_.escapeRegExp ( archiveName )}:.*$)`, 'gm' ), comment: /^(?!\s*$)(?![^\S\n]*(?!--|––|——)(?:[-❍❑■⬜□☐▪▫–—≡→›✘xX✔✓☑+]|\[[ xX+-]?\])\s[^\n]*)(?![^\S\n]*.+:[^\S\n]*(?:(?=@[^\s*~(]+(?::\/\/[^\s*~(:]+)?(?:\([^)]*\))?)|$))[^\S\n]*([^\n]+)/gm, tag: /(?:^|[^a-zA-Z0-9`])(@[^\s*~(]+(?::\/\/[^\s*~(:]+)?(?:\([^)]*\))?)/gm, - tagSpecial: new RegExp ( `(?:^|[^a-zA-Z0-9])@(${tagsNames.map ( n => _.escapeRegExp ( n ) ).join ( '|' )})(?:(?:\\([^)]*\\))|(?![a-zA-Z]))`, 'gm' ), - tagSpecialNormal: new RegExp ( `(?:^|[^a-zA-Z0-9])(?:${tagsNames.map ( n => `(@${_.escapeRegExp ( n )}(?:(?:\\([^)]*\\))|(?![a-zA-Z])))` ).join ( '|' )}|(@[^\\s*~(]+(?::\/\/[^\\s*~(:]+)?(?:(?:\\([^)]*\\))|(?![a-zA-Z]))))`, 'gm' ), + tagSpecial: new RegExp(`(?:^|[^a-zA-Z0-9-])@(${tagsNames.map(n => _.escapeRegExp(n)).join('|')})(?:(?:\\([^)]*\\))|(?![a-zA-Z0-9-]))`, 'gm'), + tagSpecialNormal: new RegExp(`(?:^|[^a-zA-Z0-9-])(?:${tagsNames.map(n => `(@${_.escapeRegExp(n)}(?:(?:\\([^)]*\\))|(?![a-zA-Z0-9-])))`).join('|')}|(@[^\\s*~(]+(?::\/\/[^\\s*~(:]+)?(?:(?:\\([^)]*\\))|(?![a-zA-Z]))))`, 'gm'), tagNormal: new RegExp ( `(?:^|[^a-zA-Z0-9])@(?!${tagsNames.map ( n => _.escapeRegExp ( n ) ).join ( '|' )}|created|done|cancelled|started|lasted|wasted|est|\\d)[^\\s*~(:]+(?::\/\/[^\\s*~(:]+)?(?:\\([^)]*\\))?` ), tagCreated: /(?:^|[^a-zA-Z0-9])@created(?:(?:\(([^)]*)\))|(?![a-zA-Z]))/, tagStarted: /(?:^|[^a-zA-Z0-9])@started(?:(?:\(([^)]*)\))|(?![a-zA-Z]))/, diff --git a/src/todo/decorators/tag.ts b/src/todo/decorators/tag.ts index e8e571d..4e5d947 100644 --- a/src/todo/decorators/tag.ts +++ b/src/todo/decorators/tag.ts @@ -8,20 +8,24 @@ import Line from './line'; /* DECORATION TYPES */ -const SPECIAL_TAGS = Consts.tags.names.map ( ( name, index ) => vscode.window.createTextEditorDecorationType ({ - backgroundColor: Consts.colors.tags.background[index], - color: Consts.colors.tags.foreground[index], - borderRadius: '2px', - rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, - dark: { - backgroundColor: Consts.colors.dark.tags.background[index], - color: Consts.colors.dark.tags.foreground[index] - }, - light: { - backgroundColor: Consts.colors.light.tags.background[index], - color: Consts.colors.light.tags.foreground[index] - } -})); +const SPECIAL_TAGS = Consts.tags.names.map((name, index) => { + const colorIndex = index % Consts.colors.tags.background.length; + return vscode.window.createTextEditorDecorationType({ + backgroundColor: Consts.colors.tags.background[colorIndex], + color: Consts.colors.tags.foreground[colorIndex], + borderRadius: '2px', + rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, + dark: { + backgroundColor: Consts.colors.dark.tags.background[colorIndex], + color: Consts.colors.dark.tags.foreground[colorIndex], + }, + light: { + backgroundColor: Consts.colors.light.tags.background[colorIndex], + color: Consts.colors.light.tags.foreground[colorIndex], + }, + }); +}); + const TAG = vscode.window.createTextEditorDecorationType ({ color: Consts.colors.tag, From 370744a4e1db59012a1ad05b306c7b9f2c068559 Mon Sep 17 00:00:00 2001 From: yizhenl3 Date: Mon, 1 May 2023 01:48:03 -0500 Subject: [PATCH 2/2] fix consistent syntax --- src/consts.ts | 4 ++-- src/todo/decorators/tag.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/consts.ts b/src/consts.ts index 849ec6c..345a728 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -65,8 +65,8 @@ const Consts = { archive: new RegExp ( `^(?![^\\S\\n]*(?!--|––|——)(?:[-❍❑■⬜□☐▪▫–—≡→›✘xX✔✓☑+]|\\[[ xX+-]?\\])\\s[^\\n]*)([^\\S\\n]*${_.escapeRegExp ( archiveName )}:.*$)`, 'gm' ), comment: /^(?!\s*$)(?![^\S\n]*(?!--|––|——)(?:[-❍❑■⬜□☐▪▫–—≡→›✘xX✔✓☑+]|\[[ xX+-]?\])\s[^\n]*)(?![^\S\n]*.+:[^\S\n]*(?:(?=@[^\s*~(]+(?::\/\/[^\s*~(:]+)?(?:\([^)]*\))?)|$))[^\S\n]*([^\n]+)/gm, tag: /(?:^|[^a-zA-Z0-9`])(@[^\s*~(]+(?::\/\/[^\s*~(:]+)?(?:\([^)]*\))?)/gm, - tagSpecial: new RegExp(`(?:^|[^a-zA-Z0-9-])@(${tagsNames.map(n => _.escapeRegExp(n)).join('|')})(?:(?:\\([^)]*\\))|(?![a-zA-Z0-9-]))`, 'gm'), - tagSpecialNormal: new RegExp(`(?:^|[^a-zA-Z0-9-])(?:${tagsNames.map(n => `(@${_.escapeRegExp(n)}(?:(?:\\([^)]*\\))|(?![a-zA-Z0-9-])))`).join('|')}|(@[^\\s*~(]+(?::\/\/[^\\s*~(:]+)?(?:(?:\\([^)]*\\))|(?![a-zA-Z]))))`, 'gm'), + tagSpecial: new RegExp ( `(?:^|[^a-zA-Z0-9-])@(${tagsNames.map ( n => _.escapeRegExp ( n ) ).join ( '|' )})(?:(?:\\([^)]*\\))|(?![a-zA-Z0-9-]))`, 'gm' ), + tagSpecialNormal: new RegExp ( `(?:^|[^a-zA-Z0-9-])(?:${tagsNames.map ( n => `(@${_.escapeRegExp ( n )}(?:(?:\\([^)]*\\))|(?![a-zA-Z0-9-])))` ).join ( '|' )}|(@[^\\s*~(]+(?::\/\/[^\\s*~(:]+)?(?:(?:\\([^)]*\\))|(?![a-zA-Z]))))`, 'gm' ), tagNormal: new RegExp ( `(?:^|[^a-zA-Z0-9])@(?!${tagsNames.map ( n => _.escapeRegExp ( n ) ).join ( '|' )}|created|done|cancelled|started|lasted|wasted|est|\\d)[^\\s*~(:]+(?::\/\/[^\\s*~(:]+)?(?:\\([^)]*\\))?` ), tagCreated: /(?:^|[^a-zA-Z0-9])@created(?:(?:\(([^)]*)\))|(?![a-zA-Z]))/, tagStarted: /(?:^|[^a-zA-Z0-9])@started(?:(?:\(([^)]*)\))|(?![a-zA-Z]))/, diff --git a/src/todo/decorators/tag.ts b/src/todo/decorators/tag.ts index 4e5d947..1de68fa 100644 --- a/src/todo/decorators/tag.ts +++ b/src/todo/decorators/tag.ts @@ -8,7 +8,7 @@ import Line from './line'; /* DECORATION TYPES */ -const SPECIAL_TAGS = Consts.tags.names.map((name, index) => { +const SPECIAL_TAGS = Consts.tags.names.map ( ( name, index ) => { const colorIndex = index % Consts.colors.tags.background.length; return vscode.window.createTextEditorDecorationType({ backgroundColor: Consts.colors.tags.background[colorIndex],