Merge pull request #152 from bnema/fix/ghosttext-min-input
fix(omnibox): delay ghost text until input
1 file · +7 -0
M internal/ui/component/omnibox.go +7 -0
| @@ -30,6 +30,7 @@ const ( | |||
| 30 | 30 | defaultOmniboxPlaceholder = "Search history or enter URL… (! lists bangs)" | |
| 31 | 31 | ghostPositionRetryMs = 16 | |
| 32 | 32 | ghostPositionMaxAttempts = 5 | |
| 33 | + | minGhostInputLength = 1 | |
| 33 | 34 | ) | |
| 34 | 35 | ||
| 35 | 36 | // ViewMode distinguishes history search from favorites display. | |
| @@ -1084,6 +1085,7 @@ func (o *Omnibox) updateGhostFromSelectionWithInput(entryText string) { | |||
| 1084 | 1085 | idx := o.selectedIndex | |
| 1085 | 1086 | mode := o.viewMode | |
| 1086 | 1087 | bangMode := o.bangMode | |
| 1088 | + | hasNavigated := o.hasNavigated | |
| 1087 | 1089 | suggestions := o.suggestions | |
| 1088 | 1090 | favorites := o.favorites | |
| 1089 | 1091 | o.mu.RUnlock() | |
| @@ -1094,6 +1096,11 @@ func (o *Omnibox) updateGhostFromSelectionWithInput(entryText string) { | |||
| 1094 | 1096 | return | |
| 1095 | 1097 | } | |
| 1096 | 1098 | ||
| 1099 | + | if utf8.RuneCountInString(entryText) < minGhostInputLength && !hasNavigated { | |
| 1100 | + | o.clearGhostTextIfInput(entryText) | |
| 1101 | + | return | |
| 1102 | + | } | |
| 1103 | + | ||
| 1097 | 1104 | if entryText != "" { | |
| 1098 | 1105 | o.resolveGhostCompletion(entryText, mode, suggestions, favorites) | |
| 1099 | 1106 | return | |
| @@ -30,6 +30,7 @@ const ( | |||||
| 30 | defaultOmniboxPlaceholder = "Search history or enter URL… (! lists bangs)" | 30 | defaultOmniboxPlaceholder = "Search history or enter URL… (! lists bangs)" | ||
| 31 | ghostPositionRetryMs = 16 | 31 | ghostPositionRetryMs = 16 | ||
| 32 | ghostPositionMaxAttempts = 5 | 32 | ghostPositionMaxAttempts = 5 | ||
| 33 | + | minGhostInputLength = 1 | |||
| 33 | ) | 34 | ) | ||
| 34 | 35 | ||||
| 35 | // ViewMode distinguishes history search from favorites display. | 36 | // ViewMode distinguishes history search from favorites display. | ||
| @@ -1084,6 +1085,7 @@ func (o *Omnibox) updateGhostFromSelectionWithInput(entryText string) { | |||||
| 1084 | idx := o.selectedIndex | 1085 | idx := o.selectedIndex | ||
| 1085 | mode := o.viewMode | 1086 | mode := o.viewMode | ||
| 1086 | bangMode := o.bangMode | 1087 | bangMode := o.bangMode | ||
| 1088 | + | hasNavigated := o.hasNavigated | |||
| 1087 | suggestions := o.suggestions | 1089 | suggestions := o.suggestions | ||
| 1088 | favorites := o.favorites | 1090 | favorites := o.favorites | ||
| 1089 | o.mu.RUnlock() | 1091 | o.mu.RUnlock() | ||
| @@ -1094,6 +1096,11 @@ func (o *Omnibox) updateGhostFromSelectionWithInput(entryText string) { | |||||
| 1094 | return | 1096 | return | ||
| 1095 | } | 1097 | } | ||
| 1096 | 1098 | ||||
| 1099 | + | if utf8.RuneCountInString(entryText) < minGhostInputLength && !hasNavigated { | |||
| 1100 | + | o.clearGhostTextIfInput(entryText) | |||
| 1101 | + | return | |||
| 1102 | + | } | |||
| 1103 | + | ||||
| 1097 | if entryText != "" { | 1104 | if entryText != "" { | ||
| 1098 | o.resolveGhostCompletion(entryText, mode, suggestions, favorites) | 1105 | o.resolveGhostCompletion(entryText, mode, suggestions, favorites) | ||
| 1099 | return | 1106 | return | ||