Skip to content

Commit

Permalink
fix: quick navigate to sessions.json
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclongdev authored Oct 18, 2024
1 parent 72bcac1 commit c283352
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-mangos-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"terminal-keeper": patch
---

fix: quick navigate to sessions.json
18 changes: 12 additions & 6 deletions src/commands/navigateAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
Expand Down
4 changes: 2 additions & 2 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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<SessionConfiguration> {
Expand Down
12 changes: 9 additions & 3 deletions src/explorer/tree-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -198,7 +198,13 @@ export class TreeProvider implements TreeDataProvider<TKTreeItem> {
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,
Expand Down Expand Up @@ -277,7 +283,7 @@ export class TreeProvider implements TreeDataProvider<TKTreeItem> {
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,
Expand Down

0 comments on commit c283352

Please sign in to comment.