MCPcopy Create free account
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / openSearchFromHotkey

Method openSearchFromHotkey

src/code_view.ts:909–938  ·  view source on GitHub ↗
(mode: "find" | "replace")

Source from the content-addressed store, hash-verified

907 }
908
909 private openSearchFromHotkey(mode: "find" | "replace") {
910 if (!this.searchPanel) return;
911
912 const isOpen = this.searchPanel.isOpen();
913 const activeEl = this.searchPanel.panelEl.ownerDocument.activeElement;
914 const focusInPanel = activeEl instanceof HTMLElement && this.searchPanel.panelEl.contains(activeEl);
915
916 // Ctrl/Cmd+F acts like a toggle: if focus is already in the panel, close it.
917 if (mode === "find" && isOpen && focusInPanel) {
918 this.searchPanel.close();
919 return;
920 }
921
922 const selected = this.getSelectedTextForSearch();
923
924 if (mode === "replace") {
925 this.searchPanel.focusReplace();
926 if (selected) {
927 // Do not steal focus from the replace input.
928 this.searchPanel.setSearchValue(selected, false);
929 }
930 return;
931 }
932
933 // Find
934 this.searchPanel.open();
935 if (selected) {
936 this.searchPanel.setSearchValue(selected, true);
937 }
938 }
939
940 private setupMobileViewportFix(root: HTMLElement) {
941 if (!Platform.isMobileApp) return;

Callers 1

initCodeMirrorMethod · 0.95

Calls 6

isOpenMethod · 0.80
focusReplaceMethod · 0.80
setSearchValueMethod · 0.80
closeMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected