({ onSubmit })
| 76 | const DebuggerInput: React.FC<{ |
| 77 | onSubmit: (code: string) => void; |
| 78 | }> = ({ onSubmit }) => { |
| 79 | const [value, setValue] = React.useState(""); |
| 80 | const ref = React.useRef<HTMLDivElement>(null); |
| 81 | |
| 82 | const { navigateUp, navigateDown, addToHistory } = useInputHistory({ |
| 83 | value, |
| 84 | setValue, |
| 85 | }); |
| 86 | |
| 87 | // Capture some events for command history navigation |
| 88 | useKeydownOnElement(ref, { |
| 89 | ArrowUp: navigateUp, |
| 90 | ArrowDown: navigateDown, |
| 91 | }); |
| 92 | |
| 93 | return ( |
| 94 | <div ref={ref}> |
| 95 | <ReactCodeMirror |
| 96 | minHeight="18px" |
| 97 | theme="dark" |
| 98 | className={ |
| 99 | "debugger-input *:outline-hidden cm-focused [&>.cm-editor]:pr-0 overflow-hidden dark border-t-4" |
| 100 | } |
| 101 | value={value} |
| 102 | autoFocus={true} |
| 103 | basicSetup={{ |
| 104 | lineNumbers: false, |
| 105 | }} |
| 106 | extensions={[ |
| 107 | langs.py(), |
| 108 | Prec.highest( |
| 109 | keymap.of([ |
| 110 | { |
| 111 | key: "Enter", |
| 112 | preventDefault: true, |
| 113 | stopPropagation: true, |
| 114 | run: () => { |
| 115 | const v = value.trim().replaceAll("\n", "\\n"); |
| 116 | if (!v) { |
| 117 | return true; |
| 118 | } |
| 119 | addToHistory(v); |
| 120 | onSubmit(v); |
| 121 | setValue(""); |
| 122 | return true; |
| 123 | }, |
| 124 | }, |
| 125 | { |
| 126 | key: "Shift-Enter", |
| 127 | preventDefault: true, |
| 128 | stopPropagation: true, |
| 129 | run: (view: EditorView) => { |
| 130 | // Insert newline and move cursor to end of line |
| 131 | view.dispatch({ |
| 132 | changes: { |
| 133 | from: view.state.selection.main.to, |
| 134 | insert: "\n", |
| 135 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…