Shift-Enter in the page navigator now takes the input literally

pull/503/head
Zef Hemel 2023-08-01 21:37:52 +02:00
parent 701a567c95
commit 2c8e1f1809
2 changed files with 16 additions and 7 deletions

View File

@ -100,8 +100,10 @@ export function FilterList({
darkMode={darkMode} darkMode={darkMode}
completer={completer} completer={completer}
placeholderText={placeholder} placeholderText={placeholder}
onEnter={() => { onEnter={(_newText, shiftDown) => {
onSelect(matchingOptions[selectedOption]); onSelect(
shiftDown ? { name: text } : matchingOptions[selectedOption],
);
return true; return true;
}} }}
onEscape={() => { onEscape={() => {

View File

@ -22,7 +22,7 @@ import {
} from "../deps.ts"; } from "../deps.ts";
type MiniEditorEvents = { type MiniEditorEvents = {
onEnter: (newText: string) => void; onEnter: (newText: string, shiftDown?: boolean) => void;
onEscape?: (newText: string) => void; onEscape?: (newText: string) => void;
onBlur?: (newText: string) => void | Promise<void>; onBlur?: (newText: string) => void | Promise<void>;
onChange?: (newText: string) => void; onChange?: (newText: string) => void;
@ -174,7 +174,14 @@ export function MiniEditor(
{ {
key: "Enter", key: "Enter",
run: (view) => { run: (view) => {
onEnter(view); onEnter(view, false);
return true;
},
},
{
key: "Shift-Enter",
run: (view) => {
onEnter(view, true);
return true; return true;
}, },
}, },
@ -204,7 +211,7 @@ export function MiniEditor(
// Enter should be handled by the keymap, except when in Vim normal mode // Enter should be handled by the keymap, except when in Vim normal mode
// because then it's disabled // because then it's disabled
if (vimMode && vimModeRef.current === "normal") { if (vimMode && vimModeRef.current === "normal") {
onEnter(view); onEnter(view, event.shiftKey);
return true; return true;
} }
return false; return false;
@ -233,12 +240,12 @@ export function MiniEditor(
}); });
// Avoid double triggering these events (may happen due to onkeypress vs onkeyup delay) // Avoid double triggering these events (may happen due to onkeypress vs onkeyup delay)
function onEnter(view: EditorView) { function onEnter(view: EditorView, shiftDown: boolean) {
if (onEntered) { if (onEntered) {
return; return;
} }
onEntered = true; onEntered = true;
callbacksRef.current!.onEnter(view.state.sliceDoc()); callbacksRef.current!.onEnter(view.state.sliceDoc(), shiftDown);
// Event may occur again in 500ms // Event may occur again in 500ms
setTimeout(() => { setTimeout(() => {
onEntered = false; onEntered = false;