Skip to content

Commit 073201f

Browse files
committed
fix: complete username autocomplete on tap, not just show it
Tapping an untouched or partially-typed username field now applies the suggestion immediately, the same way pressing Enter already did, instead of only showing the ghost-text hint. Two bugs were stacking here: find_suggestion() returns nothing for empty input (by design, to avoid hijacking typing as it's cleared), so a tap on a blank field never got the field's own suggestion to begin with. And get_suggestion_suffix() had the same empty-input guard, so even a suggestion set directly onto current-suggestion wouldn't have rendered — skipping 0 characters of the suggestion is just the whole suggestion, which is exactly right to show.
1 parent 2a46cda commit 073201f

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,13 @@ mod autocomplete_handler {
471471

472472
app.global::<AutocompleteHandler>()
473473
.on_get_suggestion_suffix(|typed, suggestion| {
474-
if suggestion.is_empty() || typed.is_empty() {
474+
if suggestion.is_empty() {
475475
return slint::SharedString::default();
476476
}
477477

478-
// Get the suffix after the typed text
478+
// Get the suffix after the typed text (if nothing's typed
479+
// yet — e.g. a tap-triggered suggestion — this is the whole
480+
// suggestion)
479481
let typed_len = typed.chars().count();
480482
let suffix: String = suggestion.chars().skip(typed_len).collect();
481483
slint::SharedString::from(suffix)

ui/autocomplete_line_edit.slint

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,19 @@ export component AutocompleteLineEdit inherits Rectangle {
7878
changed has-focus => {
7979
root.cursor-visible = true;
8080
if (root.has-focus) {
81-
root.refresh-suggestion();
81+
if (root.text == "" && root.suggestions.length > 0) {
82+
// find-suggestion() intentionally returns nothing for empty
83+
// input — that guard is for the typed-and-backspaced-to-empty
84+
// case, so it doesn't yank the cursor around mid-edit. A tap
85+
// on a still-untouched field should still offer a starting
86+
// point, so this bypasses it just for the focus-gained case.
87+
root.current-suggestion = root.suggestions[0];
88+
} else {
89+
root.refresh-suggestion();
90+
}
91+
// A tap completes the suggestion immediately, same as pressing
92+
// Enter — apply-autocomplete() is a no-op if there's none.
93+
root.apply-autocomplete();
8294
}
8395
AutocompleteHandler.return-key-active = root.has-focus && root.current-suggestion != "";
8496
}

0 commit comments

Comments
 (0)