Skip to content

Commit 22f7bdc

Browse files
authored
Merge pull request #9432 from keymanapp/feat/developer/9430-default-long-press
feat(developer): add 'default' property for longpress keys
2 parents 9e45159 + 087c68f commit 22f7bdc

File tree

10 files changed

+69
-4
lines changed

10 files changed

+69
-4
lines changed

common/schemas/keyman-touch-layout/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,17 @@ and `width`.
399399
: Number. Defines the width of the key. Not currently supported for longpress
400400
keys. See `key` object for details.
401401

402+
* `default`
403+
404+
: Boolean. Defaults to `false`. If true, this will be the default key when the
405+
user longpresses the base key without moving their finger. Only one subkey
406+
should be default; if multiple subkeys have the default field set, then
407+
behaviour is undefined. Given that cancel is not the preferred default
408+
action for a longpress, the user can cancel the longpress default by
409+
sliding outside the 'acceptance' area -- e.g. south of the key cap,
410+
which would then unhighlight the default and indicate visually that
411+
no output would occur when they release their finger.
412+
402413
## `flick` object
403414

404415
A object with a set of properties that define flick keys for given directions.
@@ -445,6 +456,9 @@ string") into the appropriate spec format.
445456

446457
# .keyman-touch-layout version history
447458

459+
## 2023-08-08 2.1 stable
460+
* Add support for default on longpress (sk) keys. Aligns with Keyman 17.0.
461+
448462
## 2022-06-30 2.0 stable
449463
* Add support for flick, multitap, hint, defaultHint. Aligns with Keyman 16.0.
450464

common/schemas/keyman-touch-layout/keyman-touch-layout.spec.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
"width": { "$ref" : "#/definitions/numeric" },
132132
"fontsize": { "$ref": "#/definitions/fontsize-spec" },
133133
"font": { "$ref": "#/definitions/font-spec" },
134-
"dk": { "type": "string" }
134+
"dk": { "type": "string" },
135+
"default": { "type": "boolean" }
135136
},
136137
"required": ["id"],
137138
"additionalProperties": false

common/web/types/src/keyman-touch-layout/keyman-touch-layout-file-writer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class TouchLayoutFileWriter {
7777
if(Object.hasOwn(key, 'text') && key.text === '') delete key.text;
7878
if(Object.hasOwn(key, 'id') && <string>key.id === '') delete key.id;
7979
if(Object.hasOwn(key, 'hint') && (<any>key).hint === '') delete (<any>key).hint;
80+
if(Object.hasOwn(key, 'default') && (<any>key).default === false) delete (<any>key).default;
8081
};
8182

8283
const fixupPlatform = (platform: TouchLayoutPlatform) => {

common/web/types/src/keyman-touch-layout/keyman-touch-layout-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface TouchLayoutSubKey {
7373
sp?: TouchLayoutKeySp;
7474
pad?: TouchLayoutKeyPad;
7575
width?: TouchLayoutKeyWidth;
76+
default?: boolean; // Only used for longpress currently
7677
};
7778

7879
export interface TouchLayoutFlick {

developer/src/tike/oskbuilder/TouchLayout.pas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ TTouchLayoutSubKey = class(TTouchLayoutObject)
9696
FPad: Integer;
9797
FSp: Integer;
9898
FText: string;
99+
FDefault: boolean;
99100
function GetSpT: TTouchKeyType; // I4119
100101
procedure SetSpT(const Value: TTouchKeyType); // I4119
101102
protected
@@ -113,6 +114,7 @@ TTouchLayoutSubKey = class(TTouchLayoutObject)
113114
property NextLayer: string read FNextLayer write FNextLayer;
114115
property Font: string read FFont write FFont;
115116
property FontSize: string read FFontSize write FFontSize;
117+
property Default: boolean read FDefault write FDefault;
116118
end;
117119

118120
TTouchLayoutSubKeys = class(TObjectList<TTouchLayoutSubKey>)
@@ -734,6 +736,7 @@ procedure TTouchLayoutSubKey.DoRead;
734736
GetValue('pad', FPad);
735737
GetValue('sp', FSp);
736738
GetValue('text', FText);
739+
GetValue('default', FDefault);
737740
end;
738741

739742
procedure TTouchLayoutObject.AddJSONValue(JSON: TJSONObject; const name, value: string);
@@ -760,6 +763,7 @@ procedure TTouchLayoutSubKey.DoWrite(JSON: TJSONObject);
760763
if FPad <> 0 then AddJSONValue(JSON, 'pad', IntToStr(FPad));
761764
if FSp <> 0 then AddJSONValue(JSON, 'sp', IntToStr(FSp));
762765
AddJSONValue(JSON, 'text', FText);
766+
if FDefault then AddJSONValue(JSON, 'default', FDefault);
763767
end;
764768

765769
function TTouchLayoutSubKey.GetSpT: TTouchKeyType; // I4119

developer/src/tike/oskbuilder/TouchLayoutDefinitions.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TJSONDef = record
3636
TJSONDefArray = array of TJSONDef;
3737

3838
const
39-
SkDef: array[0..9] of TJSONDef = (
39+
SkDef: array[0..10] of TJSONDef = (
4040
(Name: 'id'; ClassType: TJSONString; Required: True),
4141
(Name: 'text'; ClassType: TJSONString),
4242
(Name: 'sp'; ClassType: TJSONValue),
@@ -46,7 +46,8 @@ TJSONDef = record
4646
(Name: 'layer'; ClassType: TJSONString),
4747
(Name: 'nextlayer'; ClassType: TJSONString),
4848
(Name: 'font'; ClassType: TJSONString),
49-
(Name: 'fontsize'; ClassType: TJSONString)
49+
(Name: 'fontsize'; ClassType: TJSONString),
50+
(Name: 'default'; ClassType: TJSONBool)
5051
);
5152

5253
FlickDef: array[0..7] of TJSONDef = (

developer/src/tike/xml/layoutbuilder/builder.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,19 @@ body {
307307
box-shadow: 0px 0px 20px rgba(100, 100, 255, 0.5);
308308
}
309309

310+
.key.key-is-default {
311+
border-width: 4px;
312+
}
313+
314+
.key.key-is-default .id {
315+
bottom: 1px;
316+
right: 1px;
317+
}
318+
319+
.key.key-is-default .text {
320+
margin-top: -3px;
321+
}
322+
310323
.row {
311324
clear:left;
312325
line-height: 1;
@@ -578,6 +591,10 @@ body:not(.text-controls-in-toolbar) input#inpSubKeyCap {
578591
display: none;
579592
}
580593

594+
input#chkSubKeyIsDefault {
595+
margin-top: 10px;
596+
}
597+
581598
.key-size {
582599
font-family: Calibri;
583600
position: absolute;

developer/src/tike/xml/layoutbuilder/builder.xsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@
247247
<label for='selSubKeyNextLayer'>Next Layer:</label>
248248
<select id='selSubKeyNextLayer'></select>
249249
</div>
250+
<div class='toolbar-item'>
251+
<label for='chkSubKeyIsDefault'>Default selection:</label>
252+
<input id='chkSubKeyIsDefault' type='checkbox' />
253+
</div>
250254
</div>
251255

252256
<!-- Subkey Controls -->

developer/src/tike/xml/layoutbuilder/prepare-key.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ $(function() {
138138
.data('nextlayer', key.nextlayer)
139139
.data('layer', key.layer)
140140
.data('direction', key.direction) // used only by flicks
141+
.data('default', key.default) // used only by longpress
141142
.css('width', (100 * 0.7) + 'px')
142143
.css('font-family', key.font)
143144
.css('font-size', key.fontsize);
@@ -146,6 +147,10 @@ $(function() {
146147
$(nkey).addClass('key-special-text');
147148
}
148149

150+
if(key.default) {
151+
$(nkey).addClass('key-is-default');
152+
}
153+
149154
$('.text', nkey).text(builder.renameSpecialKey(text));
150155
builder.updateKeyId(nkey);
151156
}

developer/src/tike/xml/layoutbuilder/subkeys.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ $(function() {
4141
fontsize: $(key).data('fontsize'),
4242
nextlayer: $(key).data('nextlayer'),
4343
layer: $(key).data('layer'),
44-
direction: $(key).data('direction')
44+
direction: $(key).data('direction'),
45+
default: $(key).data('default')
4546
});
4647
}
4748
return items;
@@ -72,6 +73,7 @@ $(function() {
7273
$('#selSubKeyType').val($(key).data('sp') ? $(key).data('sp') : 0);
7374
$('#selSubKeyNextLayer').val($(key).data('nextlayer'));
7475
$('#selSubKeyLayerOverride').val($(key).data('layer'));
76+
$('#chkSubKeyIsDefault').prop('checked', !!$(key).data('default'));
7577
}
7678

7779
const subKeyNameChange = builder.wrapChange(function () {
@@ -166,6 +168,20 @@ $(function() {
166168

167169
$('#selSubKeyNextLayer').change(selSubKeyNextLayerChange);
168170

171+
const chkSubKeyIsDefaultChange = builder.wrapChange(function () {
172+
// Remove default property from all subkeys
173+
$('#sub-key-groups .key-is-default').removeData('default');
174+
$('#sub-key-groups .key-is-default').removeClass('key-is-default');
175+
if($(this).prop('checked')) {
176+
// Then add it to selected key
177+
builder.selectedSubKey().data('default', true);
178+
builder.selectedSubKey().addClass('key-is-default');
179+
}
180+
builder.generateSubKeys();
181+
});
182+
183+
$('#chkSubKeyIsDefault').change(chkSubKeyIsDefaultChange);
184+
169185
const selSubKeyLayerOverrideChange = builder.wrapChange(function () {
170186
$(this).val() === '' ?
171187
builder.selectedSubKey().removeData('layer') :
@@ -276,6 +292,7 @@ $(function() {
276292
$('#subKeyToolbar *').removeAttr('disabled');
277293
$('#subKeyToolbar #inpSubKeyGestureType').attr('disabled', 'disabled');
278294
$('#sub-key-cap-unicode-toolbar-item, #sub-key-cap-toolbar-item').css('display', builder.specialCharacters[val] ? 'none' : '');
295+
$('#chkSubKeyIsDefault').prop('disabled', $(key).data('type') != 'longpress');
279296
}
280297
}
281298

0 commit comments

Comments
 (0)