Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8a902a9
Increase maximum selection length
Oct 7, 2024
eb3db43
Merge branch 'master' into jeremypw/fix-highlight-selection
zeebok Oct 9, 2024
5ad6921
Add "active-project-path" setting.
Oct 9, 2024
4eb0372
Dont change active project just because a document changes
Oct 9, 2024
67f238c
Remove some unused code relating to active_project
Oct 9, 2024
a3c10fa
Merge branch 'master' into jeremypw/fix-highlight-selection
zeebok Oct 10, 2024
c2f4940
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Oct 13, 2024
c05ab29
Do not override active project with default on startup
Oct 13, 2024
5b4db0e
Show global search dialog if scope unspecified
Oct 13, 2024
ad9cc13
Distinguish global search path from default action target
Oct 14, 2024
916e10d
Allow global search when no active project
Oct 14, 2024
ca34ddd
Set active project after load folder is none already set
Oct 14, 2024
baf705e
FileView: Use git_manager property
Oct 14, 2024
b32acf1
Merge branch 'master' into jeremypw/fix-highlight-selection
zeebok Oct 20, 2024
43a4e4d
Merge branch 'master' into jeremypw/fix-highlight-selection
zeebok Oct 22, 2024
9fb47a0
Merge branch 'master' into jeremypw/fix-highlight-selection
zeebok Oct 22, 2024
b6485f4
Merge branch 'master' into jeremypw/fix-highlight-selection
jeremypw Oct 22, 2024
f742237
Simplify, handle mark-deleted signal
Oct 22, 2024
19cca3d
Update spaces immediately
Oct 22, 2024
5d350e7
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Oct 30, 2024
43c1023
Allow no project to be restored. Only user sets active project.
Oct 30, 2024
0bca777
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Nov 6, 2024
58f45bd
Merge branch 'master' into jeremypw/fix-highlight-selection
jeremypw Nov 28, 2024
0b00d39
Merge branch 'master' into jeremypw/rework-highlight-selection
zeebok Dec 1, 2024
3794a65
Merge branch 'master' into jeremypw/sync-activeproject-startup
zeebok Dec 1, 2024
e49889c
Merge branch 'master' into jeremypw/rework-highlight-selection
jeremypw Dec 2, 2024
9f129cf
Separate throttle for selection change
Dec 2, 2024
24da045
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Dec 7, 2024
f01dfde
On close other folders make remaining active
Dec 7, 2024
48320f3
Set active project context menu item for git repos
Dec 7, 2024
0198f70
Merge branch 'master' into jeremypw/fix-highlight-selection
jeremypw Dec 12, 2024
62a8244
Merge branch 'master' into jeremypw/rework-highlight-selection
jeremypw Jan 8, 2025
2fa14e9
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Jan 8, 2025
1882a3e
Change install and run under different name
Jan 11, 2025
c0d8733
Merge branch 'master' into jeremypw/fix-highlight-selection
jeremypw Jan 11, 2025
6c9afb9
Merge pull request #1 from elementary/jeremypw/fix-highlight-selection
jeremypw Jan 11, 2025
d8e21e4
Merge branch 'master' into jeremypw/sync-activeproject-startup
jeremypw Jan 11, 2025
e46440b
Merge pull request #2 from elementary/jeremypw/sync-activeproject-sta…
jeremypw Jan 11, 2025
bef4a0a
Merge branch 'master' into jeremypw/rework-highlight-selection
jeremypw Jan 11, 2025
2a7161d
Merge branch 'master' into jeremypw/rework-highlight-selection
zeebok Jan 12, 2025
72bb50c
Fix schema paths
Jan 12, 2025
adba6ec
Merge branch 'master' into jeremypw/rework-highlight-selection
jeremypw Jan 12, 2025
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
26 changes: 8 additions & 18 deletions plugins/highlight-word-selection/highlight-word-selection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A
plugins = (Scratch.Services.Interface) object;
plugins.hook_document.connect ((doc) => {
if (current_source != null) {
current_source.deselected.disconnect (on_deselection);
current_source.selection_changed.disconnect (on_selection_changed);
}

current_source = doc.source_view;
current_source.deselected.connect (on_deselection);
current_source.selection_changed.connect (on_selection_changed);
});

Expand All @@ -50,13 +48,13 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A
});
}

public void on_selection_changed (ref Gtk.TextIter start, ref Gtk.TextIter end) {
public void on_selection_changed (string selected_text, ref Gtk.TextIter start, ref Gtk.TextIter end) {
var window_search_context = main_window != null ? main_window.search_bar.search_context : null;

if (window_search_context == null ||
if (selected_text != "" &&
(window_search_context == null ||
window_search_context.settings.search_text == "" ||
window_search_context.get_occurrences_count () == 0) {
// Perform plugin selection when there is no ongoing and successful search
window_search_context.get_occurrences_count () == 0)) {
// Perform plugin selection when there is no ongoing and successful search
current_search_context = new Gtk.SourceSearchContext (
(Gtk.SourceBuffer)current_source.buffer,
null
Expand Down Expand Up @@ -118,13 +116,13 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A
);

// Ensure no leading or trailing space
var selected_text = start.get_text (end).strip ();
var stripped_selected_words = start.get_text (end).strip ();

if (selected_text.char_count () > SELECTION_HIGHLIGHT_MAX_CHARS) {
if (stripped_selected_words.char_count () > SELECTION_HIGHLIGHT_MAX_CHARS) {
return;
}

current_search_context.settings.search_text = selected_text;
current_search_context.settings.search_text = stripped_selected_words;
current_search_context.set_highlight (true);
} else if (current_search_context != null) {
// Cancel existing search
Expand All @@ -133,16 +131,8 @@ public class Scratch.Plugins.HighlightSelectedWords : Peas.ExtensionBase, Peas.A
}
}

public void on_deselection () {
if (current_search_context != null) {
current_search_context.set_highlight (false);
current_search_context = null;
}
}

public void deactivate () {
if (current_source != null) {
current_source.deselected.disconnect (on_deselection);
current_source.selection_changed.disconnect (on_selection_changed);
}
}
Expand Down
66 changes: 26 additions & 40 deletions src/Widgets/SourceView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ namespace Scratch.Widgets {
public FolderManager.ProjectFolderItem project { get; set; default = null; }

private string font;
private uint selection_changed_timer = 0;
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 string prev_selected_text = "";
private SourceGutterRenderer git_diff_gutter_renderer;

private const uint THROTTLE_MS = 400;
Expand All @@ -44,8 +43,7 @@ namespace Scratch.Widgets {

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 ();
public signal void selection_changed (string selected_text, Gtk.TextIter start_iter, Gtk.TextIter end_iter);

//lang can be null, in the case of *No highlight style* aka Normal text
public Gtk.SourceLanguage? language {
Expand Down Expand Up @@ -99,7 +97,9 @@ namespace Scratch.Widgets {
var source_buffer = new Gtk.SourceBuffer (null);
set_buffer (source_buffer);
source_buffer.highlight_syntax = true;
source_buffer.mark_set.connect (on_mark_set);
source_buffer.mark_set.connect (schedule_selection_changed_event);
// Need to handle this signal else not all deselections are detected
source_buffer.mark_deleted.connect (schedule_selection_changed_event);
highlight_current_line = true;

var draw_spaces_tag = new Gtk.SourceTag ("draw_spaces");
Expand Down Expand Up @@ -539,14 +539,12 @@ namespace Scratch.Widgets {
/* Draw spaces in selection the same way if drawn at all */
if (selection &&
draw_spaces_state in (ScratchDrawSpacesState.FOR_SELECTION | ScratchDrawSpacesState.CURRENT | ScratchDrawSpacesState.ALWAYS)) {

buffer.apply_tag_by_name ("draw_spaces", start, end);
return;
}

if (draw_spaces_state == ScratchDrawSpacesState.CURRENT &&
get_current_line (out start, out end)) {

buffer.apply_tag_by_name ("draw_spaces", start, end);
}
}
Expand Down Expand Up @@ -597,49 +595,37 @@ namespace Scratch.Widgets {
return (int) (height_in_px - (LINES_TO_KEEP * px_per_line));
}

void on_mark_set (Gtk.TextIter loc, Gtk.TextMark mar) {
// Weed out user movement for text selection changes
Gtk.TextIter start, end;
buffer.get_selection_bounds (out start, out end);

if (start.equal (last_select_start_iter) && end.equal (last_select_end_iter)) {
return;
}

last_select_start_iter.assign (start);
last_select_end_iter.assign (end);
private bool continue_selection_timer = false;
private uint selection_changed_timer = 0;
private void schedule_selection_changed_event () {
// Update spaces immediately to maintain previous behaviour
update_draw_spaces ();

if (selection_changed_timer != 0) {
Source.remove (selection_changed_timer);
selection_changed_timer = 0;
continue_selection_timer = true;
return;
}

// Fire deselected immediately
if (start.equal (end)) {
deselected ();
// Don't fire signal till we think select movement is done
} else {
selection_changed_timer = Timeout.add (THROTTLE_MS, selection_changed_event);
}
selection_changed_timer = Timeout.add (THROTTLE_MS, () => {
if (continue_selection_timer) {
continue_selection_timer = false;
return Source.CONTINUE;
}

}
selection_changed_timer = 0;
Gtk.TextIter start, end;
var selected_text = "";
if (buffer.get_selection_bounds (out start, out end)) {
selected_text = buffer.get_text (start, end, true);
}

bool selection_changed_event () {
Gtk.TextIter start, end;
bool selected = buffer.get_selection_bounds (out start, out end);
if (selected) {
var prev_selected_text = selected_text;
selected_text = buffer.get_text (start, end, true);
if (selected_text != prev_selected_text) {
selection_changed (start, end);
selection_changed (selected_text, start, end);
}
} else {
deselected ();
}

selection_changed_timer = 0;
return false;
prev_selected_text = selected_text;
return Source.REMOVE;
});
}

uint refresh_diff_timeout_id = 0;
Expand Down