Skip to content

Commit

Permalink
fix(web): more robustness in case of deadkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
jahorton committed Apr 17, 2024
1 parent 0c8f520 commit fb127e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 22 additions & 0 deletions common/web/keyboard-processor/src/text/deadkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class Deadkey {
return dk;
}

equal(other: Deadkey) {
return this.d == other.d && this.p == other.d && this.o == other.o;
}

/**
* Sorts the deadkeys in reverse order.
*/
Expand Down Expand Up @@ -151,6 +155,24 @@ export class DeadkeyTracker {
}
}

equal(other: DeadkeyTracker) {
if(this.dks.length != other.dks.length) {
return false;
}

const otherDks = other.dks;
const matchedDks: Deadkey[] = [];

for(let dk of this.dks) {
const match = otherDks.find((otherDk) => dk.equal(otherDk));
if(!match) {
return false;
}
}

return matchedDks.length == otherDks.length;
}

count(): number {
return this.dks.length;
}
Expand Down
7 changes: 4 additions & 3 deletions common/web/keyboard-processor/src/text/outputTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,14 @@ export class Mock extends OutputTarget {

/**
* Indicates if this Mock represents an identical context to that of another Mock.
*
* Does not currently validate a match for deadkeys.
* @param other
* @returns
*/
isEqual(other: Mock) {
return this.text == other.text && this.selStart == other.selStart && this.selEnd == other.selEnd;
return this.text == other.text
&& this.selStart == other.selStart
&& this.selEnd == other.selEnd
&& this.deadkeys().equal(other.deadkeys());
}

doInputEvent() {
Expand Down

0 comments on commit fb127e7

Please sign in to comment.