omnibox: close overlay when clicking outside the box (capture phase); stop propagation from box to avoid accidental closes
- commit
- d5a4bab0b78cd862d87467fd92c013ac3bf7ac09
- author
- bamen · · 2025-09-09 19:00 UTC
- committer
- bamen · · 2025-09-09 16:57 UTC
- parent
- 9de5dca
- signature
- unsigned
1 file · +10 -0
M pkg/webkit/ucm_js_cgo.go +10 -0
| @@ -92,6 +92,16 @@ func getOmniboxScript() string { | |||
| 92 | 92 | document.documentElement.appendChild(style); | |
| 93 | 93 | box.appendChild(input); box.appendChild(list); root.appendChild(box); document.documentElement.appendChild(root); | |
| 94 | 94 | H.box = box; | |
| 95 | + | // Click outside the box closes the overlay | |
| 96 | + | root.addEventListener('mousedown', (e)=>{ | |
| 97 | + | const tgt = e.target; | |
| 98 | + | if (tgt && box && !box.contains(tgt)) { | |
| 99 | + | e.preventDefault(); | |
| 100 | + | e.stopPropagation(); | |
| 101 | + | H.close(); | |
| 102 | + | } | |
| 103 | + | }, true); | |
| 104 | + | box.addEventListener('mousedown', (e)=>{ e.stopPropagation(); }, true); | |
| 95 | 105 | // Focus and select input on hover for quick typing | |
| 96 | 106 | input.addEventListener('mouseenter', ()=>{ if (H.visible) { try { input.focus({preventScroll:true}); input.select(); } catch(_) { input.focus(); } } }); | |
| 97 | 107 | root.addEventListener('mouseenter', ()=>{ if (H.visible) { try { input.focus({preventScroll:true}); } catch(_) { input.focus(); } } }); | |
| @@ -92,6 +92,16 @@ func getOmniboxScript() string { | |||||
| 92 | document.documentElement.appendChild(style); | 92 | document.documentElement.appendChild(style); | ||
| 93 | box.appendChild(input); box.appendChild(list); root.appendChild(box); document.documentElement.appendChild(root); | 93 | box.appendChild(input); box.appendChild(list); root.appendChild(box); document.documentElement.appendChild(root); | ||
| 94 | H.box = box; | 94 | H.box = box; | ||
| 95 | + | // Click outside the box closes the overlay | |||
| 96 | + | root.addEventListener('mousedown', (e)=>{ | |||
| 97 | + | const tgt = e.target; | |||
| 98 | + | if (tgt && box && !box.contains(tgt)) { | |||
| 99 | + | e.preventDefault(); | |||
| 100 | + | e.stopPropagation(); | |||
| 101 | + | H.close(); | |||
| 102 | + | } | |||
| 103 | + | }, true); | |||
| 104 | + | box.addEventListener('mousedown', (e)=>{ e.stopPropagation(); }, true); | |||
| 95 | // Focus and select input on hover for quick typing | 105 | // Focus and select input on hover for quick typing | ||
| 96 | input.addEventListener('mouseenter', ()=>{ if (H.visible) { try { input.focus({preventScroll:true}); input.select(); } catch(_) { input.focus(); } } }); | 106 | input.addEventListener('mouseenter', ()=>{ if (H.visible) { try { input.focus({preventScroll:true}); input.select(); } catch(_) { input.focus(); } } }); | ||
| 97 | root.addEventListener('mouseenter', ()=>{ if (H.visible) { try { input.focus({preventScroll:true}); } catch(_) { input.focus(); } } }); | 107 | root.addEventListener('mouseenter', ()=>{ if (H.visible) { try { input.focus({preventScroll:true}); } catch(_) { input.focus(); } } }); | ||