fix(omnibox): navigate bang queries on Enter
- commit
- a934acc0274bc25fe9fc22cc11f31d0480bf729f
- author
- brice · · 2025-12-28 14:20 UTC
- parent
- 0515f15
- signature
- unsigned
1 file · +23 -15
M internal/ui/component/omnibox.go +23 -15
| @@ -1237,25 +1237,33 @@ func (o *Omnibox) navigateToSelected() { | |||
| 1237 | 1237 | o.mu.RUnlock() | |
| 1238 | 1238 | ||
| 1239 | 1239 | entryText := o.entry.GetText() | |
| 1240 | - | if shortcutKey, query, found := url.ParseBangShortcut(entryText); found { | |
| 1241 | - | resolvedKey := shortcutKey | |
| 1242 | - | for key := range o.shortcuts { | |
| 1243 | - | if strings.EqualFold(key, shortcutKey) { | |
| 1244 | - | resolvedKey = key | |
| 1245 | - | break | |
| 1246 | - | } | |
| 1247 | - | } | |
| 1248 | - | entryText = "!" + resolvedKey + " " + query | |
| 1249 | - | } | |
| 1250 | 1240 | ||
| 1251 | 1241 | if bangMode { | |
| 1252 | - | // If the user already typed a bang query ("!key something"), Enter should navigate. | |
| 1253 | - | if _, _, found := url.ParseBangShortcut(entryText); !found { | |
| 1254 | - | if idx >= 0 && idx < len(bangSuggestions) { | |
| 1255 | - | o.entry.SetText("!" + bangSuggestions[idx].Key + " ") | |
| 1256 | - | o.entry.SetPosition(-1) | |
| 1242 | + | // If user typed a full bang query, navigate using the bang URL. | |
| 1243 | + | if shortcutKey, query, found := url.ParseBangShortcut(entryText); found { | |
| 1244 | + | resolvedKey := shortcutKey | |
| 1245 | + | for key := range o.shortcuts { | |
| 1246 | + | if strings.EqualFold(key, shortcutKey) { | |
| 1247 | + | resolvedKey = key | |
| 1248 | + | break | |
| 1249 | + | } | |
| 1250 | + | } | |
| 1251 | + | targetURL := o.buildURL("!" + resolvedKey + " " + query) | |
| 1252 | + | if targetURL == "" { | |
| 1257 | 1253 | return | |
| 1258 | 1254 | } | |
| 1255 | + | o.Hide(o.ctx) | |
| 1256 | + | if o.onNavigate != nil { | |
| 1257 | + | o.onNavigate(targetURL) | |
| 1258 | + | } | |
| 1259 | + | return | |
| 1260 | + | } | |
| 1261 | + | ||
| 1262 | + | // Otherwise, Enter autocompletes the selected bang. | |
| 1263 | + | if idx >= 0 && idx < len(bangSuggestions) { | |
| 1264 | + | o.entry.SetText("!" + bangSuggestions[idx].Key + " ") | |
| 1265 | + | o.entry.SetPosition(-1) | |
| 1266 | + | return | |
| 1259 | 1267 | } | |
| 1260 | 1268 | } | |
| 1261 | 1269 | ||
| @@ -1237,25 +1237,33 @@ func (o *Omnibox) navigateToSelected() { | |||||
| 1237 | o.mu.RUnlock() | 1237 | o.mu.RUnlock() | ||
| 1238 | 1238 | ||||
| 1239 | entryText := o.entry.GetText() | 1239 | entryText := o.entry.GetText() | ||
| 1240 | - | if shortcutKey, query, found := url.ParseBangShortcut(entryText); found { | |||
| 1241 | - | resolvedKey := shortcutKey | |||
| 1242 | - | for key := range o.shortcuts { | |||
| 1243 | - | if strings.EqualFold(key, shortcutKey) { | |||
| 1244 | - | resolvedKey = key | |||
| 1245 | - | break | |||
| 1246 | - | } | |||
| 1247 | - | } | |||
| 1248 | - | entryText = "!" + resolvedKey + " " + query | |||
| 1249 | - | } | |||
| 1250 | 1240 | ||||
| 1251 | if bangMode { | 1241 | if bangMode { | ||
| 1252 | - | // If the user already typed a bang query ("!key something"), Enter should navigate. | 1242 | + | // If user typed a full bang query, navigate using the bang URL. |
| 1253 | - | if _, _, found := url.ParseBangShortcut(entryText); !found { | 1243 | + | if shortcutKey, query, found := url.ParseBangShortcut(entryText); found { |
| 1254 | - | if idx >= 0 && idx < len(bangSuggestions) { | 1244 | + | resolvedKey := shortcutKey |
| 1255 | - | o.entry.SetText("!" + bangSuggestions[idx].Key + " ") | 1245 | + | for key := range o.shortcuts { |
| 1256 | - | o.entry.SetPosition(-1) | 1246 | + | if strings.EqualFold(key, shortcutKey) { |
| 1247 | + | resolvedKey = key | |||
| 1248 | + | break | |||
| 1249 | + | } | |||
| 1250 | + | } | |||
| 1251 | + | targetURL := o.buildURL("!" + resolvedKey + " " + query) | |||
| 1252 | + | if targetURL == "" { | |||
| 1257 | return | 1253 | return | ||
| 1258 | } | 1254 | } | ||
| 1255 | + | o.Hide(o.ctx) | |||
| 1256 | + | if o.onNavigate != nil { | |||
| 1257 | + | o.onNavigate(targetURL) | |||
| 1258 | + | } | |||
| 1259 | + | return | |||
| 1260 | + | } | |||
| 1261 | + | ||||
| 1262 | + | // Otherwise, Enter autocompletes the selected bang. | |||
| 1263 | + | if idx >= 0 && idx < len(bangSuggestions) { | |||
| 1264 | + | o.entry.SetText("!" + bangSuggestions[idx].Key + " ") | |||
| 1265 | + | o.entry.SetPosition(-1) | |||
| 1266 | + | return | |||
| 1259 | } | 1267 | } | ||
| 1260 | } | 1268 | } | ||
| 1261 | 1269 | ||||