(mode: "find" | "replace")
| 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; |
no test coverage detected