mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-24 07:29:30 +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 | Ctrl ⇧ O | Ctrl ⇧ O | ⌘ ⇧ O |
|
||||||
| Toggle outline list expand | Ctrl Space | Ctrl Space | ⌘ Space |
|
| Toggle outline list expand | Ctrl Space | Ctrl Space | ⌘ Space |
|
||||||
| Open search | Ctrl F | Ctrl F | ⌘ F |
|
| 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 strike | Ctrl ⇧ S | Ctrl ⇧ S | ⌘ ⇧ S |
|
||||||
| Toggle subscript | Ctrl , | Ctrl , | ⌘ , |
|
| Toggle subscript | Ctrl , | Ctrl , | ⌘ , |
|
||||||
| Toggle superscript | Ctrl . | Ctrl . | ⌘ . |
|
| Toggle superscript | Ctrl . | Ctrl . | ⌘ . |
|
||||||
|
|||||||
@@ -335,6 +335,12 @@ export const tiptapKeys = {
|
|||||||
category: "Editor",
|
category: "Editor",
|
||||||
type: "tiptap"
|
type: "tiptap"
|
||||||
},
|
},
|
||||||
|
openSearchAndReplace: {
|
||||||
|
keys: "Mod-Alt-f",
|
||||||
|
description: "Open search and replace",
|
||||||
|
category: "Editor",
|
||||||
|
type: "tiptap"
|
||||||
|
},
|
||||||
toggleStrike: {
|
toggleStrike: {
|
||||||
keys: "Mod-Shift-S",
|
keys: "Mod-Shift-S",
|
||||||
description: "Toggle strike",
|
description: "Toggle strike",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type DispatchFn = (tr: Transaction) => void;
|
|||||||
declare module "@tiptap/core" {
|
declare module "@tiptap/core" {
|
||||||
interface Commands<ReturnType> {
|
interface Commands<ReturnType> {
|
||||||
searchreplace: {
|
searchreplace: {
|
||||||
startSearch: () => ReturnType;
|
startSearch: (isReplacing?: boolean) => ReturnType;
|
||||||
endSearch: () => ReturnType;
|
endSearch: () => ReturnType;
|
||||||
search: (term: string, options?: SearchSettings) => ReturnType;
|
search: (term: string, options?: SearchSettings) => ReturnType;
|
||||||
moveToNextResult: () => ReturnType;
|
moveToNextResult: () => ReturnType;
|
||||||
@@ -51,7 +51,7 @@ interface Result {
|
|||||||
|
|
||||||
interface SearchOptions {
|
interface SearchOptions {
|
||||||
searchResultClass: string;
|
searchResultClass: string;
|
||||||
onStartSearch: (term?: string) => boolean;
|
onStartSearch: (term?: string, isReplacing?: boolean) => boolean;
|
||||||
onEndSearch: () => boolean;
|
onEndSearch: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
|
|||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
startSearch:
|
startSearch:
|
||||||
() =>
|
(isReplacing) =>
|
||||||
({ state, commands }) => {
|
({ state, commands }) => {
|
||||||
const term = !state.selection.empty
|
const term = !state.selection.empty
|
||||||
? state.doc.textBetween(
|
? state.doc.textBetween(
|
||||||
@@ -252,7 +252,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
|
|||||||
: undefined;
|
: undefined;
|
||||||
if (term) commands.search(term);
|
if (term) commands.search(term);
|
||||||
|
|
||||||
return this.options.onStartSearch(term);
|
return this.options.onStartSearch(term, isReplacing);
|
||||||
},
|
},
|
||||||
endSearch:
|
endSearch:
|
||||||
() =>
|
() =>
|
||||||
@@ -357,6 +357,8 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
|
|||||||
return {
|
return {
|
||||||
[tiptapKeys.openSearch.keys]: ({ editor }) =>
|
[tiptapKeys.openSearch.keys]: ({ editor }) =>
|
||||||
editor.commands.startSearch(),
|
editor.commands.startSearch(),
|
||||||
|
[tiptapKeys.openSearchAndReplace.keys]: ({ editor }) =>
|
||||||
|
editor.commands.startSearch(true),
|
||||||
Escape: ({ editor }) => editor.commands.endSearch()
|
Escape: ({ editor }) => editor.commands.endSearch()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -191,11 +191,12 @@ const useTiptap = (
|
|||||||
extensions: [
|
extensions: [
|
||||||
...CoreExtensions,
|
...CoreExtensions,
|
||||||
SearchReplace.configure({
|
SearchReplace.configure({
|
||||||
onStartSearch: (term) => {
|
onStartSearch: (term, isReplacing) => {
|
||||||
useEditorSearchStore.setState({
|
useEditorSearchStore.setState({
|
||||||
isSearching: true,
|
isSearching: true,
|
||||||
searchTerm: term,
|
searchTerm: term,
|
||||||
focusNonce: Math.random()
|
focusNonce: Math.random(),
|
||||||
|
isReplacing: isReplacing
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user