Skip to content

Commit

Permalink
feat: show settings UI to toggle QuickOpen hotkeys #179
Browse files Browse the repository at this point in the history
The quickOpen.isEnabled setting was already externalized out to data.json #124. This change just adds a new toggle Setting to generalSettingsTabSection to make quickOpen.isEnabled visible in the settings UI.
  • Loading branch information
darlal committed Oct 12, 2024
1 parent eecf18e commit 6099829
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/settings/__tests__/generalSettingsTabSection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,45 @@ describe('generalSettingsTabSection', () => {
config.renderMarkdownContentInSuggestions.renderHeadings = false;
addToggleSettingSpy.mockReset();
});

describe('showQuickOpen', () => {
type addToggleSettingArgs = Parameters<SettingsTabSection['addToggleSetting']>;
let toggleSettingOnChangeFn: addToggleSettingArgs[5];
let saveSettingsSpy: jest.SpyInstance;

beforeAll(() => {
saveSettingsSpy = jest.spyOn(config, 'saveSettings');
});

afterAll(() => {
saveSettingsSpy.mockRestore();
});

it('should save changes to the enable QuickOpen setting', () => {
const initialValue = false;
const finalValue = true;

config.quickOpen.isEnabled = initialValue;
addToggleSettingSpy.mockImplementation((...args: addToggleSettingArgs) => {
if (args[1] === 'Enable quick open hotkeys for top results') {
toggleSettingOnChangeFn = args[5];
}

return mock<Setting>();
});

sut.showQuickOpen(mockContainerEl, config);

// trigger the change/save
toggleSettingOnChangeFn(finalValue, config);

expect(saveSettingsSpy).toHaveBeenCalled();
expect(config.quickOpen.isEnabled).toBe(finalValue);

config.quickOpen.isEnabled = false;
addToggleSettingSpy.mockReset();
});
});
});

describe('showInsertLinkInEditor', () => {
Expand Down
15 changes: 15 additions & 0 deletions src/settings/generalSettingsTabSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class GeneralSettingsTabSection extends SettingsTabSection {

this.showResetFacetEachSession(containerEl, config);
this.showRenderMarkdownContentAsHTML(containerEl, config);
this.showQuickOpen(containerEl, config);
}

showPreferredSourceForTitle(
Expand Down Expand Up @@ -354,4 +355,18 @@ export class GeneralSettingsTabSection extends SettingsTabSection {
);
setting.setClass('qsp-setting-item-indent');
}

showQuickOpen(containerEl: HTMLElement, config: SwitcherPlusSettings): void {
this.addToggleSetting(
containerEl,
'Enable quick open hotkeys for top results',
'When enabled, hotkeys will be defined for each of the top N results displayed in the Switcher. These hotkeys can be used to quickly open the associated suggestion directly. when disabled, no hotkeys are defined.',
config.quickOpen.isEnabled,
null,
(value, config) => {
config.quickOpen.isEnabled = value;
config.save();
},
);
}
}

0 comments on commit 6099829

Please sign in to comment.