]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Use Unicode keysym range as fallback
authorPierre Ossman <pierre@ossman.eu>
Fri, 14 Oct 2016 06:39:28 +0000 (08:39 +0200)
committerPierre Ossman <pierre@ossman.eu>
Sat, 15 Oct 2016 12:58:55 +0000 (14:58 +0200)
Not all Unicode codepoints have an equivalent named Keysym. But
there is a range in the Keysym namespace that can be used to map
any codepoint to.

core/input/keysymdef.js
core/input/util.js
tests/test.helper.js
utils/parse.js

index f45d9d9010c5b2224e67c1dd734eb6f9f0b4048b..c4d0ace91a4114fae8859f2189bf99fb704a6948 100644 (file)
@@ -10,7 +10,13 @@ var keysyms = (function(){
 
     function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }
     return {
-        fromUnicode : function(u) { return lookup(codepoints[u]); },
+        fromUnicode : function(u) {
+            var keysym = codepoints[u];
+            if (keysym === undefined) {
+                keysym = 0x01000000 | u;
+            }
+            return lookup(keysym);
+        },
         lookup : lookup
     };
 })();
index efdccedcda9ef0b6a684c1a432034edc39215181..52b31283f9a0d728fbcfa3e5e264a5e7fef0cb89 100644 (file)
@@ -184,10 +184,7 @@ var KeyboardUtil = {};
             codepoint = evt.keyCode;
         }
         if (codepoint) {
-            var res = keysyms.fromUnicode(substituteCodepoint(codepoint));
-            if (res) {
-                return res;
-            }
+            return keysyms.fromUnicode(substituteCodepoint(codepoint));
         }
         // we could check evt.key here.
         // Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list,
index 4982535c83dc078d639f906d4227f9f559407ea3..0c68b16728fab08dd3231d831199416adc54d516 100644 (file)
@@ -38,9 +38,9 @@ describe('Helpers', function() {
         it('should map characters which aren\'t in Latin1 *or* Windows-1252 to keysyms', function() {
             expect(keysyms.fromUnicode('ลต'.charCodeAt())).to.have.property('keysym', 0x1000175);
         });
-        it('should return undefined for unknown codepoints', function() {
-            expect(keysyms.fromUnicode('\n'.charCodeAt())).to.be.undefined;
-            expect(keysyms.fromUnicode('\u1F686'.charCodeAt())).to.be.undefined;
+        it('should map unknown codepoints to the Unicode range', function() {
+            expect(keysyms.fromUnicode('\n'.charCodeAt())).to.have.property('keysym', 0x100000a);
+            expect(keysyms.fromUnicode('\u{1F686}'.charCodeAt())).to.have.property('keysym', 0x101f686);
         });
     });
 
index 02ac66c203a0bd52cfbec0e89b4cb31c9b992555..fd79b12ba576095166deec457fb0c3fe93a18d78 100644 (file)
@@ -87,7 +87,13 @@ var out = "// This file describes mappings from Unicode codepoints to the keysym
 "\n" +
 "    function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }\n" +
 "    return {\n" +
-"        fromUnicode : function(u) { return lookup(codepoints[u]); },\n" +
+"        fromUnicode : function(u) {\n" +
+"            var keysym = codepoints[u];\n" +
+"            if (keysym === undefined) {\n" +
+"                keysym = 0x01000000 | u;\n" +
+"            }\n" +
+"            return lookup(keysym);\n" +
+"        },\n" +
 "        lookup : lookup\n" +
 "    };\n" +
 "})();\n";