mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-01 00:49:33 +01:00
fix(web): synchronize iOS keyboard edits (#830)
Keep one native-input owner per iOS terminal and reconcile keyboard edits without duplicate producers. Preserve session-bound input ordering, local-echo Unicode deletion, and visual caret geometry. Cover device event sequences and lifecycle handoffs; remove obsolete helpers and source-text-only regression tests. Fixes #830
This commit is contained in:
1 parent
5548c17c4a
commit
c4b382b727
39 files changed
+5292
-824
No files matched your search
@@ -1071,19 +1071,16 @@ const VoiceInput = {
|
||||
return this._targetSessionId || app.activeSessionId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Send text to the dictation's own session. The active session keeps going
|
||||
* through app.sendInput() exactly as before; any other session goes straight
|
||||
* to the durable queue with the same useMux flag sendInput() passes.
|
||||
*/
|
||||
/** Send only to the captured dictation session, never the current tab. */
|
||||
_sendToTarget(target, text) {
|
||||
if (target === app.activeSessionId) return app.sendInput(text);
|
||||
// Closed while dictating: say so instead of queueing text for a session
|
||||
// that will only answer 404 (and never typing it into some other tab).
|
||||
if (app.sessions && !app.sessions.has(target)) {
|
||||
app.showToast?.('That session has closed; dictation not sent', 'warning');
|
||||
return Promise.resolve();
|
||||
}
|
||||
const pane = app._paneForSession?.(target);
|
||||
if (pane) app._prepareExternalInput?.(pane, 'voice-send', { flushEcho: true });
|
||||
app._sendInputAsync(target, text, { useMux: true });
|
||||
return Promise.resolve();
|
||||
},
|
||||
@@ -1113,7 +1110,13 @@ const VoiceInput = {
|
||||
// sees, so it goes straight to the session instead.
|
||||
const isActive = target === app.activeSessionId;
|
||||
const tilesOpen = !!app._tilesOwnTerminal?.();
|
||||
const pane = app._focusedPane?.();
|
||||
if (isActive && !tilesOpen && app._localEchoEnabled && app._localEchoOverlay) {
|
||||
// Focus may have moved to Pane B, but this overlay still belongs to A.
|
||||
const targetPane = pane?.isPrimary && pane.sessionId === target
|
||||
? pane
|
||||
: { isPrimary: true, tile: null, terminal: app.terminal, sessionId: target };
|
||||
app._prepareExternalInput?.(targetPane, 'voice-insert');
|
||||
app._localEchoOverlay.appendText(trimmed);
|
||||
} else {
|
||||
this._sendToTarget(target, trimmed).catch(() => {});
|
||||
@@ -1158,24 +1161,33 @@ const VoiceInput = {
|
||||
this._voiceSendHandler = () => {
|
||||
const target = this._targetSession();
|
||||
if (!target) return;
|
||||
const pane = app._focusedPane?.();
|
||||
const tilesOpen = !!app._tilesOwnTerminal?.();
|
||||
if (target === app.activeSessionId && !tilesOpen) {
|
||||
const targetPane = pane?.isPrimary && pane.sessionId === target
|
||||
? pane
|
||||
: { isPrimary: true, tile: null, terminal: app.terminal, sessionId: target };
|
||||
app._prepareExternalInput?.(targetPane, 'voice-submit');
|
||||
}
|
||||
// Simulate Enter key: if local echo is active, flush its buffer + send \r;
|
||||
// otherwise just send \r directly to the PTY. Both the overlay and the
|
||||
// predictions belong to the ACTIVE session's MAIN terminal, so a
|
||||
// dictation for another session, or for a tile while the grid has the
|
||||
// main terminal parked, just sends its Enter there.
|
||||
if (target !== app.activeSessionId || app._tilesOwnTerminal?.()) {
|
||||
if (target !== app.activeSessionId || tilesOpen) {
|
||||
this._sendToTarget(target, '\r').catch(() => {});
|
||||
} else if (app._localEchoEnabled && app._localEchoOverlay) {
|
||||
const text = app._localEchoOverlay.pendingText || '';
|
||||
app._localEchoOverlay.clear();
|
||||
app._localEchoOverlay.suppressBufferDetection();
|
||||
if (text) app.sendInput(text).catch(() => {});
|
||||
setTimeout(() => app.sendInput('\r').catch(() => {}), 80);
|
||||
const ops = text ? [{ write: text, useMux: true }, { gap: 80 }] : [];
|
||||
ops.push({ write: '\r', useMux: true });
|
||||
app._enqueueInput(target, ops);
|
||||
} else {
|
||||
// Predict-mode sessions (codex) take this branch: the send bypasses
|
||||
// onData, so clear outstanding predictions here (composer will reset)
|
||||
app._predictiveEcho?.clearPredictions();
|
||||
app.sendInput('\r').catch(() => {});
|
||||
app._sendInputAsync(target, '\r', { useMux: true });
|
||||
}
|
||||
// Blink then restore
|
||||
gear.classList.add('voice-send-blink');
|
||||
@@ -1202,6 +1214,7 @@ const VoiceInput = {
|
||||
|
||||
/** Show an editable compose overlay so the user can review/edit before sending */
|
||||
_showComposeOverlay(text) {
|
||||
const target = this._targetSession();
|
||||
document.querySelector('.voice-compose-overlay')?.remove();
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'voice-compose-overlay paste-overlay';
|
||||
@@ -1219,7 +1232,7 @@ const VoiceInput = {
|
||||
const send = () => {
|
||||
const val = textarea.value.trim();
|
||||
overlay.remove();
|
||||
if (val) this._sendToTarget(this._targetSession(), val + '\r').catch(() => {});
|
||||
if (val) this._sendToTarget(target, val + '\r').catch(() => {});
|
||||
};
|
||||
const cancel = () => overlay.remove();
|
||||
const newInput = () => {
|
||||
|
||||
Reference in new issue
Block a user