Skip to content

Commit dc72820

Browse files
committed
Enhance quick open with better keyboard navigation and file opening behavior
1 parent 09c5172 commit dc72820

File tree

3 files changed

+99
-17
lines changed

3 files changed

+99
-17
lines changed

addons/script-ide/plugin.gd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,21 @@ func navigate_on_list(event: InputEvent, list: ItemList, submit: Callable):
444444
elif (event is InputEventKey && list.item_count > 0 && !list.is_anything_selected()):
445445
list.select(0)
446446

447+
func get_list_index(list: ItemList) -> int:
448+
var items: PackedInt32Array = list.get_selected_items()
449+
450+
if (items.is_empty()):
451+
return -1
452+
453+
return items[0]
454+
455+
func navigate_list(list: ItemList, index: int, amount: int):
456+
index = clamp(index + amount, 0, list.item_count - 1)
457+
458+
list.select(index)
459+
list.ensure_current_is_visible()
460+
list.accept_event()
461+
447462
func get_center_editor_rect() -> Rect2i:
448463
var script_editor: ScriptEditor = EditorInterface.get_script_editor()
449464

@@ -524,21 +539,6 @@ func open_scripts_popup():
524539

525540
script_filter_txt.grab_focus()
526541

527-
func get_list_index(list: ItemList) -> int:
528-
var items: PackedInt32Array = list.get_selected_items()
529-
530-
if (items.is_empty()):
531-
return -1
532-
533-
return items[0]
534-
535-
func navigate_list(list: ItemList, index: int, amount: int):
536-
index = clamp(index + amount, 0, list.item_count - 1)
537-
538-
list.select(index)
539-
list.ensure_current_is_visible()
540-
list.accept_event()
541-
542542
## Removes the script filter text and emits the signal so that the Tabs stay
543543
## and we do not break anything there.
544544
func update_script_text_filter():

addons/script-ide/quickopen/quick_open_panel.gd

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ func _ready() -> void:
3636
var file_system: EditorFileSystem = EditorInterface.get_resource_filesystem()
3737
file_system.filesystem_changed.connect(schedule_rebuild)
3838

39+
filter_txt.gui_input.connect(navigate_on_list.bind(files_list, open_file))
40+
3941
func open_file(index: int):
42+
hide()
43+
4044
var file: String = files_list.get_item_metadata(index)
41-
EditorInterface.edit_resource(load(file))
45+
46+
if (ResourceLoader.exists(file)):
47+
var res: Resource = load(file)
48+
EditorInterface.edit_resource(res)
49+
50+
if (res is PackedScene):
51+
EditorInterface.open_scene_from_path(file)
4252

4353
func schedule_rebuild():
4454
is_rebuild_cache = true
@@ -66,6 +76,9 @@ func on_show():
6676
filter_txt.select_all()
6777
filter_txt.grab_focus()
6878

79+
if (files_list.item_count > 0):
80+
files_list.select(0)
81+
6982
func rebuild_cache():
7083
scenes.clear()
7184
scripts.clear()
@@ -147,6 +160,55 @@ func fill_files_list_with(files: Array[FileData]):
147160
files_list.add_item(file_data.file_name, icon)
148161
files_list.set_item_metadata(files_list.item_count - 1, file)
149162

163+
func navigate_on_list(event: InputEvent, list: ItemList, submit: Callable):
164+
if (event.is_action_pressed(&"ui_text_submit")):
165+
var index: int = get_list_index(list)
166+
if (index == -1):
167+
return
168+
169+
submit.call(index)
170+
elif (event.is_action_pressed(&"ui_down", true)):
171+
var index: int = get_list_index(list)
172+
if (index == list.item_count - 1):
173+
return
174+
175+
navigate_list(list, index, 1)
176+
elif (event.is_action_pressed(&"ui_up", true)):
177+
var index: int = get_list_index(list)
178+
if (index <= 0):
179+
return
180+
181+
navigate_list(list, index, -1)
182+
elif (event.is_action_pressed(&"ui_page_down", true)):
183+
var index: int = get_list_index(list)
184+
if (index == list.item_count - 1):
185+
return
186+
187+
navigate_list(list, index, 5)
188+
elif (event.is_action_pressed(&"ui_page_up", true)):
189+
var index: int = get_list_index(list)
190+
if (index <= 0):
191+
return
192+
193+
navigate_list(list, index, -5)
194+
elif (event is InputEventKey && list.item_count > 0 && !list.is_anything_selected()):
195+
list.select(0)
196+
197+
func get_list_index(list: ItemList) -> int:
198+
var items: PackedInt32Array = list.get_selected_items()
199+
200+
if (items.is_empty()):
201+
return -1
202+
203+
return items[0]
204+
205+
func navigate_list(list: ItemList, index: int, amount: int):
206+
index = clamp(index + amount, 0, list.item_count - 1)
207+
208+
list.select(index)
209+
list.ensure_current_is_visible()
210+
list.accept_event()
211+
150212
class FileData:
151213
var file: String
152214
var file_name: String

addons/script-ide/quickopen/quick_open_panel.tscn

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1-
[gd_scene load_steps=3 format=3 uid="uid://d2pttchmj3n7q"]
1+
[gd_scene load_steps=5 format=3 uid="uid://d2pttchmj3n7q"]
22

33
[ext_resource type="Script" path="res://addons/script-ide/quickopen/quick_open_panel.gd" id="1_3tl1s"]
44

55
[sub_resource type="ButtonGroup" id="ButtonGroup_8s5oe"]
66
resource_local_to_scene = false
77

8+
[sub_resource type="Image" id="Image_k3p7r"]
9+
data = {
10+
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 225, 225, 225, 68, 224, 224, 224, 184, 224, 224, 224, 240, 224, 224, 224, 232, 224, 224, 224, 186, 227, 227, 227, 62, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 129, 224, 224, 224, 254, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 122, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 225, 225, 225, 68, 224, 224, 224, 254, 224, 224, 224, 254, 224, 224, 224, 123, 224, 224, 224, 32, 224, 224, 224, 33, 225, 225, 225, 125, 224, 224, 224, 254, 224, 224, 224, 254, 226, 226, 226, 69, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 184, 224, 224, 224, 255, 224, 224, 224, 123, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 225, 225, 225, 125, 224, 224, 224, 255, 225, 225, 225, 174, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 240, 224, 224, 224, 255, 231, 231, 231, 31, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 226, 226, 226, 35, 224, 224, 224, 255, 224, 224, 224, 233, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 232, 224, 224, 224, 255, 224, 224, 224, 32, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 228, 228, 228, 37, 224, 224, 224, 255, 224, 224, 224, 228, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 186, 224, 224, 224, 255, 224, 224, 224, 123, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 130, 224, 224, 224, 255, 224, 224, 224, 173, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 227, 227, 227, 62, 224, 224, 224, 255, 224, 224, 224, 254, 225, 225, 225, 126, 225, 225, 225, 34, 227, 227, 227, 36, 224, 224, 224, 131, 224, 224, 224, 255, 224, 224, 224, 255, 226, 226, 226, 77, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 122, 224, 224, 224, 254, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 210, 231, 231, 231, 21, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 226, 226, 226, 69, 225, 225, 225, 174, 224, 224, 224, 233, 224, 224, 224, 228, 224, 224, 224, 173, 226, 226, 226, 77, 224, 224, 224, 210, 224, 224, 224, 255, 224, 224, 224, 210, 231, 231, 231, 21, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 231, 231, 231, 21, 224, 224, 224, 210, 224, 224, 224, 255, 224, 224, 224, 210, 231, 231, 231, 21, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 231, 231, 231, 21, 224, 224, 224, 210, 224, 224, 224, 255, 224, 224, 224, 210, 231, 231, 231, 21, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 231, 231, 231, 21, 224, 224, 224, 210, 224, 224, 224, 227, 225, 225, 225, 34, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 231, 231, 231, 21, 225, 225, 225, 34, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
11+
"format": "RGBA8",
12+
"height": 16,
13+
"mipmaps": false,
14+
"width": 16
15+
}
16+
17+
[sub_resource type="ImageTexture" id="ImageTexture_bjbm4"]
18+
image = SubResource("Image_k3p7r")
19+
820
[node name="QuickOpenPanel" type="PopupPanel"]
21+
size = Vector2i(473, 100)
22+
visible = true
923
script = ExtResource("1_3tl1s")
1024

1125
[node name="PanelContainer" type="PanelContainer" parent="."]
1226
anchors_preset = 15
1327
anchor_right = 1.0
1428
anchor_bottom = 1.0
29+
offset_left = 4.0
30+
offset_top = 4.0
31+
offset_right = -4.0
32+
offset_bottom = -4.0
1533
grow_horizontal = 2
1634
grow_vertical = 2
1735
size_flags_horizontal = 3
@@ -95,8 +113,10 @@ popup/item_1/id = 1
95113
unique_name_in_owner = true
96114
layout_mode = 2
97115
placeholder_text = "Filter files"
116+
right_icon = SubResource("ImageTexture_bjbm4")
98117

99118
[node name="FilesList" type="ItemList" parent="PanelContainer/MarginContainer/VBoxContainer"]
100119
unique_name_in_owner = true
101120
layout_mode = 2
102121
size_flags_vertical = 3
122+
allow_reselect = true

0 commit comments

Comments
 (0)