Skip to content

The agent that grows with you

fix(desktop): a two-finger gesture no longer focuses the Webapp composer

Teknium6f43cc98dfdf
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 7aba7d8e66c..345f94ef09d 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
@@ -53,6 +53,27 @@ describe('composer text entry on a touch host (#145166)', () => {
expect(editor.ownerDocument.activeElement).toBe(editor)
})
+ it('a two-finger gesture that starts in the editor does not focus it', () => {
+ const editor = render(<Editor touch />).getByTestId('editor')
+ const first = point(10, 10)
+ const second = { clientX: 200, clientY: 200, identifier: 1 }
+
+ // The second finger lands outside the editor, so only the first finger's
+ // events reach it; they still list every finger on the screen.
+ fireEvent.touchStart(editor, { touches: [first], changedTouches: [first] })
+ fireEvent.touchMove(editor, { touches: [point(12, 11), second], changedTouches: [point(12, 11)] })
+ fireEvent.touchEnd(editor, { touches: [second], changedTouches: [point(12, 11)] })
+ expect(editor.ownerDocument.activeElement).not.toBe(editor)
+
+ // Lifting the first finger with the second still down, without a move.
+ fireEvent.touchStart(editor, { touches: [first], changedTouches: [first] })
+ fireEvent.touchEnd(editor, { touches: [second], changedTouches: [first] })
+ expect(editor.ownerDocument.activeElement).not.toBe(editor)
+
+ tap(editor, [10, 10])
+ expect(editor.ownerDocument.activeElement).toBe(editor)
+ })
+
it('desktop keeps the attributes off and leaves taps to the browser', () => {
const editor = render(<Editor touch={false} />).getByTestId('editor')
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 d7b24691bc0..017bcb7e62e 100644
--- a/apps/desktop/src/app/chat/composer/touch-text-entry.ts
+++ b/apps/desktop/src/app/chat/composer/touch-text-entry.ts
@@ -49,7 +49,14 @@ export function touchTapFocusHandlers() {
const began = start
start = null
- if (!began || !touch || editor.getAttribute('contenteditable') === 'false' || document.activeElement === editor) {
+ // Another finger still down makes this a pinch or a two-finger gesture.
+ if (
+ !began ||
+ !touch ||
+ event.touches.length > 0 ||
+ editor.getAttribute('contenteditable') === 'false' ||
+ document.activeElement === editor
+ ) {
return
}
@@ -61,8 +68,10 @@ export function touchTapFocusHandlers() {
placeCaretAt(editor, touch.clientX, touch.clientY)
},
// A scroll that comes back near its start before lifting is still a scroll.
+ // A second finger landing outside the editor never fires touchstart here,
+ // but every touchmove lists it.
onTouchMove(event: ReactTouchEvent<HTMLElement>) {
- const touch = event.touches[0]
+ const touch = event.touches.length === 1 ? event.touches[0] : undefined
if (start && (!touch || !stillAt(start, touch))) {
start = null