[gnome-calculator] Fix #22, solve on [=] key if the input is not a variable name.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Fix #22, solve on [=] key if the input is not a variable name.
- Date: Wed, 13 Nov 2019 22:57:39 +0000 (UTC)
commit 2123989d5fcfc06d47ca71148893616e101d448d
Author: Alberto González Palomo <bugs sentido-labs com>
Date: Wed Nov 13 22:57:28 2019 +0000
Fix #22, solve on [=] key if the input is not a variable name.
If the input is a variable name, this would be an assignment
so the "=" sign is inserted.
Otherwise, the equation is solved which makes usage much more
comfortable in certain keyboards like mine.
src/math-display.vala | 11 +++++++++++
1 file changed, 11 insertions(+)
---
diff --git a/src/math-display.vala b/src/math-display.vala
index a54bb778..11cb5ba4 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -24,6 +24,8 @@ public class MathDisplay : Gtk.Viewport
/* Spinner widget that shows if we're calculating a response */
Gtk.Spinner spinner;
+ Regex only_variable_name = /^_*\p{L}+(_|\p{L})*$/;
+
public MathDisplay (MathEquation equation)
{
_equation = equation;
@@ -210,6 +212,15 @@ public class MathDisplay : Gtk.Viewport
var c = Gdk.keyval_to_unicode (event.keyval);
+ /* 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))
+ {
+ event.keyval = Gdk.Key.KP_Enter;
+ }
+ }
+
/* Solve on enter */
if (event.keyval == Gdk.Key.Return || event.keyval == Gdk.Key.KP_Enter)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]