selection bug

This commit is contained in:
teebarjunk 2021-10-11 16:41:54 -04:00
parent 436b7b8f10
commit 76932313ae
6 changed files with 74 additions and 50 deletions

View File

@ -19,6 +19,7 @@ var last_selection:Array = [0, 0, 0, 0]
var hscroll:int = 0 var hscroll:int = 0
var vscroll:int = 0 var vscroll:int = 0
var in_focus:bool = false
func _ready(): func _ready():
var _e var _e
@ -28,6 +29,8 @@ func _ready():
_e = editor.connect("file_selected", self, "_file_selected") _e = editor.connect("file_selected", self, "_file_selected")
_e = editor.connect("file_renamed", self, "_file_renamed") _e = editor.connect("file_renamed", self, "_file_renamed")
_e = connect("text_changed", self, "text_changed") _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: if get_parent() is TabContainer:
get_parent().connect("tab_changed", self, "_tab_changed") get_parent().connect("tab_changed", self, "_tab_changed")
@ -81,9 +84,20 @@ func _input(e):
if not editor.is_plugin_active(): if not editor.is_plugin_active():
return return
if not visible: if not visible or not in_focus:
return 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 # remember last selection
if e is InputEventKey and e.pressed: if e is InputEventKey and e.pressed:
last_key = e.scancode last_key = e.scancode

View File

@ -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 const FOLDER:String = "🗀" # not visible in godot
func _draw_dir(dir:Dictionary, deep:int): func _draw_dir(dir:Dictionary, deep:int):
var is_tagging = editor.is_tagging() 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 space = clr("".repeat(deep), Color.white.darkened(.8))
var file:String = dir.file_path var file:String = dir.file_path

View File

@ -116,9 +116,11 @@ func _ready():
popup_file = menu_file.get_popup() popup_file = menu_file.get_popup()
popup_file.clear() popup_file.clear()
popup_file.add_font_override("font", FONT_R) popup_file.add_font_override("font", FONT_R)
popup_file.add_item("New File") popup_file.add_item("New File", 100)
popup_file.add_item("New Folder") popup_file.add_item("New Folder", 200)
_e = popup_file.connect("index_pressed", self, "_menu_file") popup_file.add_separator()
popup_file.add_item("Open last closed", 300)
_e = popup_file.connect("id_pressed", self, "_menu_file")
# view # view
menu_view.add_font_override("font", FONT_R) menu_view.add_font_override("font", FONT_R)
@ -268,10 +270,14 @@ func _apply_fonts(n:Node):
if n.has_font("font"): if n.has_font("font"):
n.add_font_override("font", FONT_R) n.add_font_override("font", FONT_R)
func _menu_file(a): func _menu_file(id):
match menu_file.get_popup().items[a]: # var index = popup_file.get_item_index(id)
"New File": popup_create_file() # var data = popup_file.items[index]
"New Folder": popup_create_dir() # 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): func _menu_view_dir(index:int):
match index: match index:
@ -411,29 +417,32 @@ func create_dir(file_path:String):
func _debug_pressed(): func _debug_pressed():
set_directory() set_directory()
func _unhandled_key_input(e:InputEventKey): #func _unhandled_key_input(e:InputEventKey):
if not e.pressed: # if not e.pressed:
return # return
#
if e.control: # if e.control:
# save # # save
if e.scancode == KEY_S: # if e.scancode == KEY_S:
emit_signal("save_files") # emit_signal("save_files")
#
# close/unclose tab # # close/unclose tab
elif e.scancode == KEY_W: # elif e.scancode == KEY_W:
if e.shift: # if e.shift:
open_last_file() # open_last_file()
else: # else:
close_selected() # close_selected()
#
elif e.scancode == KEY_R: # elif e.scancode == KEY_R:
sort_files() # sort_files()
#
else: # else:
return # return
#
get_tree().set_input_as_handled() # get_tree().set_input_as_handled()
func save_files():
emit_signal("save_files")
func sort_files(): func sort_files():
TE_Util.dig(file_list, self, "_sort") TE_Util.dig(file_list, self, "_sort")

View File

@ -21,13 +21,20 @@ func toggle_comment(t:TextEdit, head:String="", tail:String=""):
var cursor_c var cursor_c
if not t.is_selection_active(): if not t.is_selection_active():
var l = t.cursor_get_line() var c = t.cursor_get_column()
var lt = t.get_line(l) t.insert_text_at_cursor(head + tail)
wasnt_selected = lt.strip_edges() == "" t.cursor_set_column(c + len(head))
cursor_l = t.cursor_get_line() return
cursor_c = t.cursor_get_column() # var l = t.cursor_get_line()
var s = len(lt) - len(lt.strip_edges(true, false)) # var lt = t.get_line(l)
t.select(l, s, l, len(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 l1 = t.get_selection_from_line()
var c1 = t.get_selection_from_column() 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 l2 = l1 + len(l)-1
var c2 = c1 + len(l[-1]) var c2 = c1 + len(l[-1])
t.select(l1, c1, l2, c2) t.select(l1, c1, l2, c2)
return [old, new]
func add_symbol(line:int=-1, deep:int=0, name:String="") -> Dictionary: func add_symbol(line:int=-1, deep:int=0, name:String="") -> Dictionary:
var symbol = { deep=deep, name=name, tags=[] } var symbol = { deep=deep, name=name, tags=[] }

View File

@ -18,11 +18,11 @@ func get_symbols(t:String):
last = add_symbol(i, deep, key) last = add_symbol(i, deep, key)
# tags # tags
elif "/* #" in lines[i]: # elif "/* #" in lines[i]:
for tag in lines[i].split("/* #", true, 1)[1].split("*/", true, 1)[0].split("#"): # for tag in lines[i].split("/* #", true, 1)[1].split("*/", true, 1)[0].split("#"):
tag = tag.strip_edges() # tag = tag.strip_edges()
if tag: # if tag:
last.tags.append(tag) # last.tags.append(tag)
elif '"#": "' in lines[i]: elif '"#": "' in lines[i]:
for tag in lines[i].split('"#": "', true, 1)[1].split('"', true, 1)[0].split("#"): for tag in lines[i].split('"#": "', true, 1)[1].split('"', true, 1)[0].split("#"):

View File

@ -42,10 +42,6 @@ config/name="TextEdit"
run/main_scene="res://addons/text_editor/TextEditor.tscn" run/main_scene="res://addons/text_editor/TextEditor.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[editor_plugins]
enabled=PoolStringArray( "res://addons/text_editor/plugin.cfg" )
[physics] [physics]
common/enable_pause_aware_picking=true common/enable_pause_aware_picking=true