From b67623b30cf5d65910c13dacc04e13cce0ab4edb Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Sun, 21 Apr 2024 05:16:18 +1000 Subject: [PATCH] Fixed Undo in Script Editor --- Scenes/OpenMap.gd | 3 +-- Scenes/ScriptEditor.gd | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Scenes/OpenMap.gd b/Scenes/OpenMap.gd index 5e9a6a50..8e3013b4 100644 --- a/Scenes/OpenMap.gd +++ b/Scenes/OpenMap.gd @@ -237,8 +237,6 @@ func continue_load(map): oDisplaySlxNumbers.update() - oMapSettingsWindow.visible = false - if oColumnEditor.visible == true: oColumnEditor.visible = false @@ -255,6 +253,7 @@ func continue_load_openmap(map): oCurrentMap.set_path_and_title(map) oCamera2D.reset_camera(M.xSize, M.ySize) oUndoStates.clear_history() + oMapSettingsWindow.visible = false if map == "": oMessage.quick('New map') else: diff --git a/Scenes/ScriptEditor.gd b/Scenes/ScriptEditor.gd index fb2f8872..eacd0fbe 100644 --- a/Scenes/ScriptEditor.gd +++ b/Scenes/ScriptEditor.gd @@ -14,6 +14,12 @@ var scriptHasBeenEditedInUnearth = false var SCRIPT_EDITOR_FONT_SIZE = 20 setget set_SCRIPT_EDITOR_FONT_SIZE, get_SCRIPT_EDITOR_FONT_SIZE +func _ready(): + oScriptTextEdit.get_menu().remove_item(0) # Remove Undo from menu because this Undo isn't used + oScriptTextEdit.get_menu().remove_item(0) # Remove Redo from menu because this Redo isn't used + oScriptTextEdit.get_menu().remove_item(0) # Remove Separator + + func set_SCRIPT_EDITOR_FONT_SIZE(setVal): SCRIPT_EDITOR_FONT_SIZE = setVal var current_font = oScriptTextEdit.get_font("font").duplicate() @@ -29,6 +35,7 @@ func initialize_for_new_map(): oScriptTextEdit.clear_undo_history() # Important so the 1st undo state is the loaded script func _on_ScriptTextEdit_text_changed(): + oScriptTextEdit.clear_undo_history() set_script_as_edited(true) set_script_data(oScriptTextEdit.text) update_empty_script_status() @@ -70,7 +77,17 @@ func load_generated_text(setWithString): update_texteditor() func update_texteditor(): - oScriptTextEdit.text = oDataScript.data + # This is for when pressing Undo + var scroll = oScriptTextEdit.scroll_vertical + var lineNumber = oScriptTextEdit.cursor_get_line() + var columnNumber = oScriptTextEdit.cursor_get_column() + + oScriptTextEdit.text = oDataScript.data # This resets a bunch of stuff in TextEdit like cursor line. + + oScriptTextEdit.cursor_set_line(lineNumber) + oScriptTextEdit.scroll_vertical = scroll + oScriptTextEdit.cursor_set_column(columnNumber) + update_empty_script_status() oScriptHelpers.start() # in the case of editing text file outside of Unearth