Skip to content

Commit 01baa7b

Browse files
Merge pull request #11 from ia3andy/history
Implement history and add keyboard shorcuts
2 parents 3dc5868 + d5686c4 commit 01baa7b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

qui-code-block.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LitElement, html, css } from 'lit';
22
import {EditorState} from "@codemirror/state";
33
import {EditorView, lineNumbers, keymap, highlightActiveLineGutter, highlightSpecialChars } from "@codemirror/view";
4-
import {defaultKeymap, indentWithTab} from "@codemirror/commands";
4+
import {defaultKeymap, indentWithTab, undo, redo, history} from "@codemirror/commands";
55
import {autocompletion} from '@codemirror/autocomplete';
66
import { xml } from '@codemirror/lang-xml';
77
import { javascript } from '@codemirror/lang-javascript';
@@ -41,8 +41,8 @@ class QuiCodeBlock extends LitElement {
4141
display: block;
4242
height: 100%;
4343
}
44-
45-
#codeMirrorContainer {
44+
45+
#codeMirrorContainer, .cm-editor {
4646
height: 100%;
4747
}
4848
@@ -159,6 +159,7 @@ class QuiCodeBlock extends LitElement {
159159
};
160160

161161
const conf = [
162+
history(),
162163
this._detectMode(),
163164
this._basicTheme,
164165
highlightActiveLineGutter(),
@@ -168,8 +169,11 @@ class QuiCodeBlock extends LitElement {
168169
keymap.of([
169170
{ key: "Shift-Enter", run: shiftEnterCommand },
170171
indentWithTab,
171-
...defaultKeymap
172-
]),
172+
...defaultKeymap,
173+
{ key: "Mod-z", run: undo }, // Undo
174+
{ key: "Mod-y", run: redo }, // Redo
175+
{ key: "Mod-Shift-z", run: redo } // Redo (macOS)
176+
]),
173177
EditorView.updateListener.of((update) => {
174178
if (update.docChanged) {
175179
const value = update.state.doc.toString();

0 commit comments

Comments
 (0)