[gnome-calculator] Fix base change for log, fixes #748729



commit 917ba191ff4528ad9469a865d16654435fa38a52
Author: Robert Roth <robert roth off gmail com>
Date:   Mon Sep 19 02:50:47 2016 +0300

    Fix base change for log, fixes #748729
    
    https://bugzilla.gnome.org/show_bug.cgi?id=748729
    Ported the behaviour of the superscript/subscript toggle of removing
    trailing spaces if no selection to the keyboard-only superscript/subscript
    entry using modifiers.

 lib/math-equation.vala |   17 +++++++++++++++++
 src/math-buttons.vala  |   21 ++-------------------
 src/math-display.vala  |    4 ++++
 3 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/lib/math-equation.vala b/lib/math-equation.vala
index 63ee889..af0dfea 100644
--- a/lib/math-equation.vala
+++ b/lib/math-equation.vala
@@ -263,6 +263,23 @@ public class MathEquation : Gtk.SourceBuffer
         get_iter_at_mark (out ans_end, ans_end_mark);
     }
 
+    public void remove_trailing_spaces ()
+    {
+        var insert_mark = get_insert ();
+        Gtk.TextIter start, end;
+        get_iter_at_mark (out end, insert_mark);
+        start = end;
+        while (start.backward_char ())
+        {
+            if (!start.get_char ().isspace ())
+            {
+                start.forward_char ();
+                break;
+            }
+        }
+        this.delete (ref start, ref end);
+    }
+
     private void reformat_separators ()
     {
         var in_number = false;
diff --git a/src/math-buttons.vala b/src/math-buttons.vala
index ff03591..e5c1534 100644
--- a/src/math-buttons.vala
+++ b/src/math-buttons.vala
@@ -934,23 +934,6 @@ public class MathButtons : Gtk.Box
         return true;
     }
 
-    private void remove_trailing_spaces ()
-    {
-        var insert_mark = equation.get_insert ();
-        Gtk.TextIter start, end;
-        equation.get_iter_at_mark (out end, insert_mark);
-        start = end;
-        while (start.backward_char ())
-        {
-            if (!start.get_char ().isspace ())
-            {
-                start.forward_char ();
-                break;
-            }
-        }
-        equation.delete (ref start, ref end);
-    }
-
     private void set_superscript_cb (Gtk.Button widget)
     {
         var button = widget as Gtk.ToggleButton;
@@ -959,7 +942,7 @@ public class MathButtons : Gtk.Box
         {
             equation.number_mode = NumberMode.SUPERSCRIPT;
             if (!equation.has_selection)
-                remove_trailing_spaces ();
+                equation.remove_trailing_spaces ();
         }
         else if (equation.number_mode == NumberMode.SUPERSCRIPT)
             equation.number_mode = NumberMode.NORMAL;
@@ -973,7 +956,7 @@ public class MathButtons : Gtk.Box
         {
             equation.number_mode = NumberMode.SUBSCRIPT;
             if (!equation.has_selection)
-                remove_trailing_spaces ();
+                equation.remove_trailing_spaces ();
         }
         else if (equation.number_mode == NumberMode.SUBSCRIPT)
             equation.number_mode = NumberMode.NORMAL;
diff --git a/src/math-display.vala b/src/math-display.vala
index bcb3ce5..9df510f 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -298,6 +298,8 @@ public class MathDisplay : Gtk.Viewport
 
         if (state == Gdk.ModifierType.CONTROL_MASK || equation.number_mode == NumberMode.SUPERSCRIPT)
         {
+            if (!equation.has_selection)
+                equation.remove_trailing_spaces ();
             switch (event.keyval)
             {
             case Gdk.Key.@0:
@@ -344,6 +346,8 @@ public class MathDisplay : Gtk.Viewport
         }
         else if (state == Gdk.ModifierType.MOD1_MASK || equation.number_mode == NumberMode.SUBSCRIPT)
         {
+            if (!equation.has_selection)
+                equation.remove_trailing_spaces ();
             switch (event.keyval)
             {
             case Gdk.Key.@0:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]