From 208bba423ec6996db79e789c6b44e14c10c0e371 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Wed, 22 Nov 2023 00:31:33 +0000 Subject: [PATCH 01/15] Add option entry for command line go-to option --- src/Application.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Application.vala b/src/Application.vala index 2c02f652e..b7cc10829 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -32,11 +32,13 @@ namespace Scratch { private static string _data_home_folder_unsaved; private static bool create_new_tab = false; private static bool create_new_window = false; + private static string? go_to_range = null; const OptionEntry[] ENTRIES = { { "new-tab", 't', 0, OptionArg.NONE, null, N_("New Tab"), null }, { "new-window", 'n', 0, OptionArg.NONE, null, N_("New Window"), null }, { "version", 'v', 0, OptionArg.NONE, null, N_("Print version info and exit"), null }, + { "go-to", 'g', 0, OptionArg.STRING, ref go_to_range, "Open file at specified selection range", "" }, { GLib.OPTION_REMAINING, 0, 0, OptionArg.FILENAME_ARRAY, null, null, N_("[FILE…]") }, { null } }; From 50512caf9142c9aea215b76184cda3965509ba5d Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Wed, 22 Nov 2023 13:11:51 +0000 Subject: [PATCH 02/15] Parse go-to range from command line argument using syntax from #415 --- src/Application.vala | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index b7cc10829..43d030f72 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -26,19 +26,26 @@ namespace Scratch { public GLib.Settings service_settings; public GLib.Settings privacy_settings; + struct GoToRange { + public int start_line; + public int end_line; + public int start_column; + public int end_column; + } + public class Application : Gtk.Application { public string data_home_folder_unsaved { get { return _data_home_folder_unsaved; } } public string default_font { get; set; } private static string _data_home_folder_unsaved; private static bool create_new_tab = false; private static bool create_new_window = false; - private static string? go_to_range = null; + private static string? go_to_range_string = null; const OptionEntry[] ENTRIES = { { "new-tab", 't', 0, OptionArg.NONE, null, N_("New Tab"), null }, { "new-window", 'n', 0, OptionArg.NONE, null, N_("New Window"), null }, { "version", 'v', 0, OptionArg.NONE, null, N_("Print version info and exit"), null }, - { "go-to", 'g', 0, OptionArg.STRING, ref go_to_range, "Open file at specified selection range", "" }, + { "go-to", 'g', 0, OptionArg.STRING, ref go_to_range_string, "Open file at specified selection range", "" }, { GLib.OPTION_REMAINING, 0, 0, OptionArg.FILENAME_ARRAY, null, null, N_("[FILE…]") }, { null } }; @@ -105,6 +112,19 @@ namespace Scratch { create_new_window = true; } + if (go_to_range_string != null) { + + Regex go_to_line_regex = /^(?[0-9]+)+(?:.(?[0-9]+)+)?(?:-(?:(?[0-9]+)+(?:.(?[0-9]+)+)?))?$/; + MatchInfo match_info; + if (go_to_line_regex.match (go_to_range_string, 0, out match_info)) { + GoToRange go_to_range = parse_go_to_range_from_match_info (match_info); + debug ("Goto - start_line: %d", go_to_range.start_line); + debug ("Goto - start_column: %d", go_to_range.start_column); + debug ("Goto - end_line: %d", go_to_range.end_line); + debug ("Goto - end_column: %d", go_to_range.end_column); + } + } + activate (); if (options.contains (GLib.OPTION_REMAINING)) { @@ -167,5 +187,25 @@ namespace Scratch { public static int main (string[] args) { return new Application ().run (args); } + + private GoToRange parse_go_to_range_from_match_info (GLib.MatchInfo match_info) { + return GoToRange () { + start_line = parse_num_from_match_info (match_info, "start_line"), + end_line = parse_num_from_match_info (match_info, "end_line"), + start_column = parse_num_from_match_info (match_info, "start_column"), + end_column = parse_num_from_match_info (match_info, "end_column"), + }; + } + + private int parse_num_from_match_info (MatchInfo match_info, string match_name) { + string str = match_info.fetch_named (match_name); + int num; + + if (int.try_parse (str, out num)) { + return num; + } + + return -1; + } } } From 573f570c3285de585325fd9d1970383360418065 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Thu, 23 Nov 2023 22:57:06 +0000 Subject: [PATCH 03/15] Files can now be opened at a selected range As long as they haven't already opened/restored --- src/Application.vala | 54 +++++++++++++++++++-------------- src/MainWindow.vala | 6 ++++ src/Structs/SelectionRange.vala | 8 +++++ src/Widgets/DocumentView.vala | 39 ++++++++++++++++++++++++ src/Widgets/SourceView.vala | 28 +++++++++++++++++ src/meson.build | 1 + 6 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 src/Structs/SelectionRange.vala diff --git a/src/Application.vala b/src/Application.vala index 43d030f72..bcae364a2 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -26,26 +26,20 @@ namespace Scratch { public GLib.Settings service_settings; public GLib.Settings privacy_settings; - struct GoToRange { - public int start_line; - public int end_line; - public int start_column; - public int end_column; - } - public class Application : Gtk.Application { public string data_home_folder_unsaved { get { return _data_home_folder_unsaved; } } public string default_font { get; set; } private static string _data_home_folder_unsaved; private static bool create_new_tab = false; private static bool create_new_window = false; - private static string? go_to_range_string = null; + private static string? selection_range_string = null; + private static SelectionRange selection_range = SelectionRange.empty; const OptionEntry[] ENTRIES = { { "new-tab", 't', 0, OptionArg.NONE, null, N_("New Tab"), null }, { "new-window", 'n', 0, OptionArg.NONE, null, N_("New Window"), null }, { "version", 'v', 0, OptionArg.NONE, null, N_("Print version info and exit"), null }, - { "go-to", 'g', 0, OptionArg.STRING, ref go_to_range_string, "Open file at specified selection range", "" }, + { "go-to", 'g', 0, OptionArg.STRING, null, "Open file at specified selection range", "" }, { GLib.OPTION_REMAINING, 0, 0, OptionArg.FILENAME_ARRAY, null, null, N_("[FILE…]") }, { null } }; @@ -112,16 +106,24 @@ namespace Scratch { create_new_window = true; } - if (go_to_range_string != null) { - - Regex go_to_line_regex = /^(?[0-9]+)+(?:.(?[0-9]+)+)?(?:-(?:(?[0-9]+)+(?:.(?[0-9]+)+)?))?$/; + if (options.contains ("go-to")) { + var go_to_string_variant = options.lookup_value ("go-to", GLib.VariantType.STRING); + selection_range_string = (string) go_to_string_variant.get_string (); + } else { + selection_range_string = null; + } + + debug ("Go to string %s:", selection_range_string); + + if (selection_range_string != null) { + Regex go_to_line_regex = /^(?[0-9]+)+(?:\.(?[0-9]+)+)?(?:-(?:(?[0-9]+)+(?:\.(?[0-9]+)+)?))?$/; // vala-lint=space-before-paren, line-length MatchInfo match_info; - if (go_to_line_regex.match (go_to_range_string, 0, out match_info)) { - GoToRange go_to_range = parse_go_to_range_from_match_info (match_info); - debug ("Goto - start_line: %d", go_to_range.start_line); - debug ("Goto - start_column: %d", go_to_range.start_column); - debug ("Goto - end_line: %d", go_to_range.end_line); - debug ("Goto - end_column: %d", go_to_range.end_column); + if (go_to_line_regex.match (selection_range_string, 0, out match_info)) { + selection_range = parse_go_to_range_from_match_info (match_info); + debug ("Selection Range - start_line: %d", selection_range.start_line); + debug ("Selection Range - start_column: %d", selection_range.start_column); + debug ("Selection Range - end_line: %d", selection_range.end_line); + debug ("Selection Range - end_column: %d", selection_range.end_column); } } @@ -165,15 +167,21 @@ namespace Scratch { protected override void open (File[] files, string hint) { var window = get_last_window (); - + debug ("Files length: %d\n", files.length); foreach (var file in files) { bool is_folder; if (Scratch.Services.FileHandler.can_open_file (file, out is_folder)) { if (is_folder) { window.open_folder (file); } else { + debug ("Files length: %d\n", files.length); var doc = new Scratch.Services.Document (window.actions, file); - window.open_document (doc); + if (selection_range_string != null && files.length == 1) { + window.open_document_at_selected_range (doc, true, selection_range); + } else { + window.open_document (doc); + } + } } } @@ -188,8 +196,8 @@ namespace Scratch { return new Application ().run (args); } - private GoToRange parse_go_to_range_from_match_info (GLib.MatchInfo match_info) { - return GoToRange () { + private SelectionRange parse_go_to_range_from_match_info (GLib.MatchInfo match_info) { + return SelectionRange () { start_line = parse_num_from_match_info (match_info, "start_line"), end_line = parse_num_from_match_info (match_info, "end_line"), start_column = parse_num_from_match_info (match_info, "start_column"), @@ -205,7 +213,7 @@ namespace Scratch { return num; } - return -1; + return 0; } } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 42b79f833..c08337c7d 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -686,6 +686,12 @@ namespace Scratch { document_view.open_document (doc, focus, cursor_position); } + public void open_document_at_selected_range (Scratch.Services.Document doc, bool focus = true, SelectionRange range = SelectionRange.empty) { + FolderManager.ProjectFolderItem? project = folder_manager_view.get_project_for_file (doc.file); + doc.source_view.project = project; + document_view.open_document_at_selected_range (doc, focus, range); + } + // Close a document public void close_document (Scratch.Services.Document doc) { document_view.close_document (doc); diff --git a/src/Structs/SelectionRange.vala b/src/Structs/SelectionRange.vala new file mode 100644 index 000000000..f4ab36ee9 --- /dev/null +++ b/src/Structs/SelectionRange.vala @@ -0,0 +1,8 @@ +public struct SelectionRange { + public int start_line; + public int start_column; + public int end_line; + public int end_column; + + public static SelectionRange empty = {0, 0, 0, 0}; +} \ No newline at end of file diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index f76831259..af5fd1e6f 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -252,6 +252,45 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { }); } + public void open_document_at_selected_range (Services.Document doc, bool focus = true, SelectionRange range = SelectionRange.empty) { + for (int n = 0; n <= docs.length (); n++) { + var nth_doc = docs.nth_data (n); + if (nth_doc == null) { + continue; + } + + if (nth_doc.file != null && nth_doc.file.get_uri () == doc.file.get_uri ()) { + if (focus) { + current_document = nth_doc; + } + + debug ("This Document was already opened! Not opening a duplicate!"); + return; + } + } + + insert_document (doc, -1); + if (focus) { + current_document = doc; + } + + Idle.add_full (GLib.Priority.LOW, () => { // This helps ensures new tab is drawn before opening document. + doc.open.begin (false, (obj, res) => { + doc.open.end (res); + if (focus && doc == current_document) { + doc.focus (); + } + + if (range != SelectionRange.empty) { + doc.source_view.select_range (range); + } + save_opened_files (); + }); + + return false; + }); + } + // Set a copy of content public void duplicate_document (Services.Document original) { try { diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index bb8bab160..1e484333a 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -476,6 +476,34 @@ namespace Scratch.Widgets { buffer.end_user_action (); } + public void select_range (SelectionRange range) { + if (range.start_line < 0) { + return; + } + Gtk.TextIter start_iter; + buffer.get_start_iter (out start_iter); + start_iter.set_line (range.start_line - 1); + + if (range.start_column > 0) { + start_iter.set_visible_line_offset (range.start_column - 1); + } + + Gtk.TextIter end_iter = start_iter.copy (); + if (range.end_line > 0) { + end_iter.set_line (range.end_line - 1); + + if (range.end_column > 0) { + end_iter.set_visible_line_offset (range.end_column - 1); + } + } + + buffer.select_range (start_iter, end_iter); + Idle.add (() => { + scroll_to_iter (end_iter, 0.25, false, 0, 0); + return Source.REMOVE; + }); + } + public void set_text (string text, bool opening = true) { var source_buffer = (Gtk.SourceBuffer) buffer; if (opening) { diff --git a/src/meson.build b/src/meson.build index ff454644d..49a5da66d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -57,6 +57,7 @@ code_files = files( 'SymbolPane/C/CtagsSymbol.vala', 'SymbolPane/C/CtagsSymbolIter.vala', 'SymbolPane/C/CtagsSymbolOutline.vala', + 'Structs/SelectionRange.vala' ) From 5244d63d2e0c8400e80e2de83804a969cece0e29 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Fri, 24 Nov 2023 14:03:29 +0000 Subject: [PATCH 04/15] Able to open new file at selected range while app is running --- src/Widgets/DocumentView.vala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index af5fd1e6f..ce8b0ee7a 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -265,6 +265,13 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { } debug ("This Document was already opened! Not opening a duplicate!"); + if (range != SelectionRange.empty) { + Idle.add_full (GLib.Priority.LOW, () => { // This helps ensures new tab is drawn before opening document. + doc.source_view.select_range (range); + return false; + }); + } + return; } } From 9d58f200bac85241aedb1f2cc65643b7e5fca87e Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Fri, 24 Nov 2023 18:01:49 +0000 Subject: [PATCH 05/15] go-to arg overrides document restore behviour --- src/Application.vala | 59 +++++++++++++++++++++++++++++-- src/MainWindow.vala | 29 +++++++++++++-- src/Services/RestoreOverride.vala | 11 ++++++ src/Widgets/DocumentView.vala | 2 ++ src/meson.build | 2 +- 5 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/Services/RestoreOverride.vala diff --git a/src/Application.vala b/src/Application.vala index bcae364a2..c64bf9a46 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -32,8 +32,9 @@ namespace Scratch { private static string _data_home_folder_unsaved; private static bool create_new_tab = false; private static bool create_new_window = false; - private static string? selection_range_string = null; + private static string selection_range_string = null; private static SelectionRange selection_range = SelectionRange.empty; + private static GLib.File selection_range_file; const OptionEntry[] ENTRIES = { { "new-tab", 't', 0, OptionArg.NONE, null, N_("New Tab"), null }, @@ -115,16 +116,33 @@ namespace Scratch { debug ("Go to string %s:", selection_range_string); + bool matched_selection_range = false; if (selection_range_string != null) { Regex go_to_line_regex = /^(?[0-9]+)+(?:\.(?[0-9]+)+)?(?:-(?:(?[0-9]+)+(?:\.(?[0-9]+)+)?))?$/; // vala-lint=space-before-paren, line-length MatchInfo match_info; - if (go_to_line_regex.match (selection_range_string, 0, out match_info)) { + matched_selection_range = go_to_line_regex.match (selection_range_string, 0, out match_info); + if (matched_selection_range) { selection_range = parse_go_to_range_from_match_info (match_info); debug ("Selection Range - start_line: %d", selection_range.start_line); debug ("Selection Range - start_column: %d", selection_range.start_column); debug ("Selection Range - end_line: %d", selection_range.end_line); debug ("Selection Range - end_column: %d", selection_range.end_column); } + } else { + selection_range = SelectionRange.empty; + } + + if (matched_selection_range && options.contains (GLib.OPTION_REMAINING)) { + (unowned string)[] file_list = options.lookup_value ( + GLib.OPTION_REMAINING, + VariantType.BYTESTRING_ARRAY + ).get_bytestring_array (); + + if (file_list.length == 1) { + unowned string selection_range_file_path = file_list[0]; + // selection_range_file = command_line.create_file_for_arg (selection_range_file_path); + selection_range_file = command_line.create_file_for_arg (selection_range_file_path); + } } activate (); @@ -145,12 +163,19 @@ namespace Scratch { open (files, ""); } + + return Posix.EXIT_SUCCESS; } protected override void activate () { if (active_window == null) { - add_window (new MainWindow (true)); // Will restore documents if required + bool will_override_restore = is_file_to_restore (selection_range_file); + if (selection_range != SelectionRange.empty && selection_range_file != null && will_override_restore) { + add_window (new MainWindow.with_restore_override (true, new RestoreOverride (selection_range_file, selection_range))); + } else { + add_window (new MainWindow (true)); // Will restore documents if required + } } else if (create_new_window) { create_new_window = false; add_window (new MainWindow (false)); // Will NOT restore documents in additional windows @@ -215,5 +240,33 @@ namespace Scratch { return 0; } + + private bool is_file_to_restore (File file_to_check) { + bool will_restore = false; + if (privacy_settings.get_boolean ("remember-recent-files")) { + var doc_infos = settings.get_value ("opened-files"); + var doc_info_iter = new VariantIter (doc_infos); + + string uri; + int pos; + while (doc_info_iter.next ("(si)", out uri, out pos)) { + if (uri != "") { + GLib.File file; + if (Uri.parse_scheme (uri) != null) { + file = File.new_for_uri (uri); + } else { + file = File.new_for_commandline_arg (uri); + } + + if (file.query_exists () && file.get_path () == file_to_check.get_path ()) { + will_restore = true; + return will_restore; + } + } + } + } + + return will_restore; + } } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index c08337c7d..b6ae398a9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -26,6 +26,7 @@ namespace Scratch { public Scratch.Application app { get; private set; } public bool restore_docs { get; construct; } + public RestoreOverride restore_override { get; construct set; } public Scratch.Widgets.DocumentView document_view; @@ -158,6 +159,14 @@ namespace Scratch { ); } + public MainWindow.with_restore_override (bool restore_docs, RestoreOverride restore_override) { + Object ( + icon_name: Constants.PROJECT_NAME, + restore_docs: restore_docs, + restore_override: restore_override + ); + } + static construct { action_accelerators.set (ACTION_FIND + "::", "f"); action_accelerators.set (ACTION_FIND_NEXT, "g"); @@ -594,6 +603,7 @@ namespace Scratch { string focused_document = settings.get_string ("focused-document"); string uri; int pos; + bool restore_overriden = false; while (doc_info_iter.next ("(si)", out uri, out pos)) { if (uri != "") { GLib.File file; @@ -610,7 +620,12 @@ namespace Scratch { var doc = new Scratch.Services.Document (actions, file); bool is_focused = file.get_uri () == focused_document; if (doc.exists () || !doc.is_file_temporary) { - open_document (doc, is_focused, pos); + if (restore_override != null && (file.get_path () == restore_override.file.get_path ())) { + open_document_at_selected_range (doc, true, restore_override.range, true); + restore_overriden = true; + } else { + open_document (doc, restore_overriden ? false : is_focused, pos); + } } if (is_focused) { //Maybe expand to show all opened documents? @@ -623,6 +638,7 @@ namespace Scratch { Idle.add (() => { document_view.request_placeholder_if_empty (); + restore_override = null; return Source.REMOVE; }); } @@ -686,7 +702,16 @@ namespace Scratch { document_view.open_document (doc, focus, cursor_position); } - public void open_document_at_selected_range (Scratch.Services.Document doc, bool focus = true, SelectionRange range = SelectionRange.empty) { + public void open_document_at_selected_range ( + Scratch.Services.Document doc, + bool focus = true, + SelectionRange range = SelectionRange.empty, + bool is_override = false) + { + if (restore_override != null && is_override == false) { + return; + } + FolderManager.ProjectFolderItem? project = folder_manager_view.get_project_for_file (doc.file); doc.source_view.project = project; document_view.open_document_at_selected_range (doc, focus, range); diff --git a/src/Services/RestoreOverride.vala b/src/Services/RestoreOverride.vala new file mode 100644 index 000000000..250579095 --- /dev/null +++ b/src/Services/RestoreOverride.vala @@ -0,0 +1,11 @@ +public class RestoreOverride : GLib.Object { + public GLib.File file { get; construct; } + public SelectionRange range { get; construct; } + + public RestoreOverride (GLib.File file, SelectionRange range) { + Object ( + file: file, + range: range + ); + } +} \ No newline at end of file diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index ce8b0ee7a..693361ea0 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -268,6 +268,8 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { if (range != SelectionRange.empty) { Idle.add_full (GLib.Priority.LOW, () => { // This helps ensures new tab is drawn before opening document. doc.source_view.select_range (range); + save_opened_files (); + return false; }); } diff --git a/src/meson.build b/src/meson.build index 49a5da66d..7c9c076e5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -36,6 +36,7 @@ code_files = files( 'Services/GitManager.vala', 'Services/MonitoredRepository.vala', 'Services/PluginManager.vala', + 'Services/RestoreOverride.vala', 'Services/Settings.vala', 'Services/TemplateManager.vala', 'Widgets/ChooseProjectButton.vala', @@ -58,7 +59,6 @@ code_files = files( 'SymbolPane/C/CtagsSymbolIter.vala', 'SymbolPane/C/CtagsSymbolOutline.vala', 'Structs/SelectionRange.vala' - ) executable( From 2771da3e1134591657d1ea0d4094aa81136a70b7 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Fri, 24 Nov 2023 19:26:43 +0000 Subject: [PATCH 06/15] Go to args also update seleccted range of files already opened --- src/Application.vala | 7 ++++--- src/Widgets/DocumentView.vala | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index c64bf9a46..0dae7692f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -170,8 +170,10 @@ namespace Scratch { protected override void activate () { if (active_window == null) { - bool will_override_restore = is_file_to_restore (selection_range_file); - if (selection_range != SelectionRange.empty && selection_range_file != null && will_override_restore) { + if (selection_range != SelectionRange.empty + && selection_range_file != null + && is_file_to_restore (selection_range_file)) + { add_window (new MainWindow.with_restore_override (true, new RestoreOverride (selection_range_file, selection_range))); } else { add_window (new MainWindow (true)); // Will restore documents if required @@ -192,7 +194,6 @@ namespace Scratch { protected override void open (File[] files, string hint) { var window = get_last_window (); - debug ("Files length: %d\n", files.length); foreach (var file in files) { bool is_folder; if (Scratch.Services.FileHandler.can_open_file (file, out is_folder)) { diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index 693361ea0..2ea5fba00 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -267,7 +267,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { debug ("This Document was already opened! Not opening a duplicate!"); if (range != SelectionRange.empty) { Idle.add_full (GLib.Priority.LOW, () => { // This helps ensures new tab is drawn before opening document. - doc.source_view.select_range (range); + current_document.source_view.select_range (range); save_opened_files (); return false; From 62d5aa46b02ca652d47e5cf45708924dced5d356 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Fri, 24 Nov 2023 22:40:31 +0000 Subject: [PATCH 07/15] Encapsulate go-to option arg handling into LocationJumpManager Fixes #415 --- src/Application.vala | 98 ++++----------------------- src/MainWindow.vala | 6 +- src/Services/LocationJumpManager.vala | 86 +++++++++++++++++++++++ src/meson.build | 1 + 4 files changed, 104 insertions(+), 87 deletions(-) create mode 100644 src/Services/LocationJumpManager.vala diff --git a/src/Application.vala b/src/Application.vala index 0dae7692f..e27adf443 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -32,9 +32,7 @@ namespace Scratch { private static string _data_home_folder_unsaved; private static bool create_new_tab = false; private static bool create_new_window = false; - private static string selection_range_string = null; - private static SelectionRange selection_range = SelectionRange.empty; - private static GLib.File selection_range_file; + private LocationJumpManager location_jump_manager; const OptionEntry[] ENTRIES = { { "new-tab", 't', 0, OptionArg.NONE, null, N_("New Tab"), null }, @@ -50,6 +48,7 @@ namespace Scratch { _data_home_folder_unsaved = Path.build_filename ( Environment.get_user_data_dir (), Constants.PROJECT_NAME, "unsaved" ); + } construct { @@ -70,6 +69,7 @@ namespace Scratch { service_settings = new GLib.Settings (Constants.PROJECT_NAME + ".services"); privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy"); + location_jump_manager = new LocationJumpManager (); Environment.set_variable ("GTK_USE_PORTAL", "1", true); GLib.Intl.setlocale (LocaleCategory.ALL, ""); @@ -98,6 +98,7 @@ namespace Scratch { }; var options = command_line.get_options_dict (); + location_jump_manager.clear (); if (options.contains ("new-tab")) { create_new_tab = true; @@ -109,30 +110,12 @@ namespace Scratch { if (options.contains ("go-to")) { var go_to_string_variant = options.lookup_value ("go-to", GLib.VariantType.STRING); - selection_range_string = (string) go_to_string_variant.get_string (); - } else { - selection_range_string = null; - } - - debug ("Go to string %s:", selection_range_string); - - bool matched_selection_range = false; - if (selection_range_string != null) { - Regex go_to_line_regex = /^(?[0-9]+)+(?:\.(?[0-9]+)+)?(?:-(?:(?[0-9]+)+(?:\.(?[0-9]+)+)?))?$/; // vala-lint=space-before-paren, line-length - MatchInfo match_info; - matched_selection_range = go_to_line_regex.match (selection_range_string, 0, out match_info); - if (matched_selection_range) { - selection_range = parse_go_to_range_from_match_info (match_info); - debug ("Selection Range - start_line: %d", selection_range.start_line); - debug ("Selection Range - start_column: %d", selection_range.start_column); - debug ("Selection Range - end_line: %d", selection_range.end_line); - debug ("Selection Range - end_column: %d", selection_range.end_column); - } - } else { - selection_range = SelectionRange.empty; + string selection_range_string = (string) go_to_string_variant.get_string (); + location_jump_manager.parse_selection_range_string (selection_range_string); + debug ("go-to arg value: %s", selection_range_string); } - if (matched_selection_range && options.contains (GLib.OPTION_REMAINING)) { + if (location_jump_manager.has_selection_range () && options.contains (GLib.OPTION_REMAINING)) { (unowned string)[] file_list = options.lookup_value ( GLib.OPTION_REMAINING, VariantType.BYTESTRING_ARRAY @@ -140,8 +123,7 @@ namespace Scratch { if (file_list.length == 1) { unowned string selection_range_file_path = file_list[0]; - // selection_range_file = command_line.create_file_for_arg (selection_range_file_path); - selection_range_file = command_line.create_file_for_arg (selection_range_file_path); + location_jump_manager.file = command_line.create_file_for_arg (selection_range_file_path); } } @@ -163,18 +145,14 @@ namespace Scratch { open (files, ""); } - - return Posix.EXIT_SUCCESS; } protected override void activate () { if (active_window == null) { - if (selection_range != SelectionRange.empty - && selection_range_file != null - && is_file_to_restore (selection_range_file)) - { - add_window (new MainWindow.with_restore_override (true, new RestoreOverride (selection_range_file, selection_range))); + if (location_jump_manager.has_selection_range () && location_jump_manager.has_override_target ()) { + RestoreOverride restore_override = location_jump_manager.create_restore_override (); + add_window (new MainWindow.with_restore_override (true, restore_override)); } else { add_window (new MainWindow (true)); // Will restore documents if required } @@ -202,8 +180,8 @@ namespace Scratch { } else { debug ("Files length: %d\n", files.length); var doc = new Scratch.Services.Document (window.actions, file); - if (selection_range_string != null && files.length == 1) { - window.open_document_at_selected_range (doc, true, selection_range); + if (location_jump_manager.has_selection_range != null && files.length == 1) { + window.open_document_at_selected_range (doc, true, location_jump_manager.range); } else { window.open_document (doc); } @@ -221,53 +199,5 @@ namespace Scratch { public static int main (string[] args) { return new Application ().run (args); } - - private SelectionRange parse_go_to_range_from_match_info (GLib.MatchInfo match_info) { - return SelectionRange () { - start_line = parse_num_from_match_info (match_info, "start_line"), - end_line = parse_num_from_match_info (match_info, "end_line"), - start_column = parse_num_from_match_info (match_info, "start_column"), - end_column = parse_num_from_match_info (match_info, "end_column"), - }; - } - - private int parse_num_from_match_info (MatchInfo match_info, string match_name) { - string str = match_info.fetch_named (match_name); - int num; - - if (int.try_parse (str, out num)) { - return num; - } - - return 0; - } - - private bool is_file_to_restore (File file_to_check) { - bool will_restore = false; - if (privacy_settings.get_boolean ("remember-recent-files")) { - var doc_infos = settings.get_value ("opened-files"); - var doc_info_iter = new VariantIter (doc_infos); - - string uri; - int pos; - while (doc_info_iter.next ("(si)", out uri, out pos)) { - if (uri != "") { - GLib.File file; - if (Uri.parse_scheme (uri) != null) { - file = File.new_for_uri (uri); - } else { - file = File.new_for_commandline_arg (uri); - } - - if (file.query_exists () && file.get_path () == file_to_check.get_path ()) { - will_restore = true; - return will_restore; - } - } - } - } - - return will_restore; - } } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index b6ae398a9..e76acf2be 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -603,7 +603,7 @@ namespace Scratch { string focused_document = settings.get_string ("focused-document"); string uri; int pos; - bool restore_overriden = false; + bool was_restore_overriden = false; while (doc_info_iter.next ("(si)", out uri, out pos)) { if (uri != "") { GLib.File file; @@ -622,9 +622,9 @@ namespace Scratch { if (doc.exists () || !doc.is_file_temporary) { if (restore_override != null && (file.get_path () == restore_override.file.get_path ())) { open_document_at_selected_range (doc, true, restore_override.range, true); - restore_overriden = true; + was_restore_overriden = true; } else { - open_document (doc, restore_overriden ? false : is_focused, pos); + open_document (doc, was_restore_overriden ? false : is_focused, pos); } } diff --git a/src/Services/LocationJumpManager.vala b/src/Services/LocationJumpManager.vala new file mode 100644 index 000000000..085b6e4b4 --- /dev/null +++ b/src/Services/LocationJumpManager.vala @@ -0,0 +1,86 @@ +namespace Scratch { + public class LocationJumpManager : GLib.Object { + public GLib.File file { get; set; } + public SelectionRange range { get; set; } + + public bool has_override_target () { + if (file == null) { + return false; + } + + bool is_override_target = false; + + if (privacy_settings.get_boolean ("remember-recent-files")) { + var doc_infos = settings.get_value ("opened-files"); + var doc_info_iter = new VariantIter (doc_infos); + + string uri; + int pos; + while (doc_info_iter.next ("(si)", out uri, out pos)) { + if (uri != "") { + GLib.File file_to_restore; + if (Uri.parse_scheme (uri) != null) { + file_to_restore = File.new_for_uri (uri); + } else { + file_to_restore = File.new_for_commandline_arg (uri); + } + + if (file_to_restore.query_exists () && file_to_restore.get_path () == file.get_path ()) { + is_override_target = true; + break; + } + } + } + } + + return is_override_target; + } + + public RestoreOverride create_restore_override () { + return new RestoreOverride (file, range); + } + + public void clear () { + range = SelectionRange.empty; + file = null; + } + + public bool has_selection_range () { + return range != SelectionRange.empty; + } + + public bool parse_selection_range_string (string selection_range_string) { + Regex go_to_line_regex = /^(?[0-9]+)+(?:\.(?[0-9]+)+)?(?:-(?:(?[0-9]+)+(?:\.(?[0-9]+)+)?))?$/; // vala-lint=space-before-paren, line-length + MatchInfo match_info; + if (go_to_line_regex.match (selection_range_string, 0, out match_info)) { + range = parse_go_to_range_from_match_info (match_info); + debug ("Selection Range - start_line: %d", range.start_line); + debug ("Selection Range - start_column: %d", range.start_column); + debug ("Selection Range - end_line: %d", range.end_line); + debug ("Selection Range - end_column: %d", range.end_column); + } + + return true; + } + + private static SelectionRange parse_go_to_range_from_match_info (GLib.MatchInfo match_info) { + return SelectionRange () { + start_line = parse_num_from_match_info (match_info, "start_line"), + end_line = parse_num_from_match_info (match_info, "end_line"), + start_column = parse_num_from_match_info (match_info, "start_column"), + end_column = parse_num_from_match_info (match_info, "end_column"), + }; + } + + private static int parse_num_from_match_info (MatchInfo match_info, string match_name) { + string str = match_info.fetch_named (match_name); + int num; + + if (int.try_parse (str, out num)) { + return num; + } + + return 0; + } + } +} diff --git a/src/meson.build b/src/meson.build index 7c9c076e5..bdafbfe28 100644 --- a/src/meson.build +++ b/src/meson.build @@ -34,6 +34,7 @@ code_files = files( 'Services/DocumentManager.vala', 'Services/FileHandler.vala', 'Services/GitManager.vala', + 'Services/LocationJumpManager.vala', 'Services/MonitoredRepository.vala', 'Services/PluginManager.vala', 'Services/RestoreOverride.vala', From d204e92065b607d34821d9acf096ac42ac635812 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Fri, 24 Nov 2023 23:32:43 +0000 Subject: [PATCH 08/15] Change SelectionRange.EMPTY into a public const value --- src/MainWindow.vala | 2 +- src/Services/LocationJumpManager.vala | 4 ++-- src/Structs/SelectionRange.vala | 2 +- src/Widgets/DocumentView.vala | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e76acf2be..7f33c06f2 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -705,7 +705,7 @@ namespace Scratch { public void open_document_at_selected_range ( Scratch.Services.Document doc, bool focus = true, - SelectionRange range = SelectionRange.empty, + SelectionRange range = SelectionRange.EMPTY, bool is_override = false) { if (restore_override != null && is_override == false) { diff --git a/src/Services/LocationJumpManager.vala b/src/Services/LocationJumpManager.vala index 085b6e4b4..a3ae70226 100644 --- a/src/Services/LocationJumpManager.vala +++ b/src/Services/LocationJumpManager.vala @@ -41,12 +41,12 @@ namespace Scratch { } public void clear () { - range = SelectionRange.empty; + range = SelectionRange.EMPTY; file = null; } public bool has_selection_range () { - return range != SelectionRange.empty; + return range != SelectionRange.EMPTY; } public bool parse_selection_range_string (string selection_range_string) { diff --git a/src/Structs/SelectionRange.vala b/src/Structs/SelectionRange.vala index f4ab36ee9..16183b1ad 100644 --- a/src/Structs/SelectionRange.vala +++ b/src/Structs/SelectionRange.vala @@ -4,5 +4,5 @@ public struct SelectionRange { public int end_line; public int end_column; - public static SelectionRange empty = {0, 0, 0, 0}; + public const SelectionRange EMPTY = {0, 0, 0, 0}; } \ No newline at end of file diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index 2ea5fba00..99c23d0c1 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -252,7 +252,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { }); } - public void open_document_at_selected_range (Services.Document doc, bool focus = true, SelectionRange range = SelectionRange.empty) { + public void open_document_at_selected_range (Services.Document doc, bool focus = true, SelectionRange range = SelectionRange.EMPTY) { for (int n = 0; n <= docs.length (); n++) { var nth_doc = docs.nth_data (n); if (nth_doc == null) { @@ -265,7 +265,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { } debug ("This Document was already opened! Not opening a duplicate!"); - if (range != SelectionRange.empty) { + if (range != SelectionRange.EMPTY) { Idle.add_full (GLib.Priority.LOW, () => { // This helps ensures new tab is drawn before opening document. current_document.source_view.select_range (range); save_opened_files (); @@ -290,7 +290,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { doc.focus (); } - if (range != SelectionRange.empty) { + if (range != SelectionRange.EMPTY) { doc.source_view.select_range (range); } save_opened_files (); From f60f177946130b350bfd2686cc617e361c7e121d Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Fri, 24 Nov 2023 23:44:44 +0000 Subject: [PATCH 09/15] Fix lint errors --- src/Application.vala | 2 +- src/MainWindow.vala | 12 +++++------- src/Services/RestoreOverride.vala | 2 +- src/Structs/SelectionRange.vala | 2 +- src/Widgets/SourceView.vala | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index e27adf443..ada5c69a0 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -109,7 +109,7 @@ namespace Scratch { } if (options.contains ("go-to")) { - var go_to_string_variant = options.lookup_value ("go-to", GLib.VariantType.STRING); + var go_to_string_variant = options.lookup_value ("go-to", GLib.VariantType.STRING); string selection_range_string = (string) go_to_string_variant.get_string (); location_jump_manager.parse_selection_range_string (selection_range_string); debug ("go-to arg value: %s", selection_range_string); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 7f33c06f2..f3469ffab 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -603,7 +603,7 @@ namespace Scratch { string focused_document = settings.get_string ("focused-document"); string uri; int pos; - bool was_restore_overriden = false; + bool was_restore_overriden = false; while (doc_info_iter.next ("(si)", out uri, out pos)) { if (uri != "") { GLib.File file; @@ -702,12 +702,10 @@ namespace Scratch { document_view.open_document (doc, focus, cursor_position); } - public void open_document_at_selected_range ( - Scratch.Services.Document doc, - bool focus = true, - SelectionRange range = SelectionRange.EMPTY, - bool is_override = false) - { + public void open_document_at_selected_range (Scratch.Services.Document doc, + bool focus = true, + SelectionRange range = SelectionRange.EMPTY, + bool is_override = false) { if (restore_override != null && is_override == false) { return; } diff --git a/src/Services/RestoreOverride.vala b/src/Services/RestoreOverride.vala index 250579095..850743d34 100644 --- a/src/Services/RestoreOverride.vala +++ b/src/Services/RestoreOverride.vala @@ -8,4 +8,4 @@ public class RestoreOverride : GLib.Object { range: range ); } -} \ No newline at end of file +} diff --git a/src/Structs/SelectionRange.vala b/src/Structs/SelectionRange.vala index 16183b1ad..b2a69d7a0 100644 --- a/src/Structs/SelectionRange.vala +++ b/src/Structs/SelectionRange.vala @@ -5,4 +5,4 @@ public struct SelectionRange { public int end_column; public const SelectionRange EMPTY = {0, 0, 0, 0}; -} \ No newline at end of file +} diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index 1e484333a..179a9e9d9 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -483,7 +483,7 @@ namespace Scratch.Widgets { Gtk.TextIter start_iter; buffer.get_start_iter (out start_iter); start_iter.set_line (range.start_line - 1); - + if (range.start_column > 0) { start_iter.set_visible_line_offset (range.start_column - 1); } From 5e41d98b29de91859cb2a68cdc74d6d622b5d272 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Mon, 27 Nov 2023 18:37:25 +0000 Subject: [PATCH 10/15] Add license headers to new source code files --- src/Services/LocationJumpManager.vala | 8 ++++++++ src/Services/RestoreOverride.vala | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Services/LocationJumpManager.vala b/src/Services/LocationJumpManager.vala index a3ae70226..c3920d3f2 100644 --- a/src/Services/LocationJumpManager.vala +++ b/src/Services/LocationJumpManager.vala @@ -1,3 +1,11 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2023 elementary, Inc. + * SPDX-FileContributor: Colin Kiama + * + * Authored by: Colin Kiama + */ + namespace Scratch { public class LocationJumpManager : GLib.Object { public GLib.File file { get; set; } diff --git a/src/Services/RestoreOverride.vala b/src/Services/RestoreOverride.vala index 850743d34..be719b2db 100644 --- a/src/Services/RestoreOverride.vala +++ b/src/Services/RestoreOverride.vala @@ -1,3 +1,11 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2023 elementary, Inc. + * SPDX-FileContributor: Colin Kiama + * + * Authored by: Colin Kiama + */ + public class RestoreOverride : GLib.Object { public GLib.File file { get; construct; } public SelectionRange range { get; construct; } From 7a01b75b860a4efd71bc47a40251fe4f46a1cc68 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Mon, 27 Nov 2023 18:41:02 +0000 Subject: [PATCH 11/15] Add null checks when parsing integers from selection range string --- src/Services/LocationJumpManager.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/LocationJumpManager.vala b/src/Services/LocationJumpManager.vala index c3920d3f2..8a9fc03cc 100644 --- a/src/Services/LocationJumpManager.vala +++ b/src/Services/LocationJumpManager.vala @@ -81,14 +81,14 @@ namespace Scratch { } private static int parse_num_from_match_info (MatchInfo match_info, string match_name) { - string str = match_info.fetch_named (match_name); - int num; + var str = match_info.fetch_named (match_name); + int num = 0; - if (int.try_parse (str, out num)) { + if (str != null && int.try_parse (str, out num)) { return num; } - return 0; + return num; } } } From da987784b0cedc93371a2df2c8c1841a4e773265 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Mon, 27 Nov 2023 18:56:57 +0000 Subject: [PATCH 12/15] Merge DocumentView.open_document methods into one method --- src/MainWindow.vala | 2 +- src/Widgets/DocumentView.vala | 44 ++++------------------------------- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f3469ffab..21ae93280 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -712,7 +712,7 @@ namespace Scratch { FolderManager.ProjectFolderItem? project = folder_manager_view.get_project_for_file (doc.file); doc.source_view.project = project; - document_view.open_document_at_selected_range (doc, focus, range); + document_view.open_document (doc, focus, 0, range); } // Close a document diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index 99c23d0c1..a6e51bc24 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -213,46 +213,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { } } - public void open_document (Services.Document doc, bool focus = true, int cursor_position = 0) { - for (int n = 0; n <= docs.length (); n++) { - var nth_doc = docs.nth_data (n); - if (nth_doc == null) { - continue; - } - - if (nth_doc.file != null && nth_doc.file.get_uri () == doc.file.get_uri ()) { - if (focus) { - current_document = nth_doc; - } - - debug ("This Document was already opened! Not opening a duplicate!"); - return; - } - } - - insert_document (doc, -1); - if (focus) { - current_document = doc; - } - - Idle.add_full (GLib.Priority.LOW, () => { // This helps ensures new tab is drawn before opening document. - doc.open.begin (false, (obj, res) => { - doc.open.end (res); - if (focus && doc == current_document) { - doc.focus (); - } - - if (cursor_position > 0) { - doc.source_view.cursor_position = cursor_position; - } - save_opened_files (); - }); - - return false; - }); - } - - public void open_document_at_selected_range (Services.Document doc, bool focus = true, SelectionRange range = SelectionRange.EMPTY) { + public void open_document (Services.Document doc, bool focus = true, int cursor_position = 0, SelectionRange range = SelectionRange.EMPTY) { for (int n = 0; n <= docs.length (); n++) { var nth_doc = docs.nth_data (n); if (nth_doc == null) { @@ -292,7 +253,10 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook { if (range != SelectionRange.EMPTY) { doc.source_view.select_range (range); + } else if (cursor_position > 0) { + doc.source_view.cursor_position = cursor_position; } + save_opened_files (); }); From 8000461998cb82b247acc0aad470a7f4ec1b52d1 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Mon, 27 Nov 2023 21:30:02 +0000 Subject: [PATCH 13/15] Amend license headers in new source code files --- src/Services/LocationJumpManager.vala | 1 - src/Services/RestoreOverride.vala | 1 - src/Structs/SelectionRange.vala | 7 +++++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Services/LocationJumpManager.vala b/src/Services/LocationJumpManager.vala index 8a9fc03cc..61f74ea2b 100644 --- a/src/Services/LocationJumpManager.vala +++ b/src/Services/LocationJumpManager.vala @@ -1,7 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later * SPDX-FileCopyrightText: 2023 elementary, Inc. - * SPDX-FileContributor: Colin Kiama * * Authored by: Colin Kiama */ diff --git a/src/Services/RestoreOverride.vala b/src/Services/RestoreOverride.vala index be719b2db..cd1f21ad4 100644 --- a/src/Services/RestoreOverride.vala +++ b/src/Services/RestoreOverride.vala @@ -1,7 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later * SPDX-FileCopyrightText: 2023 elementary, Inc. - * SPDX-FileContributor: Colin Kiama * * Authored by: Colin Kiama */ diff --git a/src/Structs/SelectionRange.vala b/src/Structs/SelectionRange.vala index b2a69d7a0..81e33cddd 100644 --- a/src/Structs/SelectionRange.vala +++ b/src/Structs/SelectionRange.vala @@ -1,3 +1,10 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2023 elementary, Inc. + * + * Authored by: Colin Kiama + */ + public struct SelectionRange { public int start_line; public int start_column; From 6af3a76a1fae17ec5a15827103e7029c69a1e73f Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Tue, 28 Nov 2023 14:08:08 +0000 Subject: [PATCH 14/15] Resolve code-style formatting issues --- src/Application.vala | 1 - src/Widgets/SourceView.vala | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index ada5c69a0..8473dd563 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -185,7 +185,6 @@ namespace Scratch { } else { window.open_document (doc); } - } } } diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index 179a9e9d9..5589de04f 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -480,6 +480,7 @@ namespace Scratch.Widgets { if (range.start_line < 0) { return; } + Gtk.TextIter start_iter; buffer.get_start_iter (out start_iter); start_iter.set_line (range.start_line - 1); From 8b7490622cb1ae950d567607fb90d44785a3ad66 Mon Sep 17 00:00:00 2001 From: Colin Kiama Date: Tue, 28 Nov 2023 14:08:57 +0000 Subject: [PATCH 15/15] Avoid unnecesaary function return in LocationJumpManager --- src/Services/LocationJumpManager.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/LocationJumpManager.vala b/src/Services/LocationJumpManager.vala index 61f74ea2b..d4423210f 100644 --- a/src/Services/LocationJumpManager.vala +++ b/src/Services/LocationJumpManager.vala @@ -83,8 +83,8 @@ namespace Scratch { var str = match_info.fetch_named (match_name); int num = 0; - if (str != null && int.try_parse (str, out num)) { - return num; + if (str != null) { + int.try_parse (str, out num); } return num;