diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 0ea5804d3..db444e8ff 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1073,6 +1073,10 @@ namespace Scratch { search_bar.search_entry.text = current_search_term; search_bar.search_entry.grab_focus (); search_bar.search_next (); + } else if (search_bar.search_entry.text != "") { + // 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. diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 3072c167c..adb7f522c 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -26,7 +26,6 @@ namespace Scratch.Widgets { MIXED, ALWAYS } - public weak MainWindow window { get; construct; } private Gtk.Button tool_arrow_up; @@ -235,8 +234,11 @@ 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); @@ -250,6 +252,13 @@ namespace Scratch.Widgets { update_search_widgets (); } + private void on_selection_changed () { + var selected_text = text_view.get_selected_text (); + if (selected_text != search_entry.text) { + search_entry.text = ""; + } + } + private void on_replace_entry_activate () { if (text_buffer == null) { warning ("No valid buffer to replace"); diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index ef67e56d1..bb8bab160 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -35,6 +35,7 @@ namespace Scratch.Widgets { private uint size_allocate_timer = 0; private Gtk.TextIter last_select_start_iter; private Gtk.TextIter last_select_end_iter; + private string selected_text = ""; private SourceGutterRenderer git_diff_gutter_renderer; private const uint THROTTLE_MS = 400; @@ -42,6 +43,7 @@ namespace Scratch.Widgets { private const double SCROLL_THRESHOLD = 1.0; public signal void style_changed (Gtk.SourceStyleScheme style); + // "selection_changed" signal now only emitted when the selected text changes (position ignored). Listened to by searchbar and highlight word selection plugin public signal void selection_changed (Gtk.TextIter start_iter, Gtk.TextIter end_iter); public signal void deselected (); @@ -570,7 +572,6 @@ namespace Scratch.Widgets { last_select_start_iter.assign (start); last_select_end_iter.assign (end); - update_draw_spaces (); if (selection_changed_timer != 0) { @@ -592,7 +593,11 @@ namespace Scratch.Widgets { Gtk.TextIter start, end; bool selected = buffer.get_selection_bounds (out start, out end); if (selected) { - selection_changed (start, end); + var prev_selected_text = selected_text; + selected_text = buffer.get_text (start, end, true); + if (selected_text != prev_selected_text) { + selection_changed (start, end); + } } else { deselected (); }