From 76932313aedb1f83d8ffb498d01ce9de73e459d4 Mon Sep 17 00:00:00 2001 From: teebarjunk Date: Mon, 11 Oct 2021 16:41:54 -0400 Subject: [PATCH] selection bug --- addons/text_editor/TE_FileEditor.gd | 16 ++++- addons/text_editor/TE_FilesList.gd | 2 +- addons/text_editor/TE_TextEditor.gd | 69 +++++++++++--------- addons/text_editor/ext/TE_ExtensionHelper.gd | 23 ++++--- addons/text_editor/ext/ext_json.gd | 10 +-- project.godot | 4 -- 6 files changed, 74 insertions(+), 50 deletions(-) diff --git a/addons/text_editor/TE_FileEditor.gd b/addons/text_editor/TE_FileEditor.gd index 58785d2..e9b1301 100644 --- a/addons/text_editor/TE_FileEditor.gd +++ b/addons/text_editor/TE_FileEditor.gd @@ -19,6 +19,7 @@ var last_selection:Array = [0, 0, 0, 0] var hscroll:int = 0 var vscroll:int = 0 +var in_focus:bool = false func _ready(): var _e @@ -28,6 +29,8 @@ func _ready(): _e = editor.connect("file_selected", self, "_file_selected") _e = editor.connect("file_renamed", self, "_file_renamed") _e = connect("text_changed", self, "text_changed") + _e = connect("focus_entered", self, "set", ["in_focus", true]) + _e = connect("focus_exited", self, "set", ["in_focus", false]) if get_parent() is TabContainer: get_parent().connect("tab_changed", self, "_tab_changed") @@ -81,9 +84,20 @@ func _input(e): if not editor.is_plugin_active(): return - if not visible: + if not visible or not in_focus: return + # save files + if e is InputEventKey and e.pressed and e.control: + if e.scancode == KEY_S: + if modified: + get_tree().set_input_as_handled() + editor.save_files() + + if e.scancode == KEY_W and not e.shift: + get_tree().set_input_as_handled() + close() + # remember last selection if e is InputEventKey and e.pressed: last_key = e.scancode diff --git a/addons/text_editor/TE_FilesList.gd b/addons/text_editor/TE_FilesList.gd index f54c066..e1ce542 100644 --- a/addons/text_editor/TE_FilesList.gd +++ b/addons/text_editor/TE_FilesList.gd @@ -191,7 +191,7 @@ func url(s:String, url:String) -> String: return "[url=%s]%s[/url]" % [url, s] const FOLDER:String = "🗀" # not visible in godot func _draw_dir(dir:Dictionary, deep:int): var is_tagging = editor.is_tagging() - var dimmest:float = .65 if is_tagging else 0.0 + var dimmest:float = .5 if is_tagging else 0.0 var space = clr("┃ ".repeat(deep), Color.white.darkened(.8)) var file:String = dir.file_path diff --git a/addons/text_editor/TE_TextEditor.gd b/addons/text_editor/TE_TextEditor.gd index d380253..a1352c0 100644 --- a/addons/text_editor/TE_TextEditor.gd +++ b/addons/text_editor/TE_TextEditor.gd @@ -116,9 +116,11 @@ func _ready(): popup_file = menu_file.get_popup() popup_file.clear() popup_file.add_font_override("font", FONT_R) - popup_file.add_item("New File") - popup_file.add_item("New Folder") - _e = popup_file.connect("index_pressed", self, "_menu_file") + popup_file.add_item("New File", 100) + popup_file.add_item("New Folder", 200) + popup_file.add_separator() + popup_file.add_item("Open last closed", 300) + _e = popup_file.connect("id_pressed", self, "_menu_file") # view menu_view.add_font_override("font", FONT_R) @@ -268,10 +270,14 @@ func _apply_fonts(n:Node): if n.has_font("font"): n.add_font_override("font", FONT_R) -func _menu_file(a): - match menu_file.get_popup().items[a]: - "New File": popup_create_file() - "New Folder": popup_create_dir() +func _menu_file(id): +# var index = popup_file.get_item_index(id) +# var data = popup_file.items[index] +# prints(id, index, data) + match id: + 100: popup_create_file() # "New File" + 200: popup_create_dir() # "New Folder" + 300: open_last_file() # "Open last closed" func _menu_view_dir(index:int): match index: @@ -411,29 +417,32 @@ func create_dir(file_path:String): func _debug_pressed(): set_directory() -func _unhandled_key_input(e:InputEventKey): - if not e.pressed: - return - - if e.control: - # save - if e.scancode == KEY_S: - emit_signal("save_files") - - # close/unclose tab - elif e.scancode == KEY_W: - if e.shift: - open_last_file() - else: - close_selected() - - elif e.scancode == KEY_R: - sort_files() - - else: - return - - get_tree().set_input_as_handled() +#func _unhandled_key_input(e:InputEventKey): +# if not e.pressed: +# return +# +# if e.control: +# # save +# if e.scancode == KEY_S: +# emit_signal("save_files") +# +# # close/unclose tab +# elif e.scancode == KEY_W: +# if e.shift: +# open_last_file() +# else: +# close_selected() +# +# elif e.scancode == KEY_R: +# sort_files() +# +# else: +# return +# +# get_tree().set_input_as_handled() + +func save_files(): + emit_signal("save_files") func sort_files(): TE_Util.dig(file_list, self, "_sort") diff --git a/addons/text_editor/ext/TE_ExtensionHelper.gd b/addons/text_editor/ext/TE_ExtensionHelper.gd index d59ce58..2fb75a2 100644 --- a/addons/text_editor/ext/TE_ExtensionHelper.gd +++ b/addons/text_editor/ext/TE_ExtensionHelper.gd @@ -21,13 +21,20 @@ func toggle_comment(t:TextEdit, head:String="", tail:String=""): var cursor_c if not t.is_selection_active(): - var l = t.cursor_get_line() - var lt = t.get_line(l) - wasnt_selected = lt.strip_edges() == "" - cursor_l = t.cursor_get_line() - cursor_c = t.cursor_get_column() - var s = len(lt) - len(lt.strip_edges(true, false)) - t.select(l, s, l, len(t.get_line(l))) + var c = t.cursor_get_column() + t.insert_text_at_cursor(head + tail) + t.cursor_set_column(c + len(head)) + return +# var l = t.cursor_get_line() +# var lt = t.get_line(l) +# wasnt_selected = lt.strip_edges() == "" +# cursor_l = t.cursor_get_line() +# cursor_c = t.cursor_get_column() +# var s = len(lt) - len(lt.strip_edges(true, false)) +# t.select(l, s, l, len(t.get_line(l))) + +# if not t.is_selection_active(): +# return var l1 = t.get_selection_from_line() var c1 = t.get_selection_from_column() @@ -51,8 +58,6 @@ func toggle_comment(t:TextEdit, head:String="", tail:String=""): var l2 = l1 + len(l)-1 var c2 = c1 + len(l[-1]) t.select(l1, c1, l2, c2) - - return [old, new] func add_symbol(line:int=-1, deep:int=0, name:String="") -> Dictionary: var symbol = { deep=deep, name=name, tags=[] } diff --git a/addons/text_editor/ext/ext_json.gd b/addons/text_editor/ext/ext_json.gd index 6b1e350..f1fe432 100644 --- a/addons/text_editor/ext/ext_json.gd +++ b/addons/text_editor/ext/ext_json.gd @@ -18,11 +18,11 @@ func get_symbols(t:String): last = add_symbol(i, deep, key) # tags - elif "/* #" in lines[i]: - for tag in lines[i].split("/* #", true, 1)[1].split("*/", true, 1)[0].split("#"): - tag = tag.strip_edges() - if tag: - last.tags.append(tag) +# elif "/* #" in lines[i]: +# for tag in lines[i].split("/* #", true, 1)[1].split("*/", true, 1)[0].split("#"): +# tag = tag.strip_edges() +# if tag: +# last.tags.append(tag) elif '"#": "' in lines[i]: for tag in lines[i].split('"#": "', true, 1)[1].split('"', true, 1)[0].split("#"): diff --git a/project.godot b/project.godot index 76c0569..77b3eb0 100644 --- a/project.godot +++ b/project.godot @@ -42,10 +42,6 @@ config/name="TextEdit" run/main_scene="res://addons/text_editor/TextEditor.tscn" config/icon="res://icon.png" -[editor_plugins] - -enabled=PoolStringArray( "res://addons/text_editor/plugin.cfg" ) - [physics] common/enable_pause_aware_picking=true