Skip to content

Commit

Permalink
web: fix search not working in readonly editor
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed May 16, 2024
1 parent d1b532a commit 46599f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
30 changes: 24 additions & 6 deletions apps/web/src/common/key-map.js → apps/web/src/common/key-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import hotkeys from "hotkeys-js";
import { navigate } from "../navigation";
// import { store as themestore } from "../stores/theme-store";
import { GlobalKeyboard } from "../utils/keyboard";
import { useEditorStore } from "../stores/editor-store";
import { useStore as useSearchStore } from "../stores/search-store";
import { useEditorManager } from "../components/editor/manager";

const KEYMAP = [
// {
Expand Down Expand Up @@ -57,11 +58,24 @@ const KEYMAP = [
keys: ["command+f", "ctrl+f"],
description: "Search all notes",
global: false,
action: (e) => {
if (e.target?.classList.contains("ProseMirror")) return;
action: (e: KeyboardEvent) => {
const isInEditor =
e.target instanceof HTMLElement &&
!!e.target?.closest(".editor-container");
if (isInEditor) {
const activeSession = useEditorStore.getState().getActiveSession();
if (activeSession?.type === "readonly") {
e.preventDefault();
const editor = useEditorManager
.getState()
.getEditor(activeSession.id);
editor?.editor?.startSearch();
}
return;
}
e.preventDefault();

navigate("/search/notes");
useSearchStore.setState({ isSearching: true, searchType: "notes" });
}
}
// {
Expand Down Expand Up @@ -137,7 +151,11 @@ export function registerKeyMap() {
KEYMAP.forEach((key) => {
hotkeys(
key.keys.join(","),
{ element: key.global ? GlobalKeyboard : window },
{
element: key.global
? (GlobalKeyboard as unknown as HTMLElement)
: document.body
},
key.action
);
});
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/components/editor/action-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export function EditorActionBar() {
activeSession &&
activeSession.type !== "new" &&
activeSession.type !== "locked" &&
activeSession.type !== "readonly" &&
activeSession.type !== "diff" &&
activeSession.type !== "conflicted",
onClick: editor?.startSearch
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/editor/tiptap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ function TipTap(props: TipTapProps) {
};
}, []);

if (readonly) return null;
return (
<>
<ScopedThemeProvider
Expand Down Expand Up @@ -418,7 +417,7 @@ function TiptapWrapper(
editorContainer={() => {
if (editorContainerRef.current) return editorContainerRef.current;
const editorContainer = document.createElement("div");
editorContainer.classList.add("selectable");
editorContainer.classList.add("selectable", "editor-container");
editorContainer.style.flex = "1";
editorContainer.style.cursor = "text";
editorContainer.style.color =
Expand All @@ -427,6 +426,7 @@ function TiptapWrapper(
editorContainer.style.fontSize = `${editorConfig.fontSize}px`;
editorContainer.style.fontFamily =
getFontById(editorConfig.fontFamily)?.font || "sans-serif";
editorContainer.tabIndex = -1;
editorContainerRef.current = editorContainer;
return editorContainer;
}}
Expand Down

0 comments on commit 46599f6

Please sign in to comment.