#1543 Key.fromMask doesn't work for complex modifier

Yuri Strot Mon 23 May 2011

Following example:

using fwt

class HelloFantom
{
  Void main()
  {
    echo((Key.shift + Key.ctrl).modifiers)
  }
}

causes following exception:

sys::Err: Invalid unicode char: 393216
fan.sys.FanInt.toChar (FanInt.java:442)
fwt::Key.fromMask (Key.fan:201)
fwt::Key.modifiers (Key.fan:273)
HelloFantom.main (fansh:7)
java.lang.reflect.Method.invoke (Method.java:43)
51 More...

I'm not sure about correct solution but I think Key.fromMask should be a bit clever.

P.S. Thanks to Kaushik this issue can be reproduced right here: http://www.fanzy.net/

brian Mon 23 May 2011

Promoted to ticket #1543 and assigned to brian

Yeah, I agree that method needs to more sophisticated to handle modifier combos

Yuri Strot Tue 24 May 2011

Looks like fwt::Key.fromMask mostly used for key codes. The only exception is fwt::Key.modifiers. May be it makes sense to leave fromMask for key codes and handle modifiers separately:

diff --git a/src/fwt/fan/Key.fan b/src/fwt/fan/Key.fan
--- a/src/fwt/fan/Key.fan
+++ b/src/fwt/fan/Key.fan
@@ -265,12 +265,20 @@
   **
   ** Decompose the key into its primary key (without modifiers).
   **
-  Key primary() { fromMask(mask.and(modifierMask.not)) }
+  Key primary() { fromMask(mask.and(modifierUnmask)) }
 
   **
   ** Return a Key instance with only the modifiers.
   **
-  Key modifiers() { fromMask(mask.and(modifierMask)) }
+  Key modifiers()
+  {
+    key := none
+    if (isAlt)     key += alt 
+    if (isShift)   key += shift 
+    if (isCtrl)    key += ctrl
+    if (isCommand) key += command
+    return key
+  }
 
   **
   ** Is this instance is a modifier which may be combined
@@ -316,6 +324,8 @@
   @Operator Key plus(Key x)
   {
     if (!isModifier && !x.isModifier) throw ArgErr("Neither is modifier: $this + $x")
+    if (mask == 0) return x
+    if (x.mask == 0) return this
     return makeNew(mask.or(x.mask), null)
   }
 

brian Tue 24 May 2011

Ticket resolved in 1.0.59

Great patch, thanks Yuri

changeset

Login or Signup to reply.