From 69ef2af6653606989683f37e9abc6d4dddbd7204 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 18 Aug 2025 14:58:24 +0100 Subject: [PATCH 1/2] Insert brackets after function --- src/MainWindow.vala | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 24041c27..144859bd 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -573,17 +573,20 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { var token = variant.get_string (); int selection_start = -1; int selection_end = -1; + var selected_text = ""; + int new_position = entry.get_position (); if (entry.get_selection_bounds (out selection_start, out selection_end)) { - int new_position = selection_start; - string selected_text = entry.get_chars (selection_start, selection_end); - string function_call = token + "(" + selected_text + ")"; - entry.delete_text (selection_start, selection_end); - entry.insert_text (function_call, -1, ref selection_start); - new_position += function_call.char_count (); - entry.grab_focus (); - entry.set_position (new_position); - } else { - activate_action (ACTION_INSERT, variant); + new_position = selection_start; + selected_text = entry.get_chars (selection_start, selection_end); + } + + string function_call = token + "(" + selected_text + ")"; + entry.delete_text (selection_start, selection_end); + entry.insert_text (function_call, -1, ref selection_start); + new_position += function_call.char_count (); + entry.grab_focus (); + if (selected_text = "") { + entry.set_position (new_position - 1); } } From 4274e5a2a602f2f11546b9a215def5a3f1dc69f5 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Mon, 18 Aug 2025 15:06:19 +0100 Subject: [PATCH 2/2] Fix position --- src/MainWindow.vala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 144859bd..c201fe09 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -585,9 +585,11 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { entry.insert_text (function_call, -1, ref selection_start); new_position += function_call.char_count (); entry.grab_focus (); - if (selected_text = "") { - entry.set_position (new_position - 1); + if (selected_text == "") { + new_position--; } + + entry.set_position (new_position); } private void button_calc_clicked () {