Skip to content

Commit 41952b7

Browse files
authored
fix: make output panes readonly (#42)
* fix: make output panes readonly The output panes currently allow pasting, though not general editing. This change makes them readonly, preventing any editing, but also allowing other features like copying, selecting, and searching. We also enable tab to create spaces in the editor. * Update README.md * Update README.md * fix: making alt+up/down navigate history on mac For some reason cmd + up/down doesn't work when trying to navigate history. It must be overloaded. This changes it to alt+up/down for mac.
1 parent 64a12fd commit 41952b7

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The library also reads from console.error and reports any errors printed out whi
9393

9494
## History
9595

96-
The library maintains the list of commands run in the upper read only code editor. It also maintains a buffer of previous commands that can be accessed in the code input section by using `super+arrow up/down`. This history is stored in local storage so that you can access it between test runs. You can clear this history by using the `Clear History` button.
96+
The library maintains the list of commands run in the upper read only code editor. It also maintains a buffer of previous commands that can be accessed in the code input section by using `ctrl+arrow up/down` (`alt+arrow up/down` on Mac). This history is stored in local storage so that you can access it between test runs. You can clear this history by using the `Clear History` button.
9797

9898
## Restarting Tests
9999

@@ -144,3 +144,12 @@ registerCommands({
144144
```
145145

146146
You can pass an object to `registerCommands` where each key is the name of the command, and the value is the function it will run when invoked.
147+
148+
## Shortcuts
149+
150+
| Key | Shortcut|
151+
|---|---|
152+
| Ctrl + Arrow Up/Down (Mac: Alt + Arrow Up/Down) | Navigate history |
153+
| Ctrl + Enter (Mac: Cmd + Enter) | Submit command |
154+
| Esc then Tab | Tab out of the command editor. Without hitting escape first, tab acts to indent |
155+

test-runner/src/App.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
height: 100vh;
1010
display: flex;
1111
flex-direction: column;
12-
width: 450px;
12+
width: 500px;
1313
justify-content: space-between;
1414
}
1515

@@ -49,3 +49,7 @@ button:focus {
4949
min-height: 0;
5050
overflow: auto;
5151
}
52+
53+
.tab-instruction {
54+
font-size: 10pt;
55+
}

test-runner/src/CommandInput.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ function CommandInput({ setInnerHTML, availableCommands }) {
181181
</button>
182182
<button onClick={() => axios.post("/stop")}>Stop Test</button>
183183
</div>
184+
<p className="tab-instruction">
185+
Note the tab key is used to indent inside the editor. Hit esc then tab
186+
to escape.
187+
</p>
184188
</>
185189
);
186190
}

test-runner/src/Editor.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useEffect, useCallback, useRef, useMemo } from "react";
2-
32
import {
43
keymap,
54
highlightSpecialChars,
@@ -19,7 +18,7 @@ import {
1918
gutter,
2019
GutterMarker,
2120
} from "@codemirror/gutter";
22-
import { defaultKeymap } from "@codemirror/commands";
21+
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
2322
import { bracketMatching } from "@codemirror/matchbrackets";
2423
import { closeBrackets, closeBracketsKeymap } from "@codemirror/closebrackets";
2524
import { searchKeymap, highlightSelectionMatches } from "@codemirror/search";
@@ -432,23 +431,22 @@ export default function Editor({
432431

433432
const previousCommandsKeyMap = [
434433
{
435-
key: "Ctrl-ArrowUp",
436-
mac: "Cmd-ArrowUp",
434+
key: "Mod-ArrowUp",
435+
mac: "Alt-ArrowUp",
437436
run: ctrlCursorArrowUp,
438437
preventDefault: true,
439438
},
440439
{
441-
key: "Ctrl-ArrowDown",
442-
mac: "Cmd-ArrowDown",
440+
key: "Mod-ArrowDown",
441+
mac: "Alt-ArrowDown",
443442
run: ctrlCursorArrowDown,
444443
preventDefault: true,
445444
},
446445
];
447446

448447
const sendCommandKeyMap = [
449448
{
450-
key: "Ctrl-Enter",
451-
mac: "Cmd-Enter",
449+
key: "Mod-Enter",
452450
run: ({ state }) => {
453451
state.field(submitFunctionState).submit();
454452
},
@@ -486,6 +484,7 @@ export default function Editor({
486484
...completionKeymap,
487485
...lintKeymap,
488486
...previousCommandsKeyMap,
487+
indentWithTab,
489488
]),
490489
javascript(),
491490
autocompletion({ override: [myCompletions] }),
@@ -499,7 +498,7 @@ export default function Editor({
499498
cursorTooltipBaseTheme,
500499
errorUnderlineTheme,
501500
warningUnderlineTheme,
502-
EditorView.editable.of(!readonly),
501+
EditorState.readOnly.of(readonly),
503502
],
504503
});
505504
if (

0 commit comments

Comments
 (0)