Skip to content

The agent that grows with you

fix(desktop): a scroll that returns to its start does not open the keyboard

Tekniumbccf27cc4493
diff --git a/apps/desktop/src/app/chat/composer/touch-text-entry.test.tsx b/apps/desktop/src/app/chat/composer/touch-text-entry.test.tsx
index 3a179bcc7de..7aba7d8e66c 100644
--- a/apps/desktop/src/app/chat/composer/touch-text-entry.test.tsx
+++ b/apps/desktop/src/app/chat/composer/touch-text-entry.test.tsx
@@ -25,8 +25,13 @@ function Editor({ touch }: { touch: boolean }) {
const point = (x: number, y: number) => ({ clientX: x, clientY: y, identifier: 0 })
-function tap(editor: HTMLElement, from: [number, number], to: [number, number] = from) {
+function tap(editor: HTMLElement, from: [number, number], to: [number, number] = from, via?: [number, number]) {
fireEvent.touchStart(editor, { touches: [point(...from)], changedTouches: [point(...from)] })
+
+ if (via) {
+ fireEvent.touchMove(editor, { touches: [point(...via)], changedTouches: [point(...via)] })
+ }
+
fireEvent.touchEnd(editor, { touches: [], changedTouches: [point(...to)] })
}
@@ -38,8 +43,10 @@ describe('composer text entry on a touch host (#145166)', () => {
expect(editor.getAttribute('autocorrect')).toBe('on')
expect(editor.getAttribute('spellcheck')).toBe('true')
- // A swipe across the composer is a scroll, not a tap: focus stays put.
+ // A swipe across the composer is a scroll, not a tap, even one that
+ // comes back to where it started: focus stays put.
tap(editor, [10, 10], [10, 60])
+ tap(editor, [10, 10], [10, 11], [10, 80])
expect(editor.ownerDocument.activeElement).not.toBe(editor)
tap(editor, [10, 10], [12, 11])
diff --git a/apps/desktop/src/app/chat/composer/touch-text-entry.ts b/apps/desktop/src/app/chat/composer/touch-text-entry.ts
index 95579a4b12c..d7b24691bc0 100644
--- a/apps/desktop/src/app/chat/composer/touch-text-entry.ts
+++ b/apps/desktop/src/app/chat/composer/touch-text-entry.ts
@@ -19,6 +19,9 @@ export function composerTextEntryProps(touch: boolean) {
: ({ autoCapitalize: 'off', autoCorrect: isMacPlatform() ? 'on' : 'off', spellCheck: false } as const)
}
+const stillAt = (from: { x: number; y: number }, touch: { clientX: number; clientY: number }) =>
+ Math.hypot(touch.clientX - from.x, touch.clientY - from.y) <= TAP_MAX_MOVE_PX
+
function placeCaretAt(editor: HTMLElement, x: number, y: number) {
const range = document.caretRangeFromPoint?.(x, y)
const selection = window.getSelection()
@@ -50,15 +53,21 @@ export function touchTapFocusHandlers() {
return
}
- const still = Math.hypot(touch.clientX - began.x, touch.clientY - began.y) <= TAP_MAX_MOVE_PX
-
- if (!still || event.timeStamp - began.at > TAP_MAX_MS) {
+ if (!stillAt(began, touch) || event.timeStamp - began.at > TAP_MAX_MS) {
return
}
editor.focus()
placeCaretAt(editor, touch.clientX, touch.clientY)
},
+ // A scroll that comes back near its start before lifting is still a scroll.
+ onTouchMove(event: ReactTouchEvent<HTMLElement>) {
+ const touch = event.touches[0]
+
+ if (start && (!touch || !stillAt(start, touch))) {
+ start = null
+ }
+ },
onTouchStart(event: ReactTouchEvent<HTMLElement>) {
const touch = event.touches.length === 1 ? event.touches[0] : undefined
start = touch ? { at: event.timeStamp, x: touch.clientX, y: touch.clientY } : null