Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,13 @@ namespace Scratch {

// If selected text covers more than one line return just the first.
public void set_selected_text_for_search () {
// Do not overwrite search term if we are editing the entry.
if (search_bar.is_focused) {
return;
}

var doc = get_current_document ();

var selected_text = doc != null ? doc.get_selected_text (false) : "";
var search_term = "";
if (selected_text.contains ("\n")) {
Expand Down Expand Up @@ -1186,19 +1192,21 @@ namespace Scratch {
}

private void find (string search_term = "") {
// Set search term before focusing search bar else maybe ineffective
if (search_term != "") {
search_bar.set_search_entry_text (search_term);
} else {
set_selected_text_for_search ();
}

if (!search_bar.is_revealed) {
var show_find_action = Utils.action_from_group (ACTION_TOGGLE_SHOW_FIND, actions);
if (show_find_action.enabled) {
// This focuses the search bar
show_find_action.activate (new Variant ("b", true));
}
}

if (search_term != "") {
search_bar.set_search_entry_text (search_term);
} else {
set_selected_text_for_search ();
}

search_bar.search ();
}

Expand Down
9 changes: 7 additions & 2 deletions src/Widgets/SearchBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,13 @@ namespace Scratch.Widgets {
return false;
}

update_search_widgets ();
return false;
Idle.add (() => {
update_search_widgets ();
search_entry.select_region (0, -1);
return Source.REMOVE;
});

return Gdk.EVENT_PROPAGATE;
}

public bool search () {
Expand Down