Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: add shortcut to open search and replace (#9043)

01zulfi2cdfe2c158cc
diff --git a/docs/help/contents/keyboard-shortcuts.md b/docs/help/contents/keyboard-shortcuts.md
index 1a829035a..654b5b5fb 100644
--- a/docs/help/contents/keyboard-shortcuts.md
+++ b/docs/help/contents/keyboard-shortcuts.md
@@ -67,6 +67,7 @@ The following keyboard shortcuts will help you navigate Notesnook faster.
| Toggle outline list | Ctrl ⇧ O | Ctrl ⇧ O | ⌘ ⇧ O |
| Toggle outline list expand | Ctrl Space | Ctrl Space | ⌘ Space |
| Open search | Ctrl F | Ctrl F | ⌘ F |
+| Open search and replace | Ctrl Alt F | Ctrl Alt F | ⌘ ⌥ F |
| Toggle strike | Ctrl ⇧ S | Ctrl ⇧ S | ⌘ ⇧ S |
| Toggle subscript | Ctrl , | Ctrl , | ⌘ , |
| Toggle superscript | Ctrl . | Ctrl . | ⌘ . |
diff --git a/packages/common/src/utils/keybindings.ts b/packages/common/src/utils/keybindings.ts
index 1fbb87207..74e3a5fea 100644
--- a/packages/common/src/utils/keybindings.ts
+++ b/packages/common/src/utils/keybindings.ts
@@ -335,6 +335,12 @@ export const tiptapKeys = {
category: "Editor",
type: "tiptap"
},
+ openSearchAndReplace: {
+ keys: "Mod-Alt-f",
+ description: "Open search and replace",
+ category: "Editor",
+ type: "tiptap"
+ },
toggleStrike: {
keys: "Mod-Shift-S",
description: "Toggle strike",
diff --git a/packages/editor/src/extensions/search-replace/search-replace.ts b/packages/editor/src/extensions/search-replace/search-replace.ts
index a743a940a..41ed33a71 100644
--- a/packages/editor/src/extensions/search-replace/search-replace.ts
+++ b/packages/editor/src/extensions/search-replace/search-replace.ts
@@ -33,7 +33,7 @@ type DispatchFn = (tr: Transaction) => void;
declare module "@tiptap/core" {
interface Commands<ReturnType> {
searchreplace: {
- startSearch: () => ReturnType;
+ startSearch: (isReplacing?: boolean) => ReturnType;
endSearch: () => ReturnType;
search: (term: string, options?: SearchSettings) => ReturnType;
moveToNextResult: () => ReturnType;
@@ -51,7 +51,7 @@ interface Result {
interface SearchOptions {
searchResultClass: string;
- onStartSearch: (term?: string) => boolean;
+ onStartSearch: (term?: string, isReplacing?: boolean) => boolean;
onEndSearch: () => boolean;
}
@@ -242,7 +242,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
addCommands() {
return {
startSearch:
- () =>
+ (isReplacing) =>
({ state, commands }) => {
const term = !state.selection.empty
? state.doc.textBetween(
@@ -252,7 +252,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
: undefined;
if (term) commands.search(term);
- return this.options.onStartSearch(term);
+ return this.options.onStartSearch(term, isReplacing);
},
endSearch:
() =>
@@ -357,6 +357,8 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
return {
[tiptapKeys.openSearch.keys]: ({ editor }) =>
editor.commands.startSearch(),
+ [tiptapKeys.openSearchAndReplace.keys]: ({ editor }) =>
+ editor.commands.startSearch(true),
Escape: ({ editor }) => editor.commands.endSearch()
};
},
diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts
index 1c16a8286..a389877b6 100644
--- a/packages/editor/src/index.ts
+++ b/packages/editor/src/index.ts
@@ -191,11 +191,12 @@ const useTiptap = (
extensions: [
...CoreExtensions,
SearchReplace.configure({
- onStartSearch: (term) => {
+ onStartSearch: (term, isReplacing) => {
useEditorSearchStore.setState({
isSearching: true,
searchTerm: term,
- focusNonce: Math.random()
+ focusNonce: Math.random(),
+ isReplacing: isReplacing
});
return true;
},