Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve show_replace action #1374

Merged
merged 3 commits into from
Nov 30, 2023
Merged
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
18 changes: 16 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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 @@ -1056,7 +1056,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 @@ -1070,6 +1070,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