Use Unicode keysym range as fallback
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.
This commit is contained in:
parent
4dc8953658
commit
115eedf69c
|
@ -10,7 +10,13 @@ var keysyms = (function(){
|
||||||
|
|
||||||
function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }
|
function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }
|
||||||
return {
|
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
|
lookup : lookup
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -184,10 +184,7 @@ var KeyboardUtil = {};
|
||||||
codepoint = evt.keyCode;
|
codepoint = evt.keyCode;
|
||||||
}
|
}
|
||||||
if (codepoint) {
|
if (codepoint) {
|
||||||
var res = keysyms.fromUnicode(substituteCodepoint(codepoint));
|
return keysyms.fromUnicode(substituteCodepoint(codepoint));
|
||||||
if (res) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// we could check evt.key here.
|
// we could check evt.key here.
|
||||||
// Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list,
|
// Legal values are defined in http://www.w3.org/TR/DOM-Level-3-Events/#key-values-list,
|
||||||
|
|
|
@ -38,9 +38,9 @@ describe('Helpers', function() {
|
||||||
it('should map characters which aren\'t in Latin1 *or* Windows-1252 to keysyms', 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);
|
expect(keysyms.fromUnicode('ŵ'.charCodeAt())).to.have.property('keysym', 0x1000175);
|
||||||
});
|
});
|
||||||
it('should return undefined for unknown codepoints', function() {
|
it('should map unknown codepoints to the Unicode range', function() {
|
||||||
expect(keysyms.fromUnicode('\n'.charCodeAt())).to.be.undefined;
|
expect(keysyms.fromUnicode('\n'.charCodeAt())).to.have.property('keysym', 0x100000a);
|
||||||
expect(keysyms.fromUnicode('\u1F686'.charCodeAt())).to.be.undefined;
|
expect(keysyms.fromUnicode('\u{1F686}'.charCodeAt())).to.have.property('keysym', 0x101f686);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,13 @@ var out = "// This file describes mappings from Unicode codepoints to the keysym
|
||||||
"\n" +
|
"\n" +
|
||||||
" function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }\n" +
|
" function lookup(k) { return k ? {keysym: k, keyname: keynames ? keynames[k] : k} : undefined; }\n" +
|
||||||
" return {\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" +
|
" lookup : lookup\n" +
|
||||||
" };\n" +
|
" };\n" +
|
||||||
"})();\n";
|
"})();\n";
|
||||||
|
|
Loading…
Reference in New Issue