From 26a73fdf071ccd5f3adcb63112e1714e39b70cf6 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 9 Nov 2025 16:34:20 +0000 Subject: [PATCH 1/2] Add setting for highlighting syntax and honor it. --- data/io.elementary.code.gschema.xml | 5 +++++ src/Services/Document.vala | 14 +++++++++++--- src/Widgets/SourceView.vala | 7 ++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index 0f78a64f7..0a8ba0f70 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -207,6 +207,11 @@ Whether to automatically remove trailing whitespace on saving Whether trailing whitespace should be removed from a document whenever it is saved, including on autosave. + + true + Show source language syntax highlighting + Whether the document should display the style scheme for the associated language. + diff --git a/src/Services/Document.vala b/src/Services/Document.vala index ae4bf524f..a5d04b75d 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -238,6 +238,7 @@ namespace Scratch.Services { set_strip_trailing_whitespace (); settings.changed["show-mini-map"].connect (set_minimap); settings.changed["strip-trailing-on-save"].connect (set_strip_trailing_whitespace); + settings.changed["highlight-syntax"].connect (set_syntax_highlighting); var source_grid = new Gtk.Grid () { orientation = Gtk.Orientation.HORIZONTAL, @@ -450,7 +451,7 @@ namespace Scratch.Services { } // Change syntax highlight - this.source_view.change_syntax_highlight_from_file (this.file); + set_syntax_highlighting (); source_view.buffer.set_modified (false); original_content = source_view.buffer.text; @@ -711,7 +712,8 @@ namespace Scratch.Services { } delete_backup (current_file.get_uri () + "~"); - this.source_view.change_syntax_highlight_from_file (this.file); + set_syntax_highlighting (); + } // Calling function responsible for restoring original } @@ -723,7 +725,13 @@ namespace Scratch.Services { return is_saved; } - public bool move (File new_dest) { + private void set_syntax_highlighting () { + this.source_view.change_syntax_highlight_from_file ( + settings.get_boolean ("highlight-syntax") ? this.file : null + ); + } + + public bool move (File new_dest) { this.file = new_dest; this.save.begin (); diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index c03ddafba..609923659 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -213,7 +213,12 @@ namespace Scratch.Widgets { return !start.equal (end); } - public void change_syntax_highlight_from_file (File file) { + public void change_syntax_highlight_from_file (File? file) { + if (file == null) { + // Remove all highlighting + language = null; + } + try { var info = file.query_info ("standard::*", FileQueryInfoFlags.NONE, null); var mime_type = ContentType.get_mime_type ( From 606307cefdc93f99132f506b24e38a0a69e1b6cd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 9 Nov 2025 16:40:11 +0000 Subject: [PATCH 2/2] Add setting switch to PreferencesDialog --- src/Dialogs/PreferencesDialog.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 53288c398..b8fae810a 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -28,6 +28,7 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog { "smart-cut-copy", _("Cutting or copying without an active selection will cut or copy the entire current line") )); + general_box.add (new SettingSwitch (_("Highlight syntax"), "highlight-syntax")); var indent_width = new Gtk.SpinButton.with_range (1, 24, 1); Scratch.settings.bind ("indent-width", indent_width, "value", DEFAULT);