script-ide icon indicating copy to clipboard operation
script-ide copied to clipboard

[feature request] highlight current and previous file on quick search panel

Open KnIfER opened this issue 3 months ago • 1 comments

on the list of quick search panel, current file and previous file should be colored .

Or simpler, focus on the previous file, so that pressing Enter switches to the previous file

KnIfER avatar Aug 31 '25 12:08 KnIfER

it's more easy to achieve than a recent file list.

but it's not very useful to just highlight or focus items. so I decided to move the current and previous file to the end of list. ( dont know how to insert item to top for godot 4.0 )

code :

quick_open_panel.gd


func remove_item_at(lv:ItemList, pos):
	var ret = [files_list.get_item_text(pos)
	, files_list.get_item_icon(pos)
	, files_list.get_item_metadata(pos)
	, files_list.get_item_tooltip(pos)
	]
	files_list.remove_item(pos)
	return ret

var now_open_idx = -1
var prev_open_idx = -1

func focus_and_select_first():

...


	var prev_last = now_open_idx
	now_open_idx = -1
	prev_open_idx = -1
		
	if prev_last>=0 && prev_last<files_list.item_count:
		files_list.set_item_custom_fg_color(prev_last, Color.WHITE)

	for i in range((files_list.item_count)):
		if files_list.get_item_metadata(i) == now_open_file:
			now_open_idx = i
			break
#	printt('now_open_file::', files_list.get_item_text(0));
	if now_open_idx>0:
		var item = remove_item_at(files_list, now_open_idx)
		var idx = files_list.add_item(item[0], item[1])
		files_list.set_item_metadata(idx, item[2])
		files_list.set_item_tooltip(idx, item[3])
		now_open_idx = idx
	
	for i in range((files_list.item_count)):
		if files_list.get_item_metadata(i) == prev_open_file:
			prev_open_idx = i
			break	
	if prev_open_idx>0:
		var item = remove_item_at(files_list, prev_open_idx)
		var idx = files_list.add_item(item[0], item[1])
		files_list.set_item_metadata(idx, item[2])
		files_list.set_item_tooltip(idx, item[3])
		prev_open_idx = idx
		now_open_idx = now_open_idx - 1
		
			
	if now_open_idx>=0:
		files_list.set_item_custom_fg_color(now_open_idx,  Color.ORANGE)
		
	var sel:=-1
	if prev_open_idx>0:
		sel = prev_open_idx
	elif now_open_idx>=0:
		sel = now_open_idx
	if sel>=0:
		files_list.select(sel)
		scroll_to_item(files_list, sel-5)
	

func scroll_to_item(lv:ItemList, index: int):
	if index < 0 or index >= lv.get_item_count():
		print("Invalid item index.")
		return
	var v_scroll_bar = lv.get_v_scroll_bar()
	if v_scroll_bar:
		var item_height = 35
		var target_scroll_value = item_height * index
		target_scroll_value = clampi(target_scroll_value, v_scroll_bar.min_value, v_scroll_bar.max_value)
		v_scroll_bar.value = target_scroll_value

func open_file(index: int):


	if (ResourceLoader.exists(file)):
		if now_open_file != file:
			prev_open_file = now_open_file
			now_open_file = file

plugin.gd

func on_tab_changed(index: int):

...

if (is_auto_navigate_in_fs && script_editor.get_current_script() != null):
		var file: String = script_editor.get_current_script().get_path()

		if (file.contains(BUILT_IN_SCRIPT)):
			# We navigate to the scene in case of a built-in script.
			file = file.get_slice(BUILT_IN_SCRIPT, 0)

		if quick_open_popup && quick_open_popup.now_open_file != file:
			quick_open_popup.prev_open_file = quick_open_popup.now_open_file
			quick_open_popup.now_open_file = file
#		printt('file_to_navigate::', file);
		file_to_navigate = file
	else:
		file_to_navigate = &""


KnIfER avatar Sep 01 '25 13:09 KnIfER