mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 03:37:55 +01:00
editor: add shortcut to open search and replace (#9043)
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
@@ -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 . | ⌘ . |
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user