Skip to content

Commit

Permalink
Merge pull request #148 from mdenet/feature/only-save-dirty-panels
Browse files Browse the repository at this point in the history
Manage editor state when changing contents
  • Loading branch information
barnettwilliam authored Dec 11, 2023
2 parents 699212a + c8db740 commit a547712
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions platform/src/ConsolePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ConsolePanel extends Panel {
element.style.color = "black";
this.editor.getSession().setUseWrapMode(false);
this.editor.setValue(str, 1);
// Reset undo manager
this.editor.session.getUndoManager().reset();
// Scroll to the bottom. This works because we're really still using an ACE editor even in the console panel.
this.editor.renderer.scrollToLine(Number.POSITIVE_INFINITY);
}
Expand Down
10 changes: 9 additions & 1 deletion platform/src/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Panel {
} else {
this.editor = editor;
}

// Reset undo manager
this.editor.session.getUndoManager().reset();

this.visible = true;
}
Expand Down Expand Up @@ -73,7 +76,10 @@ class Panel {
* @returns a promise
*/
save(fileHandler) {
return fileHandler.storeFile(this.getFileUrl(), this.getValueSha(), this.getValue());
let thisEditor = this.editor;
return fileHandler.storeFile(this.getFileUrl(), this.getValueSha(), this.getValue())
// Mark the editor clean if the save completed
.then((response) => { thisEditor.session.getUndoManager().markClean(); });
}

getEditor() {
Expand All @@ -86,6 +92,8 @@ class Panel {

setValue(value) {
this.editor.setValue((value+""), 1);
// Reset undo manager
this.editor.session.getUndoManager().markClean();
}

getValueSha() {
Expand Down
3 changes: 2 additions & 1 deletion platform/src/ProgramPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class ProgramPanel extends Panel {


canSave() {
return true;
// Only save if there are any actual changes to save -- this avoids empty commits.
return !(this.editor.session.getUndoManager().isClean());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion platform/src/XtextEditorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class XtextEditorPanel extends Panel {
}

canSave() {
return true;
// Only save if there are any actual changes to save -- this avoids empty commits.
return !(this.editor.session.getUndoManager().isClean());
}

/**
Expand Down

0 comments on commit a547712

Please sign in to comment.