Skip to content

Commit

Permalink
Separate action_show_replace; focus replace entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Paul Wootten authored and Jeremy Paul Wootten committed Sep 22, 2023
1 parent 315f702 commit 96de074
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace Scratch {
{ ACTION_PREFERENCES, action_preferences },
{ ACTION_UNDO, action_undo },
{ ACTION_REDO, action_redo },
{ ACTION_SHOW_REPLACE, action_fetch },
{ ACTION_SHOW_REPLACE, action_show_replace },
{ ACTION_TO_LOWER_CASE, action_to_lower_case },
{ ACTION_TO_UPPER_CASE, action_to_upper_case },
{ ACTION_DUPLICATE, action_duplicate },
Expand Down Expand Up @@ -1012,7 +1012,7 @@ namespace Scratch {
/** Not a toggle action - linked to keyboard short cut (Ctrl-f). **/
private string current_search_term = "";
private void action_fetch (SimpleAction action, Variant? param) {
current_search_term = param.get_string ();
current_search_term = param != null ? param.get_string () : "";
if (!search_revealer.child_revealed) {
var show_find_action = Utils.action_from_group (ACTION_SHOW_FIND, actions);
if (show_find_action.enabled) {
Expand All @@ -1026,6 +1026,20 @@ namespace Scratch {
}
}

private void action_show_replace (SimpleAction action) {
action_fetch (action, null);
// May have to wait for the search bar to be revealed before we can grab focus
if (search_revealer.child_revealed) {
search_bar.replace_entry.grab_focus ();
} else {
ulong map_handler = 0;
map_handler = search_bar.map.connect_after (() => {
search_bar.replace_entry.grab_focus ();
search_bar.disconnect (map_handler);
});
}
}

private void action_find_next () {
search_bar.search_next ();
}
Expand Down

0 comments on commit 96de074

Please sign in to comment.