Skip to content

Commit

Permalink
CodeEditor: fix undo history that was erased by setCode()
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoVgr committed Jan 7, 2025
1 parent 099c2ea commit 0546976
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions hide/comp/CodeEditor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CodeEditor extends Component {
var newCode = [for( l in StringTools.trim(code).split("\n") ) StringTools.rtrim(l)].join("\n");
if( newCode != code ) {
var p = editor.getPosition();
setCode(newCode);
setCode(newCode, true);
editor.setPosition(p);
}
}
Expand All @@ -123,7 +123,13 @@ class CodeEditor extends Component {
return editor.getValue({preserveBOM:true});
}

public function setCode( code : String ) {
public function setCode( code : String, keepHistory : Bool = false ) {
if ( keepHistory ) {
editor.executeEdits('set_code', [{ identifier: 'delete', range: new monaco.Range(1, 1, 10000, 1), text: '', forceMoveMarkers: true }]);
editor.executeEdits('set_code', [{ identifier: 'insert', range: new monaco.Range(1, 1, 1, 1), text: code, forceMoveMarkers: true }]);
return;
}

editor.setValue(code);
}

Expand Down
1 change: 1 addition & 0 deletions hide/comp/cdb/Formulas.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Formulas {
}

function reloadFile() {
ide.error("formulas reload");
load();
evaluateAll();
editor.save();
Expand Down
6 changes: 3 additions & 3 deletions hide/view/Domkit.hx
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ class Domkit extends FileView {
};
var str = hrt.impl.DomkitViewer.toStr(data);
prevSave = data;
if( data.css != cssEditor.code ) cssEditor.setCode(data.css);
if( data.dml != dmlEditor.code ) dmlEditor.setCode(data.dml);
if( data.params != paramsEditor.code ) paramsEditor.setCode(data.params);
if( data.css != cssEditor.code ) cssEditor.setCode(data.css, true);
if( data.dml != dmlEditor.code ) dmlEditor.setCode(data.dml, true);
if( data.params != paramsEditor.code ) paramsEditor.setCode(data.params, true);
sys.io.File.saveContent(getPath(),str);
}

Expand Down
1 change: 1 addition & 0 deletions libs/monaco/ScriptEditor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern class ScriptEditor {
function getModel() : Model;
function deltaDecorations( old : Array<String>, newDeco : Array<ModelDeltaDecoration> ) : Array<String>;
function setValue( script : String ) : Void;
function executeEdits( source : String, edits : Array<Dynamic>, ?endCursorState : Array<Dynamic> ) : Void;
function updateOptions( options : Dynamic ) : Void;
function getPosition() : Position;
function setPosition( p : Position ) : Void;
Expand Down

0 comments on commit 0546976

Please sign in to comment.