From 96cd2bb4fcec9bc33bd32f63769e1206b4b140d4 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 14 Aug 2026 16:46:43 +0100 Subject: [PATCH 1/3] Ensure update language when doc loaded and language identified --- src/Widgets/FormatBar.vala | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Widgets/FormatBar.vala b/src/Widgets/FormatBar.vala index 3616d59246..98364b5dbb 100644 --- a/src/Widgets/FormatBar.vala +++ b/src/Widgets/FormatBar.vala @@ -270,16 +270,45 @@ public class Code.FormatBar : Gtk.Box { goto_entry.text = "%d.%d".printf (line, iter.get_line_offset () + 1); } - public void set_document (Scratch.Services.Document doc) { - if (this.doc != null) { - this.doc.source_view.buffer.notify["cursor-position"].disconnect (format_line_header); + private ulong cursor_handler = 0; + private ulong language_handler = 0; + public void set_document (Scratch.Services.Document set_doc) requires (set_doc != null) { + if (doc != null) { + SignalHandler.disconnect (doc, cursor_handler); + SignalHandler.disconnect (doc, language_handler); } - this.doc = doc; + doc = set_doc; + if (doc.loading) { + Timeout.add (200, () => { + if (doc.loading) { + return Source.CONTINUE; + } else { + update_widgets (); + return Source.REMOVE; + } + }); + } else { + update_widgets (); + } + } + + private void update_widgets () requires (this.doc != null) { + // Cannot be sure when language will be identified on new doc so update when it changes + if (language_handler == 0) { + language_handler = this.doc.source_view.notify["language"].connect (update_current_lang); + } + // Also update here in case already identified. update_current_lang (); + + if (cursor_handler == 0) { + cursor_handler = this.doc.source_view.buffer.notify["cursor-position"].connect (format_line_header); + } + + format_tab_header_from_global_settings (); format_tab_header_from_global_settings (); format_line_header (); - this.doc.source_view.buffer.notify["cursor-position"].connect (format_line_header); + } public void set_insert_spaces_instead_of_tabs (bool use_spaces) { From 6b54b2785f657656f5aebf918d978809cb7ee0ec Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 14 Aug 2026 17:16:48 +0100 Subject: [PATCH 2/3] Simplify --- src/Widgets/FormatBar.vala | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/src/Widgets/FormatBar.vala b/src/Widgets/FormatBar.vala index 98364b5dbb..12aea7a46e 100644 --- a/src/Widgets/FormatBar.vala +++ b/src/Widgets/FormatBar.vala @@ -270,45 +270,22 @@ public class Code.FormatBar : Gtk.Box { goto_entry.text = "%d.%d".printf (line, iter.get_line_offset () + 1); } - private ulong cursor_handler = 0; - private ulong language_handler = 0; public void set_document (Scratch.Services.Document set_doc) requires (set_doc != null) { - if (doc != null) { - SignalHandler.disconnect (doc, cursor_handler); - SignalHandler.disconnect (doc, language_handler); + if (doc != null) { + warning ("disconnect %s", doc.file.get_basename ()); + doc.source_view.notify["language"].disconnect (update_current_lang); + doc.source_view.buffer.notify["cursor-position"].disconnect (format_line_header); } doc = set_doc; - if (doc.loading) { - Timeout.add (200, () => { - if (doc.loading) { - return Source.CONTINUE; - } else { - update_widgets (); - return Source.REMOVE; - } - }); - } else { - update_widgets (); - } - } - private void update_widgets () requires (this.doc != null) { - // Cannot be sure when language will be identified on new doc so update when it changes - if (language_handler == 0) { - language_handler = this.doc.source_view.notify["language"].connect (update_current_lang); - } - // Also update here in case already identified. + doc.source_view.notify["language"].connect (update_current_lang); update_current_lang (); - if (cursor_handler == 0) { - cursor_handler = this.doc.source_view.buffer.notify["cursor-position"].connect (format_line_header); - } - - format_tab_header_from_global_settings (); - format_tab_header_from_global_settings (); + doc.source_view.buffer.notify["cursor-position"].connect (format_line_header); format_line_header (); + format_tab_header_from_global_settings (); } public void set_insert_spaces_instead_of_tabs (bool use_spaces) { From a04786a58bd0fc5113369b1773c17015e9f6140e Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 14 Aug 2026 17:18:26 +0100 Subject: [PATCH 3/3] Lose debug code --- src/Widgets/FormatBar.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Widgets/FormatBar.vala b/src/Widgets/FormatBar.vala index 12aea7a46e..0cfee4d666 100644 --- a/src/Widgets/FormatBar.vala +++ b/src/Widgets/FormatBar.vala @@ -272,7 +272,6 @@ public class Code.FormatBar : Gtk.Box { public void set_document (Scratch.Services.Document set_doc) requires (set_doc != null) { if (doc != null) { - warning ("disconnect %s", doc.file.get_basename ()); doc.source_view.notify["language"].disconnect (update_current_lang); doc.source_view.buffer.notify["cursor-position"].disconnect (format_line_header); }