fix(autocomplete): Sync last_filter en setText/clear + auto-cierre dropdown vacío
Cambios de Gemini para estabilidad IMGUI: - setText(): Sincroniza last_filter para evitar falsos text_changed - clear(): Resetea last_filter_len - autocompleteRect(): Cierra dropdown si options.len == 0 Parte de la solución para corrupción de memoria en cascade AutoComplete.
This commit is contained in:
parent
f077c87dfc
commit
fc2dc83e6c
1 changed files with 14 additions and 5 deletions
|
|
@ -59,6 +59,10 @@ pub const AutoCompleteState = struct {
|
|||
@memcpy(self.buffer[0..copy_len], new_text[0..copy_len]);
|
||||
self.len = copy_len;
|
||||
self.cursor = copy_len;
|
||||
|
||||
// Sync filter to avoid spurious text_changed events
|
||||
@memcpy(self.last_filter[0..copy_len], new_text[0..copy_len]);
|
||||
self.last_filter_len = copy_len;
|
||||
}
|
||||
|
||||
/// Clear the input
|
||||
|
|
@ -68,6 +72,7 @@ pub const AutoCompleteState = struct {
|
|||
self.selected = -1;
|
||||
self.highlighted = -1;
|
||||
self.open = false;
|
||||
self.last_filter_len = 0;
|
||||
}
|
||||
|
||||
/// Insert a single character at cursor
|
||||
|
|
@ -403,11 +408,15 @@ pub fn autocompleteRect(
|
|||
var filtered_indices: [256]usize = undefined;
|
||||
var filtered_count: usize = 0;
|
||||
|
||||
for (options, 0..) |opt, i| {
|
||||
if (filtered_count >= filtered_indices.len) break;
|
||||
if (matchesFilter(opt, filter_text, config.match_mode, config.case_sensitive)) {
|
||||
filtered_indices[filtered_count] = i;
|
||||
filtered_count += 1;
|
||||
if (options.len == 0) {
|
||||
state.closeDropdown();
|
||||
} else {
|
||||
for (options, 0..) |opt, i| {
|
||||
if (filtered_count >= filtered_indices.len) break;
|
||||
if (matchesFilter(opt, filter_text, config.match_mode, config.case_sensitive)) {
|
||||
filtered_indices[filtered_count] = i;
|
||||
filtered_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue