-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change(web): move KeyboardProcessor.Codes into common/web/types 🏗️ #11913
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,8 @@ | ||||||||||||||
// TODO: Move to separate folder: 'codes' | ||||||||||||||
// We should start splitting off code needed by keyboards even without a KeyboardProcessor active. | ||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be deleted; and we need a header.
Suggested change
|
||||||||||||||
// see also: common/web/types/src/kmx/kmx.ts | ||||||||||||||
|
||||||||||||||
const Codes = { | ||||||||||||||
export const Codes = { | ||||||||||||||
// Define Keyman Developer modifier bit-flags (exposed for use by other modules) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a overly broad export name! Can we rename it? |
||||||||||||||
// Compare against /common/include/kmx_file.h. CTRL+F "#define LCTRLFLAG" to find the secton. | ||||||||||||||
modifierCodes: { | ||||||||||||||
|
@@ -115,13 +114,13 @@ const Codes = { | |||||||||||||
* @return {number} modifier key state (desktop keyboards) | ||||||||||||||
*/ | ||||||||||||||
getModifierState(layerId: string): number { | ||||||||||||||
var modifier=0; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think any of the functions in this file should be moved over -- just the constants. These functions should stay in KeymanWeb's source, because they are not generic nor consistent enough to be put into common/types. |
||||||||||||||
let modifier=0; | ||||||||||||||
if(layerId.indexOf('shift') >= 0) { | ||||||||||||||
Comment on lines
-118
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason these were changed in this PR? I would prefer not to have even minimal changes like this in a refactor PR |
||||||||||||||
modifier |= Codes.modifierCodes['SHIFT']; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// The chiral checks must not be directly exclusive due each other to visual OSK feedback. | ||||||||||||||
var ctrlMatched=false; | ||||||||||||||
let ctrlMatched=false; | ||||||||||||||
if(layerId.indexOf('leftctrl') >= 0) { | ||||||||||||||
modifier |= Codes.modifierCodes['LCTRL']; | ||||||||||||||
ctrlMatched=true; | ||||||||||||||
|
@@ -134,7 +133,7 @@ const Codes = { | |||||||||||||
modifier |= Codes.modifierCodes['CTRL']; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
var altMatched=false; | ||||||||||||||
let altMatched=false; | ||||||||||||||
if(layerId.indexOf('leftalt') >= 0) { | ||||||||||||||
modifier |= Codes.modifierCodes['LALT']; | ||||||||||||||
altMatched=true; | ||||||||||||||
|
@@ -157,7 +156,7 @@ const Codes = { | |||||||||||||
* @return {number} modifier key state (desktop keyboards) | ||||||||||||||
*/ | ||||||||||||||
getStateFromLayer(layerId: string): number { | ||||||||||||||
var modifier=0; | ||||||||||||||
let modifier=0; | ||||||||||||||
|
||||||||||||||
if(layerId.indexOf('caps') >= 0) { | ||||||||||||||
modifier |= Codes.modifierCodes['CAPS']; | ||||||||||||||
|
@@ -168,5 +167,3 @@ const Codes = { | |||||||||||||
return modifier; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
export default Codes; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'mocha'; | ||
import { assert } from 'chai'; | ||
import { Codes } from '../../../src/consts/codes.js'; | ||
|
||
describe('Codes', function () { | ||
describe('test isFrameKey()', function () { | ||
it('should properly identify frame keys', () => { | ||
[ | ||
'K_SHIFT', | ||
'K_LOPT', | ||
'K_ROPT', | ||
'K_NUMLOCK', | ||
'K_CAPS', | ||
'K_NUMERALS', // not explicitly listed, but included because > 50000 | ||
].forEach(keyId => assert.isTrue(Codes.isFrameKey(keyId), `isFrameKey(${keyId})`)); | ||
|
||
[ | ||
'K_ESC', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a frame key, shouldn't it? But a job for a future PR if so. |
||
'K_OE2', | ||
'K_ALT', // not currently included in isFrameKey | ||
'K_CTRL', // not currently included in isFrameKey | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These also should be frame keys, shouldn't they? But also a job for a future PR if so. |
||
].forEach(keyId => assert.isFalse(Codes.isFrameKey(keyId), `!isFrameKey(${keyId})`)); | ||
}); | ||
}); | ||
|
||
describe('test getModifierState()', function () { | ||
it('should properly identify modifiers from layer id', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think many of these layerIds are deprecated, and it would be good to split tests for deprecated layerIds out. |
||
[ | ||
{ layerId: 'shift', expected: Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'leftshift', expected: Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'rightshift', expected: Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'ctrlshift', expected: Codes.modifierCodes['CTRL'] | Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'shiftctrl', expected: Codes.modifierCodes['CTRL'] | Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'fooshift', expected: Codes.modifierCodes['SHIFT'] }, | ||
|
||
{ layerId: 'leftctrl', expected: Codes.modifierCodes['LCTRL'] }, | ||
{ layerId: 'rightctrl', expected: Codes.modifierCodes['RCTRL'] }, | ||
{ layerId: 'ctrl', expected: Codes.modifierCodes['CTRL'] }, | ||
{ layerId: 'right_ctrl', expected: Codes.modifierCodes['CTRL'] }, | ||
{ layerId: 'leftctrlrightctrlshift', expected: Codes.modifierCodes['LCTRL'] | Codes.modifierCodes['RCTRL'] | Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'leftctrl-rightctrl-shift', expected: Codes.modifierCodes['LCTRL'] | Codes.modifierCodes['RCTRL'] | Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'ctrl-rightctrl-shift', expected: Codes.modifierCodes['RCTRL'] | Codes.modifierCodes['SHIFT'] }, | ||
|
||
{ layerId: 'leftalt', expected: Codes.modifierCodes['LALT'] }, | ||
{ layerId: 'rightalt', expected: Codes.modifierCodes['RALT'] }, | ||
{ layerId: 'alt', expected: Codes.modifierCodes['ALT'] }, | ||
{ layerId: 'leftaltrightaltshift', expected: Codes.modifierCodes['LALT'] | Codes.modifierCodes['RALT'] | Codes.modifierCodes['SHIFT'] }, | ||
{ layerId: 'leftaltrightalt', expected: Codes.modifierCodes['LALT'] | Codes.modifierCodes['RALT'] }, | ||
{ layerId: 'shiftleftctrlrightctrlleftaltrightalt', expected: Codes.modifierCodes['LCTRL'] | Codes.modifierCodes['RCTRL'] | Codes.modifierCodes['SHIFT'] | Codes.modifierCodes['LALT'] | Codes.modifierCodes['RALT'] }, | ||
{ layerId: 'shiftctrlalt', expected: Codes.modifierCodes['SHIFT'] | Codes.modifierCodes['CTRL'] | Codes.modifierCodes['ALT'] }, | ||
|
||
{ layerId: 'foo', expected: 0 }, | ||
|
||
].forEach(testdata => assert.equal(Codes.getModifierState(testdata.layerId), testdata.expected, `getModifierState(${testdata.layerId})`)); | ||
}); | ||
}); | ||
|
||
describe('test getStateFromLayer()', function () { | ||
it('should properly identify caps state from layer id', () => { | ||
[ | ||
{ layerId: 'caps', expected: Codes.modifierCodes['CAPS'] }, | ||
{ layerId: 'altcaps', expected: Codes.modifierCodes['CAPS'] }, | ||
{ layerId: 'capsalt', expected: Codes.modifierCodes['CAPS'] }, | ||
|
||
{ layerId: 'shift', expected: Codes.modifierCodes['NO_CAPS'] }, | ||
{ layerId: 'foo', expected: Codes.modifierCodes['NO_CAPS'] }, | ||
|
||
].forEach(testdata => { assert.equal(Codes.getStateFromLayer(testdata.layerId), testdata.expected, `getStateFromLayer(${testdata.layerId})`); }); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Codes } from "@keymanapp/common-types"; | ||
import { | ||
Codes, | ||
DefaultRules, | ||
type KeyEvent, | ||
type OutputTarget | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { Codes, DeviceSpec, Keyboard, KeyboardProperties, SpacebarText } from '@keymanapp/keyboard-processor'; | ||
export { DeviceSpec, Keyboard, KeyboardProperties, SpacebarText } from '@keymanapp/keyboard-processor'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering that we only even modularized to this extent with Keyman 17, I severely doubt anyone external is relying upon I would be a touch worried about Web's test-sequence "recording" module... but that's built via tl;dr: nah, no need to re-export. |
||
export { default as OSKView } from './views/oskView.js'; | ||
export { default as FloatingOSKView, FloatingOSKViewConfiguration } from './views/floatingOskView.js'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not great (double-exporting and flattening of exports like this) and I am glad it's gone ... but do we need to maintain the exports for compatibility? @jahorton
Also exported in web/src/engine/osk/src/index.ts (why?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, if it builds, I assume it's fine. Standard Web CI builds even build the development tools, which would be the only thing I'd worry about falling over. (They'd fail the build if they fell over.)