diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 34fe7d93d..85b0e0e1e 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -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 (); @@ -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 != "") { diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 5f43f0015..6e752bbca 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -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); @@ -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) {