@agentsky/desktop-ui 0.4.236 → 0.4.238

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.
@@ -1568,6 +1568,18 @@ ${mXe}`:mXe,e.head.append(n),t.push(n.outerHTML),t}function mv(e){let t=e.body;f
1568
1568
  event.preventDefault();
1569
1569
  document.execCommand('insertText', false, event.clipboardData.getData('text/plain'));
1570
1570
  }, true);
1571
+ const caretAtPointer = (event, host) => {
1572
+ const selection = document.getSelection();
1573
+ if (!selection || event.detail > 1) return;
1574
+ let point = null;
1575
+ if (document.caretPositionFromPoint) {
1576
+ const position = document.caretPositionFromPoint(event.clientX, event.clientY);
1577
+ if (position) { point = document.createRange(); point.setStart(position.offsetNode, position.offset); point.collapse(true); }
1578
+ } else if (document.caretRangeFromPoint) point = document.caretRangeFromPoint(event.clientX, event.clientY);
1579
+ if (!point || !host.contains(point.startContainer)) return;
1580
+ selection.removeAllRanges();
1581
+ selection.addRange(point);
1582
+ };
1571
1583
  document.addEventListener('click', (event) => {
1572
1584
  if (commenting || event.target.closest('[data-artifact-chrome]')) return;
1573
1585
  const box = event.target.closest('input[type=checkbox][data-todo-id]');
@@ -1582,15 +1594,21 @@ ${mXe}`:mXe,e.head.append(n),t.push(n.outerHTML),t}function mv(e){let t=e.body;f
1582
1594
  if (element.closest('a,button,label,summary,details,input,select,textarea,option,video,audio')) event.preventDefault();
1583
1595
  const root = element.hasAttribute('data-artifact-text-node') ? null : richRoot(element);
1584
1596
  if (enabled && root) {
1597
+ const opening = document.activeElement !== root;
1585
1598
  activate(root);
1586
- if (document.activeElement !== root) root.focus();
1599
+ if (opening) { root.focus(); caretAtPointer(event, root); }
1587
1600
  select(root, root);
1588
1601
  return;
1589
1602
  }
1590
1603
  if (enabled && editable(element)) {
1604
+ // The press landed before the text was editable, so the browser placed
1605
+ // no caret; focus() alone would put it at the start. Put it where the
1606
+ // person clicked, as a second click would.
1607
+ const opening = document.activeElement !== element;
1591
1608
  element.setAttribute('data-artifact-inline', '');
1592
1609
  element.contentEditable = 'plaintext-only';
1593
1610
  element.focus();
1611
+ if (opening) caretAtPointer(event, element);
1594
1612
  } else event.preventDefault();
1595
1613
  const target = element.hasAttribute('data-artifact-text-node') ? element.parentElement : element;
1596
1614
  select(element, target);