Skip to content

Commit fe1d4c8

Browse files
committed
asset editor redo
1 parent bc00bd0 commit fe1d4c8

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

src/ide/views/asseteditor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,18 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
381381
setVisible?(showing: boolean): void {
382382
// TODO: make into toolbar?
383383
if (showing) {
384-
// limit undo to since opening this editor
384+
// limit undo/redo to since opening this editor
385385
projectWindows.undofiles = [];
386-
if (Mousetrap.bind) Mousetrap.bind('mod+z', projectWindows.undoStep.bind(projectWindows));
386+
projectWindows.redofiles = [];
387+
if (Mousetrap.bind) {
388+
Mousetrap.bind('mod+z', projectWindows.undoStep.bind(projectWindows));
389+
Mousetrap.bind('mod+shift+z', projectWindows.redoStep.bind(projectWindows));
390+
}
387391
} else {
388-
if (Mousetrap.unbind) Mousetrap.unbind('mod+z');
392+
if (Mousetrap.unbind) {
393+
Mousetrap.unbind('mod+z');
394+
Mousetrap.unbind('mod+shift+z');
395+
}
389396
}
390397
}
391398

src/ide/views/baseviews.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ProjectView {
1919
setTimingResult?(result: CodeAnalyzer): void;
2020
recreateOnResize?: boolean;
2121
undoStep?(): void;
22+
redoStep?(): void;
2223
};
2324

2425
// detect mobile (https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device)

src/ide/views/editors.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { closeBrackets, deleteBracketPair } from "@codemirror/autocomplete";
2-
import { defaultKeymap, history, historyKeymap, indentWithTab, isolateHistory, undo } from "@codemirror/commands";
2+
import { defaultKeymap, history, historyKeymap, indentWithTab, isolateHistory, redo, undo } from "@codemirror/commands";
33
import { cpp } from "@codemirror/lang-cpp";
44
import { markdown } from "@codemirror/lang-markdown";
55
import { bracketMatching, foldGutter, indentOnInput, indentUnit } from "@codemirror/language";
@@ -535,6 +535,10 @@ export class SourceEditor implements ProjectView {
535535
undo(this.editor);
536536
}
537537

538+
redoStep() {
539+
redo(this.editor);
540+
}
541+
538542
getBreakpointPCs(): number[] {
539543
if (this.sourcefile == null) return [];
540544
const pcs: number[] = [];

src/ide/windows.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export class ProjectWindows {
2020
activediv: HTMLElement;
2121
lasterrors: WorkerError[];
2222
undofiles: string[];
23+
redofiles: string[];
2324

2425
constructor(containerdiv: HTMLElement, project: CodeProject) {
2526
this.containerdiv = containerdiv;
2627
this.project = project;
2728
this.undofiles = [];
29+
this.redofiles = [];
2830
}
2931
// TODO: delete windows ever?
3032

@@ -129,6 +131,7 @@ export class ProjectWindows {
129131
if (wnd && wnd.setText && typeof data === 'string') {
130132
wnd.setText(data);
131133
this.undofiles.push(fileid);
134+
this.redofiles = [];
132135
} else {
133136
this.project.updateFile(fileid, data);
134137
}
@@ -138,15 +141,26 @@ export class ProjectWindows {
138141
var fileid = this.undofiles.pop();
139142
var wnd = this.id2window[fileid];
140143
if (wnd && wnd.undoStep) {
141-
// undo source
142144
wnd.undoStep();
143-
// refresh active window from updated source
145+
this.redofiles.push(fileid);
144146
this.refresh(false);
145147
} else {
146148
bootbox.alert("No more steps to undo.");
147149
}
148150
}
149151

152+
redoStep() {
153+
var fileid = this.redofiles.pop();
154+
var wnd = this.id2window[fileid];
155+
if (wnd && wnd.redoStep) {
156+
wnd.redoStep();
157+
this.undofiles.push(fileid);
158+
this.refresh(false);
159+
} else {
160+
bootbox.alert("No more steps to redo.");
161+
}
162+
}
163+
150164
updateAllOpenWindows(store) {
151165
for (var fileid in this.id2window) {
152166
var wnd = this.id2window[fileid];

0 commit comments

Comments
 (0)