Skip to content

Commit

Permalink
Do not replace search term with doc selection unless action-fetch act…
Browse files Browse the repository at this point in the history
…ivated
  • Loading branch information
Jeremy Wootten authored and Jeremy Wootten committed Jan 16, 2025
1 parent e8cc677 commit 9d698f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
24 changes: 12 additions & 12 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,18 @@ namespace Scratch {
}

private void set_search_text () {
var current_doc = get_current_document ();
// This is also called when all documents are closed.
if (current_doc != null) {
var selected_text = current_doc.get_selected_text (false);
if (selected_text != "" && selected_text.length < MAX_SEARCH_TEXT_LENGTH) {
current_search_term = selected_text.split ("\n", 2)[0];
search_bar.search_entry.text = current_search_term;
}

search_bar.search_entry.grab_focus (); /* causes loss of document selection */
}

if (current_search_term != "") {
search_bar.search_entry.text = current_search_term;
search_bar.search_entry.grab_focus ();
Expand All @@ -1248,18 +1260,6 @@ namespace Scratch {
// Always search on what is showing in search entry
current_search_term = search_bar.search_entry.text;
search_bar.search_entry.grab_focus ();
} else {
var current_doc = get_current_document ();
// This is also called when all documents are closed.
if (current_doc != null) {
var selected_text = current_doc.get_selected_text (false);
if (selected_text != "" && selected_text.length < MAX_SEARCH_TEXT_LENGTH) {
current_search_term = selected_text.split ("\n", 2)[0];
search_bar.search_entry.text = current_search_term;
}

search_bar.search_entry.grab_focus (); /* causes loss of document selection */
}
}

if (current_search_term != "") {
Expand Down
14 changes: 0 additions & 14 deletions src/Widgets/SearchBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,9 @@ namespace Scratch.Widgets {
return;
} else if (this.text_buffer != null) {
this.text_buffer.changed.disconnect (on_text_buffer_changed);
this.text_view.selection_changed.disconnect (on_selection_changed);
}

this.text_view = text_view;
this.text_view.selection_changed.connect (on_selection_changed);
this.text_buffer = text_view.get_buffer ();
this.text_buffer.changed.connect (on_text_buffer_changed);
this.search_context = new Gtk.SourceSearchContext (text_buffer as Gtk.SourceBuffer, null);
Expand All @@ -251,20 +249,8 @@ namespace Scratch.Widgets {
update_search_widgets ();
}

private void on_selection_changed () {

var selected_text = text_view.get_selected_text ();
bool clear_required;
if (search_context.settings.case_sensitive) {
clear_required = selected_text != search_entry.text;
} else {
clear_required = selected_text.down () != search_entry.text.down ();
}

if (clear_required) {
search_entry.text = "";
}
}

private void on_replace_entry_activate () {
if (text_buffer == null) {
Expand Down

0 comments on commit 9d698f8

Please sign in to comment.