Add native keyboard shortcuts for Find+Replace, closes #6468
This commit is contained in:
@@ -150,15 +150,38 @@ export default function FindAndReplace({
|
|||||||
|
|
||||||
const handleKeyDown = React.useCallback(
|
const handleKeyDown = React.useCallback(
|
||||||
(ev: React.KeyboardEvent<HTMLInputElement>) => {
|
(ev: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (ev.key === "Enter") {
|
function nextPrevious(ev: React.KeyboardEvent<HTMLInputElement>) {
|
||||||
ev.preventDefault();
|
|
||||||
|
|
||||||
if (ev.shiftKey) {
|
if (ev.shiftKey) {
|
||||||
editor.commands.prevSearchMatch();
|
editor.commands.prevSearchMatch();
|
||||||
} else {
|
} else {
|
||||||
editor.commands.nextSearchMatch();
|
editor.commands.nextSearchMatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function selectInputText() {
|
||||||
|
inputRef.current?.setSelectionRange(0, inputRef.current?.value.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (ev.key) {
|
||||||
|
case "Enter": {
|
||||||
|
ev.preventDefault();
|
||||||
|
nextPrevious(ev);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case "g": {
|
||||||
|
if (ev.metaKey) {
|
||||||
|
ev.preventDefault();
|
||||||
|
nextPrevious(ev);
|
||||||
|
selectInputText();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case "F3": {
|
||||||
|
ev.preventDefault();
|
||||||
|
nextPrevious(ev);
|
||||||
|
selectInputText();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[editor.commands]
|
[editor.commands]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user