瀏覽代碼

CodeEditor: fix undo history that was erased by setCode()

lviguier 8 月之前
父節點
當前提交
0546976ab6
共有 4 個文件被更改,包括 13 次插入5 次删除
  1. 8 2
      hide/comp/CodeEditor.hx
  2. 1 0
      hide/comp/cdb/Formulas.hx
  3. 3 3
      hide/view/Domkit.hx
  4. 1 0
      libs/monaco/ScriptEditor.hx

+ 8 - 2
hide/comp/CodeEditor.hx

@@ -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);
 		}
 	}
@@ -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);
 	}
 

+ 1 - 0
hide/comp/cdb/Formulas.hx

@@ -70,6 +70,7 @@ class Formulas {
 	}
 
 	function reloadFile() {
+		ide.error("formulas reload");
 		load();
 		evaluateAll();
 		editor.save();

+ 3 - 3
hide/view/Domkit.hx

@@ -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);
 	}
 

+ 1 - 0
libs/monaco/ScriptEditor.hx

@@ -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;