Skip to content

Commit bb82671

Browse files
committed
#338: Fix hotkey buttons not working in Obsidian 1.2.0 onwards.
1 parent afe1826 commit bb82671

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/settings/setting_elements/CreateShellCommandField.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export function createShellCommandField(
242242
}),
243243
);
244244

245+
// Create Hotkey settings icon.
245246
if (t_shell_command.canHaveHotkeys()) {
246247
setting_group.preview_setting.addExtraButton(button => button
247248
.setIcon("any-key")
@@ -254,12 +255,23 @@ export function createShellCommandField(
254255

255256
// @ts-ignore
256257
const hotkeys_settings_tab = plugin.app.setting.settingTabs.filter(tab => tab.id === "hotkeys").shift();
257-
if (hotkeys_settings_tab && hotkeys_settings_tab.searchInputEl && hotkeys_settings_tab.updateHotkeyVisibility) {
258-
debugLog("Hotkeys: Filtering by shell command " + t_shell_command.getObsidianCommand().name);
259-
hotkeys_settings_tab.searchInputEl.value = t_shell_command.getObsidianCommand().name;
260-
hotkeys_settings_tab.updateHotkeyVisibility();
258+
const searchErrorMessage = "Shell command hotkey search failed due to a private API change in the hotkey search. Please start a discussion in the SC plugin's GitHub repo.";
259+
if (hotkeys_settings_tab) {
260+
const hotkeySearchElement =
261+
hotkeys_settings_tab.searchInputEl ?? // For Obsidian versions before 1.2.0.
262+
hotkeys_settings_tab.searchComponent.inputEl // For Obsidian version 1.2.0 and onwards.
263+
;
264+
if (hotkeySearchElement && hotkeys_settings_tab.updateHotkeyVisibility) {
265+
debugLog("Hotkeys: Filtering by shell command " + t_shell_command.getObsidianCommand().name);
266+
hotkeySearchElement.value = t_shell_command.getObsidianCommand().name;
267+
hotkeys_settings_tab.updateHotkeyVisibility();
268+
} else {
269+
debugLog("Hotkeys: Cannot do filtering due to API changes. Search element has changed.");
270+
this.plugin.newNotification(searchErrorMessage);
271+
}
261272
} else {
262-
debugLog("Hotkeys: Cannot do filtering due to API changes.");
273+
debugLog("Hotkeys: Cannot do filtering due to API changes. 'Hotkeys' settings tab has changed.");
274+
this.plugin.newNotification(searchErrorMessage);
263275
}
264276
}),
265277
);

0 commit comments

Comments
 (0)