fix(ask-dewee): hide floating selection button after outside click

Aperta
#31 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

Start in src/ask/selection-button.ts, in mountAskButton(), where the mousedown hide, the mouseup handler that calls later() and setTimeout(show, 0), and dispose() are. Reproduce the outside-click case in Chrome first, since the issue says the root cause is unconfirmed. Extend tests/unit/ask/selection-button.test.ts with the outside-click and race sequences from the checklist. Done when the tooltip stays hidden after an outside click, reappears only on a new selection gesture, and the regression checklist passes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Bug report

Người dùng chọn một đoạn text trên trang → tooltip/button "Ask Dewee" xuất hiện đúng. Khi click chuột ra ngoài để bỏ selection, tooltip đôi lúc không biến mất (hoặc biến mất rồi hiện lại), che nội dung trang. Cần đảm bảo biến mất khi selection bị huỷ hoặc người dùng dismiss bằng outside click.

Code audit (main @ 1296da790de7)

  • src/ask/selection-button.ts trong mountAskButton():
    • capture listener mousedown → onDown() → hide() đã có.
    • listener mouseup → later() → setTimeout(show, 0) kiểm tra selectedText() và có thể hiển thị lại khi Chrome vẫn giữ selection range sau outside click, hoặc khi timeout cũ chạy muộn.
    • selectionchange chưa được lắng nghe; later() timers không có cancel/generation token, dispose() cũng không huỷ pending timeout.
  • tests/unit/ask/selection-button.test.ts chỉ test Escape + removeAllRanges() rồi mouseup; thiếu outside-click sequence + race regression. Đây là nghi vấn nguyên nhân từ code, cần xác nhận trên Chrome thực tế, chưa kết luận duy nhất root cause.

Expected behavior

  1. Khi người dùng tạo selection hợp lệ bằng chuột/bàn phím, Ask Dewee xuất hiện cạnh vùng chọn.
  2. Khi click hoặc tap/pointerdown ngoài tooltip để dismiss/bỏ text selection, tooltip biến mất và không tự hiện lại trong chính gesture đó, kể cả selection DOM tạm vẫn còn non-collapsed.
  3. Khi selection bị clear/collapse (selectionchange), Escape, scroll, tab navigation, hoặc unmount, tooltip biến mất.
  4. Chỉ xuất hiện lại khi có selection gesture mới; hỗ trợ drag-to-select tiếp theo, không làm mất trải nghiệm chọn văn bản; click chính tooltip phải giữ selected text và gửi draft một lần như hiện tại.
  5. Không tạo ask.selection message từ click ngoài, không capture input/textarea/contenteditable, không tự gửi text hay làm thay đổi site selection ngoài nhu cầu UX.

Suggested fix (implementation choice to verify)

  • Track pointer/selection gesture state (e.g. outside pointerdown dismisses and suppresses its matching pointerup/mouseup) + fresh-selection version/generation; chỉ show() sau selection mới thực sự phù hợp. Xử lý keyboard selection riêng.
  • Subscribe selectionchange to hide on collapsed/empty; guard debounce and suppression against browser order of events (pointerdown → mousedown → selectionchange → mouseup).
  • Make pending timers cancellable/generation-aware, cancel at hide/dispose/navigation. Avoid race that reopens tooltip after outside click; tests cover legacy mouse and pointer/touch.
  • Keep Shadow DOM event path checks + trusted click guard.

Regression tests

  • Select text → tooltip visible; outside mousedown/mouseup with selection still non-collapsed → remains hidden.
  • Select → outside click clears ranges → hidden.
  • New drag-selection after dismissal → visible again.
  • Select via Shift+arrows/keyboard → visible; Escape hides.
  • Press Ask Dewee → sends exactly one selected-text draft; no double show.
  • Rapid repeat clicks, scroll, selection changes, dispose with pending timer → never re-show.
  • Sensitive editable form elements excluded.

Related

Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
2g 5h
PR unite (30g)
4

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nextlevelbuilder/dewee-chrome-ext

Tutte le issue di nextlevelbuilder/dewee-chrome-ext

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.