mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(web): delete one grapheme per iOS Backspace, keep the recovery fallback (#830)
Count native edits and overlay deletions in grapheme clusters (Intl.Segmenter, code-point fallback), so one Backspace on a multi-code-point emoji sends one DEL. Toolbar Enter with echo off tells the codex predictor about the CR, clearing its predictions as typed Enter does. Fall back to the keyCode-229 recovery when the iOS owner refuses to start, in the main pane and tiles.
This commit is contained in:
1 parent
05fc2f990b
commit
71c7d01d02
8 files changed
+184
-24
No files matched your search
@@ -15,9 +15,27 @@
|
||||
(function (global) {
|
||||
'use strict';
|
||||
|
||||
// WebKit removes one grapheme cluster per Backspace, and Claude Code and Codex
|
||||
// delete one grapheme per DEL, so an edit is counted in graphemes: a red heart,
|
||||
// a skin-tone emoji, a flag or a ZWJ family is one DEL, as it was through xterm.
|
||||
// Code points stand in where Intl.Segmenter is missing.
|
||||
const graphemeSegmenter = (function () {
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
while (prefix < a.length && prefix < b.length && a[prefix] === b[prefix]) prefix += 1;
|
||||
return { deleted: a.length - prefix, inserted: b.slice(prefix).join('') };
|
||||
|
||||
@@ -661,7 +661,11 @@
|
||||
});
|
||||
if (this._iosNativeInput) {
|
||||
this._iosCaretMarker = nativeInput.attachCaretMarker(this.terminal, this._iosNativeInput);
|
||||
return;
|
||||
}
|
||||
// create() refused (screen reader, missing xterm internals): keep the
|
||||
// soft-keyboard recovery rather than leaving the tile with neither.
|
||||
this._createKeyCode229Recovery();
|
||||
}
|
||||
|
||||
_sendNativeInputTransaction(ops) {
|
||||
|
||||
@@ -764,21 +764,26 @@ Object.assign(CodemanApp.prototype, {
|
||||
},
|
||||
isScreenReaderMode: () => this.terminal?.options?.screenReaderMode === true,
|
||||
});
|
||||
this._iosCaretMarker = window.CodemanIosNativeInput.attachCaretMarker?.(this.terminal, this._iosNativeInput, {
|
||||
anchor: () => this._nativeInputAnchor(),
|
||||
subscribe: (callback) => this._localEchoOverlay?.onLayout?.(callback),
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
this._keyCode229Recovery = window.CodemanKeyCode229Recovery?.create?.({
|
||||
textarea: this.terminal.textarea,
|
||||
emitRecovered: (data) => this._handleTerminalData(data, this.activeSessionId),
|
||||
getCompositionHelper: () => this.terminal?._core?._compositionHelper,
|
||||
isScreenReaderMode: () => this.terminal?.options?.screenReaderMode === true,
|
||||
if (this._iosNativeInput) {
|
||||
this._iosCaretMarker = window.CodemanIosNativeInput.attachCaretMarker?.(this.terminal, this._iosNativeInput, {
|
||||
anchor: () => this._nativeInputAnchor(),
|
||||
subscribe: (callback) => this._localEchoOverlay?.onLayout?.(callback),
|
||||
});
|
||||
} catch {
|
||||
this._keyCode229Recovery = null;
|
||||
return;
|
||||
}
|
||||
// create() refused (screen reader, missing xterm internals): keep master's
|
||||
// soft-keyboard recovery rather than leaving iOS with neither.
|
||||
this._iosNativeInput = null;
|
||||
}
|
||||
try {
|
||||
this._keyCode229Recovery = window.CodemanKeyCode229Recovery?.create?.({
|
||||
textarea: this.terminal.textarea,
|
||||
emitRecovered: (data) => this._handleTerminalData(data, this.activeSessionId),
|
||||
getCompositionHelper: () => this.terminal?._core?._compositionHelper,
|
||||
isScreenReaderMode: () => this.terminal?.options?.screenReaderMode === true,
|
||||
});
|
||||
} catch {
|
||||
this._keyCode229Recovery = null;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -829,6 +834,9 @@ Object.assign(CodemanApp.prototype, {
|
||||
this._enqueueInput(sessionId, [{ write: text }, { gap: 80 }, { write: '\r' }]);
|
||||
} else {
|
||||
this._echoPassthroughSessions?.delete(sessionId);
|
||||
// The CR bypasses onData here, so tell the codex predictor about it as
|
||||
// typed Enter does (it clears the prediction run).
|
||||
this._predictHookOnData('\r');
|
||||
this._enqueueInput(sessionId, [{ write: '\r' }]);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user