[gnome-calculator] Fix issue when user write = in func definition



commit 10ac240d8bc699eb6f9b8ef939d4ed7948cd107b
Author: harryjrk <martinjirku gmail com>
Date:   Sat May 15 17:25:18 2021 +0200

    Fix issue when user write = in func definition
    
    When user specifies custom function, application changed = to KP_Enter
    key, instead allow user to continue, which made it impossible to specify
    custom function without copy+paste. After user write =, application will
    check, if user started to write function definition.
    
    Implements #188

 src/math-display.vala | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/src/math-display.vala b/src/math-display.vala
index 760fd397..93f2dc39 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -27,6 +27,7 @@ public class MathDisplay : Gtk.Box
     public bool completion_selected { get; set;}
 
     Regex only_variable_name = /^_*\p{L}+(_|\p{L})*$/;
+    Regex only_function_definition = /^[a-zA-Z0-9 ]*\(([a-zA-z0-9;]*)?\)[ ]*$/;
 
     static construct {
         set_css_name ("mathdisplay");
@@ -247,7 +248,8 @@ public class MathDisplay : Gtk.Box
         /* Solve on [=] if the input is not a variable name */
         if (event.keyval == Gdk.Key.equal || event.keyval == Gdk.Key.KP_Equal)
         {
-            if (!only_variable_name.match((string) equation.equation))
+            if (!(only_variable_name.match((string) equation.equation)
+                || only_function_definition.match((string) equation.equation)))
             {
                 event.keyval = Gdk.Key.KP_Enter;
             }


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