@neuroplastio/xterm-addon-hotty 0.1.0-next.4 → 0.1.0-next.5

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.
@@ -1384,6 +1384,9 @@ var Surface = class {
1384
1384
  /** The document's base URL (SPEC §7.3). */
1385
1385
  base = NO_BASE;
1386
1386
  keyboard = false;
1387
+ /** The element the program knows has focus: the last `focus` named it,
1388
+ * or the program's `a=focus` gave it (SPEC §10.1). */
1389
+ told = null;
1387
1390
  /** Detached (SPEC §5.5): nothing in the surface reaches the program. */
1388
1391
  detachedState = false;
1389
1392
  /** A press is on something that takes no focus (SPEC §10.1): the focus
@@ -1560,6 +1563,7 @@ var Surface = class {
1560
1563
  this.dropDrag();
1561
1564
  const had = this.keyboard || this.frameFocused();
1562
1565
  this.keyboard = false;
1566
+ this.told = null;
1563
1567
  this.focusedControl()?.blur();
1564
1568
  if (had) this.giveBack();
1565
1569
  }
@@ -1751,17 +1755,21 @@ var Surface = class {
1751
1755
  if (target && !el) throw new Error(target);
1752
1756
  this.programFocus = true;
1753
1757
  try {
1754
- this.frame.focus();
1755
- this.frame.contentWindow?.focus();
1758
+ if (!this.frameFocused()) {
1759
+ this.frame.focus();
1760
+ this.frame.contentWindow?.focus();
1761
+ }
1756
1762
  if (el) el.focus();
1757
1763
  else if (!this.focusedControl()) this.tabbable()[0]?.focus();
1758
1764
  this.keyboard = true;
1765
+ this.told = this.focusedControl();
1759
1766
  } finally {
1760
1767
  setTimeout(() => this.programFocus = false, 0);
1761
1768
  }
1762
1769
  }
1763
1770
  /** `a=blur`, or the keyboard leaving: the edited control commits first. */
1764
1771
  blur() {
1772
+ this.pressed = null;
1765
1773
  this.commit();
1766
1774
  if (this.keyboard) this.giveBack();
1767
1775
  }
@@ -1812,6 +1820,7 @@ var Surface = class {
1812
1820
  if (this.keyboard) {
1813
1821
  this.commit();
1814
1822
  this.keyboard = false;
1823
+ this.told = null;
1815
1824
  this.emit("blur", "");
1816
1825
  }
1817
1826
  this.settle();
@@ -1839,16 +1848,24 @@ var Surface = class {
1839
1848
  }
1840
1849
  /** An element got focus: the surface takes the keyboard if the element is
1841
1850
  * one that takes focus, and the focus is neither the program's (no echo)
1842
- * nor a detached surface's. */
1851
+ * nor a detached surface's. The program hears where the user put focus,
1852
+ * each time it is another element than the one it knows (SPEC §10.1). */
1843
1853
  onFocusIn(e) {
1844
- if (this.programFocus || this.auxPress) return;
1845
- if (this.detachedState || this.pressNothing || !isElement(e.target) || !takesFocus(e.target, this.hyper)) {
1854
+ const el = isElement(e.target) ? e.target : null;
1855
+ if (this.programFocus) {
1856
+ this.told = el;
1857
+ return;
1858
+ }
1859
+ if (this.auxPress) return;
1860
+ if (this.detachedState || this.pressNothing || !el || !takesFocus(el, this.hyper)) {
1846
1861
  this.settle();
1847
1862
  return;
1848
1863
  }
1849
- if (this.keyboard) return;
1864
+ const gained = !this.keyboard;
1850
1865
  this.keyboard = true;
1851
- this.emit("focus", "");
1866
+ if (!gained && el === this.told) return;
1867
+ this.told = el;
1868
+ this.emit("focus", el.closest('[id]:not([id=""])')?.id ?? "");
1852
1869
  }
1853
1870
  tabbable() {
1854
1871
  const all = this.doc.querySelectorAll(
@@ -2712,6 +2729,7 @@ var Surface = class {
2712
2729
  this.commit();
2713
2730
  if (this.keyboard) {
2714
2731
  this.keyboard = false;
2732
+ this.told = null;
2715
2733
  this.emit("blur", "");
2716
2734
  }
2717
2735
  });