feat: simplify chord guide feature; updated help doc; added hotkeys doc

This commit is contained in:
Xiaohan-Tian
2026-05-28 21:03:02 -07:00
parent cd4d5847eb
commit 4d415a7f7d
18 changed files with 522 additions and 51 deletions
+54
View File
@@ -0,0 +1,54 @@
import { describe, expect, it } from 'vitest';
import { enforceDefaultHotkeysForAppConfig } from './ConfigManager';
const baseConfig = {
general: {} as never,
hotkeys: {
main: {} as never,
piano_roll: {
switch: 'g',
switch_voicing: 'shift+tab',
select: 'q',
pencil: 'w',
hold_to_create_note: 'ctrl',
snap_none: '1',
snap_1_4: '2',
snap_1_8: '3',
snap_1_16: '4',
qua_pos_1_4: '5',
qua_pos_1_8: '6',
qua_pos_1_16: '7',
qua_len_1_4: '8',
qua_len_1_8: '9',
qua_len_1_16: '0',
},
},
editor: {} as never,
chatbox: {} as never,
audio: {} as never,
templates: {} as never,
chord_guide: {} as never,
};
describe('enforceDefaultHotkeysForAppConfig', () => {
it('always replaces saved hotkeys with config defaults', () => {
const result = enforceDefaultHotkeysForAppConfig(
{
...baseConfig,
hotkeys: {
...baseConfig.hotkeys,
piano_roll: {
...baseConfig.hotkeys.piano_roll,
switch: 'tab',
switch_voicing: 'f',
},
},
} as never,
baseConfig as never
);
expect(result.hotkeys.main).toBe(baseConfig.hotkeys.main);
expect(result.hotkeys.piano_roll.switch).toBe('g');
expect(result.hotkeys.piano_roll.switch_voicing).toBe('shift+tab');
});
});
+18 -2
View File
@@ -65,6 +65,7 @@ interface AppConfig {
};
piano_roll: {
switch: string;
switch_voicing: string;
select: string;
pencil: string;
hold_to_create_note: string;
@@ -106,6 +107,13 @@ interface AppConfig {
[key: string]: unknown;
}
export function enforceDefaultHotkeysForAppConfig(config: AppConfig, defaultConfig: AppConfig): AppConfig {
return {
...config,
hotkeys: defaultConfig.hotkeys,
};
}
/**
* ConfigManager - Manages application configuration with IndexedDB persistence
* Implements the singleton pattern for global access
@@ -162,6 +170,7 @@ export class ConfigManager {
// Merge with default config (saved config overrides defaults)
this.config = this.mergeConfigs(this.defaultConfig!, savedConfig);
this.config = enforceDefaultHotkeysForAppConfig(this.config, this.defaultConfig!);
this.isInitialized = true;
console.log('ConfigManager initialized successfully with config:', this.config);
@@ -253,7 +262,8 @@ export class ConfigManager {
merge_regions: 'ctrl+j'
},
piano_roll: {
switch: 'tab',
switch: 'g',
switch_voicing: 'shift+tab',
select: 'q',
pencil: 'w',
hold_to_create_note: 'ctrl',
@@ -329,9 +339,10 @@ export class ConfigManager {
try {
const shouldSanitize = !this.isRunningOnLocalhost() &&
!this.config.general.persist_api_keys_non_localhost;
const configToPersist = shouldSanitize
const baseConfigToPersist = shouldSanitize
? this.getSanitizedConfigForStorage()
: this.config;
const configToPersist = this.removeHotkeysFromConfigForStorage(baseConfigToPersist);
await this.storage.save(
ConfigManager.CONFIG_KEY,
@@ -475,6 +486,11 @@ export class ConfigManager {
return { ...this.config };
}
private removeHotkeysFromConfigForStorage(config: AppConfig): AppConfig {
const { hotkeys: _hotkeys, ...configWithoutHotkeys } = config;
return configWithoutHotkeys as AppConfig;
}
/**
* Get a value from an object using dot notation
*/