@lethevimlet/sshift 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,11 @@ class MobileTerminalHandler {
59
59
  // terminal. All input diffing runs against this persistent baseline —
60
60
  // see _syncTextareaToTerminal().
61
61
  this._sentValue = '';
62
+ // Ring buffer of the last keyboard/IME events on the hidden textarea
63
+ // (Debug Info → "Copy Input Trace"). Gboard behaviour cannot be
64
+ // reproduced on a desktop; this is how device reports become
65
+ // actionable.
66
+ this._inputTrace = [];
62
67
  this.contextMenuUserPositioned = false; // Track if user has manually positioned the menu
63
68
 
64
69
  // Configuration
@@ -490,11 +495,11 @@ class MobileTerminalHandler {
490
495
  // empty snapshot, desyncing Gboard's own state from the textarea and
491
496
  // making it re-insert the full text on the next suggestion tap.
492
497
  this.hiddenTextarea.addEventListener('input', (e) => {
493
- if (this.touchState.isSelecting) {
494
- e.preventDefault();
495
- this._resetInputTracking();
496
- return;
497
- }
498
+ this._trace('input', {
499
+ inputType: e.inputType,
500
+ data: e.data,
501
+ composing: !!(e.isComposing || this._isComposing)
502
+ });
498
503
 
499
504
  // While a composition is in flight we don't send anything; the
500
505
  // textarea is synced once on compositionend. (Sending live
@@ -504,7 +509,7 @@ class MobileTerminalHandler {
504
509
  return;
505
510
  }
506
511
 
507
- if (this.touchState.isDragging) {
512
+ if (this.touchState.isDragging || this.selection.active) {
508
513
  return;
509
514
  }
510
515
 
@@ -513,7 +518,10 @@ class MobileTerminalHandler {
513
518
 
514
519
  // Handle keydown for special keys
515
520
  this.hiddenTextarea.addEventListener('keydown', (e) => {
516
- if (this.touchState.isSelecting) {
521
+ if (e.key === 'Enter' || e.key === 'Backspace' || e.key === 'Tab') {
522
+ this._trace('keydown', { key: e.key, composing: this._isComposing });
523
+ }
524
+ if (this.selection.active) {
517
525
  e.preventDefault();
518
526
  return;
519
527
  }
@@ -552,6 +560,7 @@ class MobileTerminalHandler {
552
560
 
553
561
  // Prevent focus when in selection mode or when selection is active
554
562
  this.hiddenTextarea.addEventListener('focus', (e) => {
563
+ this._trace('focus', {});
555
564
  if (this.touchState.isSelecting || this.selection.active) {
556
565
  e.preventDefault();
557
566
  this._intentionalBlur = true;
@@ -560,16 +569,74 @@ class MobileTerminalHandler {
560
569
  }
561
570
  });
562
571
 
572
+ // The blur tears down the IME session: a reset that had to wait for
573
+ // the field to lose focus (see _resetInputTracking) is applied now.
574
+ this.hiddenTextarea.addEventListener('blur', () => {
575
+ this._trace('blur', {});
576
+ this._isComposing = false;
577
+ if (this._pendingTrackingReset) {
578
+ this._resetInputTracking();
579
+ }
580
+ });
581
+
563
582
  // Composition events for IME/autocomplete handling
564
- this.hiddenTextarea.addEventListener('compositionstart', () => {
583
+ this.hiddenTextarea.addEventListener('compositionstart', (e) => {
584
+ this._trace('compositionstart', { data: e && e.data });
565
585
  this._isComposing = true;
566
586
  });
567
587
 
568
- this.hiddenTextarea.addEventListener('compositionend', () => {
588
+ this.hiddenTextarea.addEventListener('compositionend', (e) => {
589
+ this._trace('compositionend', { data: e && e.data });
569
590
  this._onCompositionEnd();
570
591
  });
571
592
  }
572
593
 
594
+ /**
595
+ * Record one keyboard/IME event (ring buffer, see Debug Info → Copy
596
+ * Input Trace). Values are trimmed so the trace stays small.
597
+ * @private
598
+ */
599
+ _trace(kind, extra) {
600
+ if (!this._inputTrace) this._inputTrace = [];
601
+ const ta = this.hiddenTextarea;
602
+ const value = ta && typeof ta.value === 'string' ? ta.value : '';
603
+ const entry = {
604
+ t: Date.now(),
605
+ kind,
606
+ len: value.length,
607
+ tail: value.length > 48 ? '…' + value.slice(-48) : value,
608
+ sel: ta && typeof ta.selectionStart === 'number' ? [ta.selectionStart, ta.selectionEnd] : undefined,
609
+ sentLen: this._sentValue ? this._sentValue.length : 0
610
+ };
611
+ if (typeof document !== 'undefined' && ta) {
612
+ entry.focused = document.activeElement === ta;
613
+ }
614
+ Object.keys(extra || {}).forEach(k => {
615
+ let v = extra[k];
616
+ if (typeof v === 'string' && v.length > 64) v = v.slice(0, 64) + '…';
617
+ if (v !== undefined) entry[k] = v;
618
+ });
619
+ this._inputTrace.push(entry);
620
+ if (this._inputTrace.length > 400) this._inputTrace.splice(0, this._inputTrace.length - 400);
621
+ }
622
+
623
+ /**
624
+ * @returns {Array} copy of the keyboard/IME event trace
625
+ */
626
+ getInputTrace() {
627
+ return (this._inputTrace || []).slice();
628
+ }
629
+
630
+ /**
631
+ * @returns {boolean} true while the hidden textarea owns focus (a live
632
+ * IME session may be tracking its content)
633
+ * @private
634
+ */
635
+ _isTextareaFocused() {
636
+ return typeof document !== 'undefined' && !!this.hiddenTextarea &&
637
+ document.activeElement === this.hiddenTextarea;
638
+ }
639
+
573
640
  /**
574
641
  * compositionend handler, extracted so the deferred-reset behaviour is
575
642
  * unit-testable without a DOM.
@@ -578,13 +645,13 @@ class MobileTerminalHandler {
578
645
  _onCompositionEnd() {
579
646
  this._isComposing = false;
580
647
  // A reset was requested while the composition was in flight
581
- // (e.g. Enter/Tab committed through the input path, or a selection
582
- // started mid-word): apply it now, discarding the composition
583
- // result, instead of having cleared the field under the IME.
648
+ // (e.g. a selection started mid-word): apply it now, discarding the
649
+ // composition result, instead of having cleared the field under the
650
+ // IME. If the field is still focused the reset stays deferred (until
651
+ // blur) and the composition result is synced like any other input.
584
652
  if (this._pendingTrackingReset) {
585
- this._pendingTrackingReset = false;
586
653
  this._resetInputTracking();
587
- return;
654
+ if (!this._pendingTrackingReset) return;
588
655
  }
589
656
  // Sync whatever the composition left in the textarea. Because the
590
657
  // diff runs against the persistent _sentValue baseline, this is
@@ -610,17 +677,26 @@ class MobileTerminalHandler {
610
677
  * mismatch on the next suggestion tap, and re-inserts text computed
611
678
  * from the stale model — the "autocomplete types repetitive text"
612
679
  * bug. When composing, defer the reset to compositionend instead.
680
+ *
681
+ * Focus guard (v1.8.1): the same applies to ANY clear while the
682
+ * textarea is focused — the IME session is alive and keeps its own
683
+ * model. So a reset is only ever applied when the field is not focused
684
+ * (after the blur in _collapseKeyboard, or from the blur listener);
685
+ * otherwise it is remembered and applied on the next blur.
613
686
  * @private
614
687
  */
615
688
  _resetInputTracking() {
616
- if (this._isComposing) {
689
+ if (this._isComposing || this._isTextareaFocused()) {
617
690
  this._pendingTrackingReset = true;
691
+ this._trace('reset-deferred', { composing: this._isComposing });
618
692
  return;
619
693
  }
694
+ this._pendingTrackingReset = false;
620
695
  if (this.hiddenTextarea) {
621
696
  this.hiddenTextarea.value = '';
622
697
  }
623
698
  this._sentValue = '';
699
+ this._trace('reset', {});
624
700
  }
625
701
 
626
702
  /**
@@ -681,6 +757,7 @@ class MobileTerminalHandler {
681
757
  insert = insert.replace(/\r\n/g, '\r').replace(/\n/g, '\r');
682
758
  }
683
759
 
760
+ this._trace('sync', { prefixLen, del: deleteCount, insert });
684
761
  if (deleteCount > 0) {
685
762
  this._sendToTerminal('\x7f'.repeat(deleteCount));
686
763
  }
@@ -832,9 +909,17 @@ class MobileTerminalHandler {
832
909
  // during long press detection. This will be reset in touchEnd if it's
833
910
  // a quick tap for text input.
834
911
  this.touchState.isSelecting = true;
835
-
836
- // Always prevent keyboard from appearing during touch interactions
837
- this._collapseKeyboard();
912
+
913
+ // Do NOT collapse the keyboard here. Until v1.8.0 every touchstart
914
+ // blurred AND cleared the hidden textarea and a quick tap re-focused
915
+ // it ~100 ms later. That is a programmatic clear under a live Gboard
916
+ // session (Chrome coalesces the blur/focus into one IME state update
917
+ // when they land close together, so Gboard never restarts its field
918
+ // model): the next suggestion tap then re-inserted text from the
919
+ // stale model — the "autocomplete repeats words" family. A tap on the
920
+ // terminal while typing is extremely common (dismissing a suggestion
921
+ // popup, repositioning). Long press, double tap, selection and drags
922
+ // collapse the keyboard themselves when they are detected.
838
923
 
839
924
  const touch = e.touches[0];
840
925
  const now = Date.now();
@@ -1589,6 +1674,7 @@ class MobileTerminalHandler {
1589
1674
  // autocomplete" regression). Force the caret to the end so typing
1590
1675
  // appends, matching both the diff and the remote prompt cursor.
1591
1676
  const len = this.hiddenTextarea.value.length;
1677
+ this._trace('focus-request', { from: document.activeElement ? document.activeElement.tagName : null });
1592
1678
  this.hiddenTextarea.focus();
1593
1679
  try { this.hiddenTextarea.setSelectionRange(len, len); } catch (_) {}
1594
1680
  this._keyboardCollapsed = false;
@@ -1605,6 +1691,7 @@ class MobileTerminalHandler {
1605
1691
  if (this._keyboardCollapsed) return;
1606
1692
  this._keyboardCollapsed = true;
1607
1693
  this._intentionalBlur = true;
1694
+ this._trace('collapse', {});
1608
1695
  this.hiddenTextarea.blur();
1609
1696
  // Restore readonly to prevent keyboard on any accidental focus
1610
1697
  this.hiddenTextarea.setAttribute('readonly', 'true');