mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(web): count Android recovery deletions in graphemes, release the overlay change (#830)
The keyCode-229 recovery diff counts grapheme clusters, matching the overlay and the iOS owner, so one Backspace on a multi-code-point emoji is one DEL. List xterm-zerolag-input in the changeset; document getInputEndAnchor(), onLayout() and the grapheme unit of removeChar().
This commit is contained in:
1 parent
71c7d01d02
commit
e4ac7728ba
4 files changed
+76
-6
No files matched your search
@@ -60,15 +60,32 @@
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
// Grapheme clusters, the unit a soft-keyboard Backspace removes, Claude Code and
|
||||
// Codex delete per DEL, and the local-echo overlay drops per DEL. Code points
|
||||
// stand in where Intl.Segmenter is missing (same rule as terminal-ios-native-input.js).
|
||||
const graphemeSegmenter = (() => {
|
||||
try {
|
||||
return typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function'
|
||||
? new Intl.Segmenter(undefined, { granularity: 'grapheme' })
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
function graphemes(text) {
|
||||
return graphemeSegmenter ? Array.from(graphemeSegmenter.segment(text), (part) => part.segment) : Array.from(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* What turns `previous` into `next`, as a terminal sees it: how many characters to delete from
|
||||
* the END of the line, then what to type. Everything after the common prefix is treated as
|
||||
* replaced, because a terminal can only edit at its cursor. Counts are code points, so an
|
||||
* emoji is one DEL, as it is one backspace.
|
||||
* replaced, because a terminal can only edit at its cursor. Counts are grapheme clusters, so a
|
||||
* red heart, a skin-tone emoji, a flag or a ZWJ family is one DEL, as it is one backspace.
|
||||
*/
|
||||
function editBetween(previous, next) {
|
||||
const a = Array.from(previous);
|
||||
const b = Array.from(next);
|
||||
const a = graphemes(previous);
|
||||
const b = graphemes(next);
|
||||
let prefix = 0;
|
||||
const max = Math.min(a.length, b.length);
|
||||
while (prefix < max && a[prefix] === b[prefix]) prefix += 1;
|
||||
|
||||
Reference in new issue
Block a user