feat: add undo/redo/reset editor tools with keyboard shortcuts
- Add history extension to CodeMirror for undo/redo support - Ctrl+Z for undo, Ctrl+Shift+Z for redo now work - Add toolbar buttons: ↶ Undo, ↷ Redo, ⟲ Reset - Reset button restores editor to initial lesson code - Add .btn-icon and .editor-tools CSS styles
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
*/
|
||||
import { EditorState, Prec } from "@codemirror/state";
|
||||
import { EditorView, keymap, placeholder } from "@codemirror/view";
|
||||
import { defaultKeymap, indentMore, indentLess } from "@codemirror/commands";
|
||||
import { defaultKeymap, historyKeymap, indentMore, indentLess, undo, redo } from "@codemirror/commands";
|
||||
import { history } from "@codemirror/commands";
|
||||
import { oneDark } from "@codemirror/theme-one-dark";
|
||||
import { html } from "@codemirror/lang-html";
|
||||
import { css } from "@codemirror/lang-css";
|
||||
@@ -49,6 +50,8 @@ export class CodeEditor {
|
||||
langExtension,
|
||||
oneDark,
|
||||
editorTheme,
|
||||
// History for undo/redo
|
||||
history(),
|
||||
// Emmet abbreviation tracking
|
||||
abbreviationTracker(),
|
||||
// High priority keymap for Emmet
|
||||
@@ -58,8 +61,9 @@ export class CodeEditor {
|
||||
run: expandAbbreviation
|
||||
}
|
||||
])),
|
||||
// Standard keymaps
|
||||
// Standard keymaps including history (Ctrl+Z, Ctrl+Shift+Z)
|
||||
keymap.of([
|
||||
...historyKeymap,
|
||||
{ key: "Tab", run: indentMore },
|
||||
{ key: "Shift-Tab", run: indentLess },
|
||||
...defaultKeymap
|
||||
@@ -138,6 +142,24 @@ export class CodeEditor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo last change
|
||||
*/
|
||||
undo() {
|
||||
if (this.view) {
|
||||
undo(this.view);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redo last undone change
|
||||
*/
|
||||
redo() {
|
||||
if (this.view) {
|
||||
redo(this.view);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the editor
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user