Skip to content

Do not jump to search match when sourcing search string from selected text in document.#722

Open
abebinder wants to merge 1 commit intolinuxmint:masterfrom
abebinder:selection_fix_no_debug_logs
Open

Do not jump to search match when sourcing search string from selected text in document.#722
abebinder wants to merge 1 commit intolinuxmint:masterfrom
abebinder:selection_fix_no_debug_logs

Conversation

@abebinder
Copy link

@abebinder abebinder commented Feb 16, 2026

Related Issue

#402

TLDR

An async callback runs whenever the searchbar text is changed which changes the selection to the first match in the document

xed/xed/xed-searchbar.c

Lines 140 to 141 in 78ff0d1

gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match_start, &match_end);
xed_view_scroll_to_cursor (view);

I tried to stop the callback from running for case where we select text in the document then do a search.

Before

2026-02-16.21-10-49.mp4

After

2026-02-16.21-26-59.mp4

Explanation Of Problem

When you select text in the document and then do a search using Search -> Find menu button (or ctrl + f), the search bar is opened and the selected text is copied into the search bar. All this rocks and is great and is like other editors.

Ideally, after that happens, the text in the searchbar would now be selected. This is what happens for other editors (eg: sublime). It also is consistent with xeds behavior when you do a Search->Find without any text in the document selected (in that case, it will open the search bar and select whatever was in the search bar previously).

However, when you do have text in the document selected, this does not happen for xed. This is because the following call chain happens:

search_text_entry_changed -> do_find -> run_forward_search -> forward_search_finished

In forward_search_finished, we change the selection of the text to one of the "matches" for that search in the document:

xed/xed/xed-searchbar.c

Lines 140 to 141 in 78ff0d1

gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match_start, &match_end);
xed_view_scroll_to_cursor (view);

This "forward search" which changes the selection to the matches in the document is good behavior when we are typing in the search bar but not really after initializing the search bar with selected text from the document.

Explanation of Fix

Add logic that makes it so we don't call the "run_forward_search" function if we are initializing the search bar with selected text from the document.

Alternative Solution

One thing I noticed when using sublime is that the text selection never changes at all when using find and the next/previous buttons. It always stays selected in the search bar. They just highlight the matches instead of selecting them. That makes lots of sense to me but is more involved change. Would be willing to try that though if asked.

Screenshot from sublime:

sublime

@abebinder abebinder changed the title Do not jump to search match when sourcing search string from selected text. [WIP] Do not jump to search match when sourcing search string from selected text. Feb 16, 2026
@abebinder abebinder marked this pull request as ready for review February 17, 2026 07:31
@abebinder abebinder changed the title [WIP] Do not jump to search match when sourcing search string from selected text. Do not jump to search match when sourcing search string from selected text. Feb 17, 2026
@abebinder abebinder changed the title Do not jump to search match when sourcing search string from selected text. Do not jump to search match when sourcing search string from selected text in document. Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments