find: show active match in orange (.dumber-find-active) and manage active class on selection changes; resets on clear
- commit
- 157c30c30e3e8d38340e9e4f6cabc8c97db39ca6
- author
- bamen · · 2025-09-09 19:22 UTC
- committer
- bamen · · 2025-09-09 19:36 UTC
- parent
- 8ab9109
- signature
- unsigned
1 file · +7 -1
M pkg/webkit/ucm_js_cgo.go +7 -1
| @@ -22,6 +22,7 @@ func getOmniboxScript() string { | |||
| 22 | 22 | suggestions: [], | |
| 23 | 23 | matches: [], // {el, context} | |
| 24 | 24 | selectedIndex: -1, | |
| 25 | + | activeIndex: -1, | |
| 25 | 26 | debounceTimer: 0, | |
| 26 | 27 | highlightNodes: [], | |
| 27 | 28 | faded: false, | |
| @@ -92,7 +93,7 @@ func getOmniboxScript() string { | |||
| 92 | 93 | const list = document.createElement('div'); | |
| 93 | 94 | list.style.cssText = 'margin-top:8px;max-height:50vh;overflow:auto;border-top:1px solid #333;'; | |
| 94 | 95 | const style = document.createElement('style'); | |
| 95 | - | style.textContent = '.dumber-find-highlight{background:#ffeb3b;color:#000;padding:0 1px;border-radius:2px;box-shadow:0 0 0 1px #c8b900 inset}'; | |
| 96 | + | style.textContent = '.dumber-find-highlight{background:#ffeb3b;color:#000;padding:0 1px;border-radius:2px;box-shadow:0 0 0 1px #c8b900 inset}.dumber-find-active{background:#ff9800 !important;color:#000;box-shadow:0 0 0 1px #b36b00 inset}'; | |
| 96 | 97 | document.documentElement.appendChild(style); | |
| 97 | 98 | box.appendChild(input); box.appendChild(list); root.appendChild(box); document.documentElement.appendChild(root); | |
| 98 | 99 | H.box = box; | |
| @@ -199,6 +200,7 @@ func getOmniboxScript() string { | |||
| 199 | 200 | H.highlightNodes = []; | |
| 200 | 201 | H.matches = []; | |
| 201 | 202 | H.selectedIndex = -1; | |
| 203 | + | H.activeIndex = -1; | |
| 202 | 204 | H.paintList(); | |
| 203 | 205 | }, | |
| 204 | 206 | find(q){ | |
| @@ -248,7 +250,11 @@ func getOmniboxScript() string { | |||
| 248 | 250 | H.revealSelection(); | |
| 249 | 251 | }, | |
| 250 | 252 | revealSelection(){ | |
| 253 | + | const prev = H.matches[H.activeIndex|0]; | |
| 254 | + | if (prev && prev.el && prev.el.classList) { prev.el.classList.remove('dumber-find-active'); } | |
| 251 | 255 | const m = H.matches[H.selectedIndex|0]; if (!m) return; | |
| 256 | + | if (m.el && m.el.classList) { m.el.classList.add('dumber-find-active'); } | |
| 257 | + | H.activeIndex = H.selectedIndex|0; | |
| 252 | 258 | try { m.el.scrollIntoView({block:'center', inline:'nearest'}); } catch(_){ m.el.scrollIntoView(); } | |
| 253 | 259 | }, | |
| 254 | 260 | jump(delta){ | |
| @@ -22,6 +22,7 @@ func getOmniboxScript() string { | |||||
| 22 | suggestions: [], | 22 | suggestions: [], | ||
| 23 | matches: [], // {el, context} | 23 | matches: [], // {el, context} | ||
| 24 | selectedIndex: -1, | 24 | selectedIndex: -1, | ||
| 25 | + | activeIndex: -1, | |||
| 25 | debounceTimer: 0, | 26 | debounceTimer: 0, | ||
| 26 | highlightNodes: [], | 27 | highlightNodes: [], | ||
| 27 | faded: false, | 28 | faded: false, | ||
| @@ -92,7 +93,7 @@ func getOmniboxScript() string { | |||||
| 92 | const list = document.createElement('div'); | 93 | const list = document.createElement('div'); | ||
| 93 | list.style.cssText = 'margin-top:8px;max-height:50vh;overflow:auto;border-top:1px solid #333;'; | 94 | list.style.cssText = 'margin-top:8px;max-height:50vh;overflow:auto;border-top:1px solid #333;'; | ||
| 94 | const style = document.createElement('style'); | 95 | const style = document.createElement('style'); | ||
| 95 | - | style.textContent = '.dumber-find-highlight{background:#ffeb3b;color:#000;padding:0 1px;border-radius:2px;box-shadow:0 0 0 1px #c8b900 inset}'; | 96 | + | style.textContent = '.dumber-find-highlight{background:#ffeb3b;color:#000;padding:0 1px;border-radius:2px;box-shadow:0 0 0 1px #c8b900 inset}.dumber-find-active{background:#ff9800 !important;color:#000;box-shadow:0 0 0 1px #b36b00 inset}'; |
| 96 | document.documentElement.appendChild(style); | 97 | document.documentElement.appendChild(style); | ||
| 97 | box.appendChild(input); box.appendChild(list); root.appendChild(box); document.documentElement.appendChild(root); | 98 | box.appendChild(input); box.appendChild(list); root.appendChild(box); document.documentElement.appendChild(root); | ||
| 98 | H.box = box; | 99 | H.box = box; | ||
| @@ -199,6 +200,7 @@ func getOmniboxScript() string { | |||||
| 199 | H.highlightNodes = []; | 200 | H.highlightNodes = []; | ||
| 200 | H.matches = []; | 201 | H.matches = []; | ||
| 201 | H.selectedIndex = -1; | 202 | H.selectedIndex = -1; | ||
| 203 | + | H.activeIndex = -1; | |||
| 202 | H.paintList(); | 204 | H.paintList(); | ||
| 203 | }, | 205 | }, | ||
| 204 | find(q){ | 206 | find(q){ | ||
| @@ -248,7 +250,11 @@ func getOmniboxScript() string { | |||||
| 248 | H.revealSelection(); | 250 | H.revealSelection(); | ||
| 249 | }, | 251 | }, | ||
| 250 | revealSelection(){ | 252 | revealSelection(){ | ||
| 253 | + | const prev = H.matches[H.activeIndex|0]; | |||
| 254 | + | if (prev && prev.el && prev.el.classList) { prev.el.classList.remove('dumber-find-active'); } | |||
| 251 | const m = H.matches[H.selectedIndex|0]; if (!m) return; | 255 | const m = H.matches[H.selectedIndex|0]; if (!m) return; | ||
| 256 | + | if (m.el && m.el.classList) { m.el.classList.add('dumber-find-active'); } | |||
| 257 | + | H.activeIndex = H.selectedIndex|0; | |||
| 252 | try { m.el.scrollIntoView({block:'center', inline:'nearest'}); } catch(_){ m.el.scrollIntoView(); } | 258 | try { m.el.scrollIntoView({block:'center', inline:'nearest'}); } catch(_){ m.el.scrollIntoView(); } | ||
| 253 | }, | 259 | }, | ||
| 254 | jump(delta){ | 260 | jump(delta){ | ||