fix(web): font assignment if special-text

This commit is contained in:
Joshua A. Horton 2024-01-12 12:37:21 +07:00
parent 46b0411c34
commit b60e2e2884
3 changed files with 18 additions and 6 deletions

View file

@ -60,10 +60,7 @@ export default class Multitap implements GestureHandler {
const tapLookahead = (offset) => (this.tapIndex + offset) % this.multitaps.length;
const updatePreview = () => {
previewHost?.setMultitapHint(
renameSpecialKey(this.multitaps[tapLookahead(0)].text, vkbd),
renameSpecialKey(this.multitaps[tapLookahead(1)].text, vkbd)
);
previewHost?.setMultitapHint(this.multitaps[tapLookahead(0)], this.multitaps[tapLookahead(1)], vkbd);
}
source.on('complete', () => {

View file

@ -4,6 +4,8 @@ import EventEmitter from "eventemitter3";
import { KeyElement } from "../keyElement.js";
import { FlickNameCoordMap, OrderedFlickDirections } from "../input/gestures/browser/flick.js";
import { PhoneKeyTipOrientation } from "../input/gestures/browser/keytip.js";
import { default as VisualKeyboard } from "../visualKeyboard.js";
import { renameSpecialKey } from "./oskKey.js";
/**With edge lengths of 1, to keep flick-text invisible at the start, the
* hypotenuse for an inter-cardinal path is sqrt(2). To keep a perfect circle
@ -130,10 +132,16 @@ export class GesturePreviewHost extends EventEmitter<EventMap> {
this.onCancel = handler;
}
public setMultitapHint(current: string, next: string) {
public setMultitapHint(currentSrc: ActiveKeyBase, nextSrc: ActiveKeyBase, vkbd?: VisualKeyboard) {
const current = renameSpecialKey(currentSrc.text, vkbd);
const next = renameSpecialKey(nextSrc.text, vkbd);
this.label.textContent = current;
this.hintLabel.textContent = next;
this.label.style.fontFamily = (current != currentSrc.text) ? 'SpecialOSK' : currentSrc.font ?? this.label.style.fontFamily;
this.hintLabel.style.fontFamily = (next != nextSrc.text) ? 'SpecialOSK' : nextSrc.font ?? this.hintLabel.style.fontFamily;
this.emit('startFade');
this.clearFlick();

View file

@ -161,11 +161,18 @@ export default class OSKBaseKey extends OSKKey {
// If the base key itself is the source of the hint text, we use `hint` directly.
// Otherwise, we present the source subkey's key cap as the hint.
const text = renameSpecialKey(hintSpec == this.spec ? this.spec.hint : hintSpec.text, vkbd);
const baseText = hintSpec == this.spec ? this.spec.hint : hintSpec.text
const text = renameSpecialKey(baseText, vkbd);
if(text == '\u2022') {
// The original, pre-17.0 longpress dot-hint used bold-face styling.
skIcon.style.fontWeight='bold';
}
if(baseText != text) {
// if the text is from a *Special* shorthand, always use our special-key OSK font.
skIcon.style.fontFamily = 'SpecialOSK';
}
skIcon.textContent = text;
return skIcon;