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

Fix searchterm reverts #1336

Merged
merged 12 commits into from
Jul 11, 2023
4 changes: 4 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion src/Widgets/SearchBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace Scratch.Widgets {
MIXED,
ALWAYS
}

public weak MainWindow window { get; construct; }

private Gtk.Button tool_arrow_up;
Expand Down Expand 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);
Expand All @@ -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");
Expand Down
10 changes: 8 additions & 2 deletions src/Widgets/SourceView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ 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;
private double total_delta = 0;
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 ();

Expand Down Expand Up @@ -563,12 +565,12 @@ namespace Scratch.Widgets {
buffer.get_selection_bounds (out start, out end);

if (start.equal (last_select_start_iter) && end.equal (last_select_end_iter)) {
// warning ("selection unchanged");
jeremypw marked this conversation as resolved.
Show resolved Hide resolved
return;
}

last_select_start_iter.assign (start);
last_select_end_iter.assign (end);

update_draw_spaces ();

if (selection_changed_timer != 0) {
Expand All @@ -590,7 +592,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 ();
}
Expand Down