@lethevimlet/sshift 1.3.7 → 1.3.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -59,6 +59,7 @@ class MobileTerminalHandler {
59
59
  this._compositionEndTs = 0;
60
60
  this._lastSentInput = '';
61
61
  this._lastSentInputTs = 0;
62
+ this._previousTextareaValue = '';
62
63
  this.contextMenuUserPositioned = false; // Track if user has manually positioned the menu
63
64
 
64
65
  // Configuration
@@ -463,46 +464,88 @@ class MobileTerminalHandler {
463
464
  });
464
465
 
465
466
  // Handle input events (for virtual keyboard)
467
+ // We let the textarea accumulate text so that Gboard autocorrect can
468
+ // operate on it (replacing a misspelled word with the correction).
469
+ // Diff tracking between beforeinput and input events computes the delta
470
+ // to send to the terminal, handling insertText, deleteContentBackward,
471
+ // and insertReplacementText (Gboard autocorrect) uniformly.
472
+ this.hiddenTextarea.addEventListener('beforeinput', (e) => {
473
+ if (e.isComposing) return;
474
+ if (this._isComposing) return;
475
+ if (e.inputType === 'insertCompositionText') return;
476
+ this._previousTextareaValue = this.hiddenTextarea.value;
477
+ });
478
+
466
479
  this.hiddenTextarea.addEventListener('input', (e) => {
467
480
  if (this.touchState.isSelecting) {
468
481
  e.preventDefault();
469
482
  this.hiddenTextarea.value = '';
483
+ this._previousTextareaValue = '';
470
484
  return;
471
485
  }
472
486
 
473
- // Skip composition-related input events - they are handled by compositionend.
474
- // e.isComposing is true when the event is part of an active composition.
475
- // e.inputType checks catch 'insertCompositionText' and 'insertReplacementText'
476
- // which some browsers fire instead of or alongside composition events.
477
487
  if (e.isComposing) {
478
488
  return;
479
489
  }
480
490
 
481
491
  if (this._isComposing) {
482
- this.hiddenTextarea.value = '';
483
492
  return;
484
493
  }
485
494
 
486
- if (e.inputType === 'insertCompositionText' || e.inputType === 'insertReplacementText') {
487
- this.hiddenTextarea.value = '';
495
+ if (e.inputType === 'insertCompositionText') {
488
496
  return;
489
497
  }
490
498
 
491
499
  // Guard against double-sending after compositionend.
492
- // On some browsers/IMEs, an input event fires right after compositionend
493
- // with the same text. We debounce this by tracking the last composition
494
- // end time and skipping input events that arrive within a short window.
495
500
  if (this._compositionEndTs && (Date.now() - this._compositionEndTs) < 300) {
496
- this.hiddenTextarea.value = '';
501
+ this.hiddenTextarea.value = this._previousTextareaValue;
502
+ this._previousTextareaValue = '';
503
+ return;
504
+ }
505
+
506
+ if (this.touchState.isDragging) {
507
+ this._previousTextareaValue = '';
497
508
  return;
498
509
  }
499
510
 
500
- if (e.data && !this.touchState.isDragging) {
501
- this._sendToTerminal(e.data);
502
- this._lastSentInput = e.data;
511
+ const prev = this._previousTextareaValue;
512
+ const curr = this.hiddenTextarea.value;
513
+
514
+ if (curr === prev) {
515
+ // No change, nothing to send.
516
+ } else if (curr.length > prev.length && curr.startsWith(prev)) {
517
+ // Simple append: previous text unchanged, new text appended.
518
+ this._sendToTerminal(curr.substring(prev.length));
519
+ this._lastSentInput = curr.substring(curr.length - 1);
520
+ this._lastSentInputTs = Date.now();
521
+ } else {
522
+ // Complex change (replacement, deletion, or mixed).
523
+ // Find common prefix and suffix to minimize the diff.
524
+ let prefixLen = 0;
525
+ while (prefixLen < prev.length && prefixLen < curr.length && prev[prefixLen] === curr[prefixLen]) {
526
+ prefixLen++;
527
+ }
528
+ let suffixLen = 0;
529
+ while (
530
+ suffixLen < (prev.length - prefixLen) &&
531
+ suffixLen < (curr.length - prefixLen) &&
532
+ prev[prev.length - 1 - suffixLen] === curr[curr.length - 1 - suffixLen]
533
+ ) {
534
+ suffixLen++;
535
+ }
536
+ const deletedCount = prev.length - prefixLen - suffixLen;
537
+ const inserted = curr.substring(prefixLen, curr.length - suffixLen);
538
+ if (deletedCount > 0) {
539
+ this._sendToTerminal('\x7f'.repeat(deletedCount));
540
+ }
541
+ if (inserted) {
542
+ this._sendToTerminal(inserted);
543
+ }
544
+ this._lastSentInput = inserted || '';
503
545
  this._lastSentInputTs = Date.now();
504
- this.hiddenTextarea.value = '';
505
546
  }
547
+
548
+ this._previousTextareaValue = '';
506
549
  });
507
550
 
508
551
  // Handle keydown for special keys
@@ -521,14 +564,20 @@ class MobileTerminalHandler {
521
564
  e.preventDefault();
522
565
  this._sendToTerminal('\r');
523
566
  this.hiddenTextarea.value = '';
567
+ this._previousTextareaValue = '';
524
568
  } else if (e.key === 'Backspace') {
525
- e.preventDefault();
526
- this._sendToTerminal('\x7f');
527
- this.hiddenTextarea.value = '';
569
+ // Let the browser handle backspace in the textarea; the beforeinput/input
570
+ // diff will detect the deletion and send \x7f to the terminal.
571
+ // Only prevent default if the textarea is empty (nothing to delete).
572
+ if (!this.hiddenTextarea.value) {
573
+ e.preventDefault();
574
+ this._sendToTerminal('\x7f');
575
+ }
528
576
  } else if (e.key === 'Tab') {
529
577
  e.preventDefault();
530
578
  this._sendToTerminal('\t');
531
579
  this.hiddenTextarea.value = '';
580
+ this._previousTextareaValue = '';
532
581
  }
533
582
  });
534
583
 
@@ -546,6 +595,7 @@ class MobileTerminalHandler {
546
595
  this.hiddenTextarea.addEventListener('compositionstart', () => {
547
596
  this._isComposing = true;
548
597
  this._compositionText = '';
598
+ this._previousTextareaValue = '';
549
599
  });
550
600
 
551
601
  this.hiddenTextarea.addEventListener('compositionupdate', (e) => {
@@ -577,7 +627,7 @@ class MobileTerminalHandler {
577
627
  this._compositionText = '';
578
628
  this._lastSentInput = '';
579
629
  this._lastSentInputTs = 0;
580
- this.hiddenTextarea.value = '';
630
+ this._previousTextareaValue = '';
581
631
  });
582
632
  }
583
633
 
@@ -1425,6 +1475,12 @@ class MobileTerminalHandler {
1425
1475
  if (this.hiddenTextarea) {
1426
1476
  // Remove readonly to allow keyboard
1427
1477
  this.hiddenTextarea.removeAttribute('readonly');
1478
+ // Reset textarea to empty when refocusing so the diff tracking
1479
+ // starts from a clean state. Gboard autocorrect operates on the
1480
+ // textarea content, so stale text from a previous focus would
1481
+ // produce incorrect diffs.
1482
+ this.hiddenTextarea.value = '';
1483
+ this._previousTextareaValue = '';
1428
1484
  this.hiddenTextarea.focus();
1429
1485
  }
1430
1486
  }