diff --git a/.changeset/famous-mangos-play.md b/.changeset/famous-mangos-play.md new file mode 100644 index 0000000..5afb66a --- /dev/null +++ b/.changeset/famous-mangos-play.md @@ -0,0 +1,5 @@ +--- +"terminal-keeper": patch +--- + +fix: quick navigate to sessions.json diff --git a/src/commands/navigateAsync.ts b/src/commands/navigateAsync.ts index 4fe0851..5162dc4 100644 --- a/src/commands/navigateAsync.ts +++ b/src/commands/navigateAsync.ts @@ -12,13 +12,19 @@ const getFileUriBySource = (source: string | undefined): Uri => { return Uri.file(Configuration.sessionFilePath); }; +const escapeRegExp = (input: string) => { + return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +}; + const getKeywordRegex = (treeItem: TKTreeItem): RegExp => { - const { source, keyword } = treeItem; - let keywordFull = keyword || ''; - if (source === 'settings.json') { - keywordFull = `terminal-keeper.${keyword}`; - } - return new RegExp(keywordFull, 'gm'); + const { keywords = [] } = treeItem; + const enhanceKeywords = keywords.map((keyword) => { + let enhanceKeyword = escapeRegExp(keyword) + .replace(`: `, `: ?`) // match space or no space + .replace(`"`, `(?:'|")`); // match single quote or double quote + return enhanceKeyword; + }); + return new RegExp(enhanceKeywords.join('|'), 'gm'); }; export const navigateAsync = async (treeItem: TKTreeItem): Promise => { diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index b30010a..d3cd83c 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -6,7 +6,7 @@ import { getTabWidth } from '../utils/utils'; import { SessionConfiguration } from './interface'; export class Configuration { - private static workSpaceConfigurationSpace: string = 'terminal-keeper'; + public static wsConfigurationSpace: string = 'terminal-keeper'; public static vscodeDirPath: string = ''; public static sessionFilePath: string = ''; public static userConfigKeys: string[] = []; @@ -144,7 +144,7 @@ export class Configuration { } private static getWorkspaceConfiguration(): WorkspaceConfiguration { - return workspace.getConfiguration(this.workSpaceConfigurationSpace); + return workspace.getConfiguration(this.wsConfigurationSpace); } private static async getSessionConfiguration(): Promise { diff --git a/src/explorer/tree-provider.ts b/src/explorer/tree-provider.ts index 63f39da..2b97581 100644 --- a/src/explorer/tree-provider.ts +++ b/src/explorer/tree-provider.ts @@ -20,7 +20,7 @@ export class TKTreeItem extends TreeItem { // Use to navigate to json source: 'settings.json' | 'sessions.json' | undefined; - keyword: string | undefined; + keywords: string[] | undefined; constructor(label: string, children?: TKTreeItem[]) { super(label, children === undefined ? TreeItemCollapsibleState.None : TreeItemCollapsibleState.Collapsed); @@ -198,7 +198,13 @@ export class TreeProvider implements TreeDataProvider { item.contextValue = 'overview-context'; item.iconPath = new ThemeIcon(id || 'circle-filled', color); item.source = source; - item.keyword = label; + item.keywords = + source === 'settings.json' + ? [ + `"${Configuration.wsConfigurationSpace}.${label}": ${value}`, + `"${Configuration.wsConfigurationSpace}.${label}": "${value}"` + ] + : [`"${label}": ${value}`, `"${label}": "${value}"`]; item.command = { title: 'Navigate to configuration', command: extCommands.navigateActivity, @@ -277,7 +283,7 @@ export class TreeProvider implements TreeDataProvider { item.sessionId = sessionId; item.terminalArrayIndex = terminalArrayIndex; item.source = 'sessions.json'; - item.keyword = terminalName; + item.keywords = [`"name": "${terminalName}"`]; item.command = { title: 'Navigate to configuration', command: extCommands.navigateActivity,