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]);
|
@memcpy(self.buffer[0..copy_len], new_text[0..copy_len]);
|
||||||
self.len = copy_len;
|
self.len = copy_len;
|
||||||
self.cursor = 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
|
/// Clear the input
|
||||||
|
|
@ -68,6 +72,7 @@ pub const AutoCompleteState = struct {
|
||||||
self.selected = -1;
|
self.selected = -1;
|
||||||
self.highlighted = -1;
|
self.highlighted = -1;
|
||||||
self.open = false;
|
self.open = false;
|
||||||
|
self.last_filter_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a single character at cursor
|
/// Insert a single character at cursor
|
||||||
|
|
@ -403,6 +408,9 @@ pub fn autocompleteRect(
|
||||||
var filtered_indices: [256]usize = undefined;
|
var filtered_indices: [256]usize = undefined;
|
||||||
var filtered_count: usize = 0;
|
var filtered_count: usize = 0;
|
||||||
|
|
||||||
|
if (options.len == 0) {
|
||||||
|
state.closeDropdown();
|
||||||
|
} else {
|
||||||
for (options, 0..) |opt, i| {
|
for (options, 0..) |opt, i| {
|
||||||
if (filtered_count >= filtered_indices.len) break;
|
if (filtered_count >= filtered_indices.len) break;
|
||||||
if (matchesFilter(opt, filter_text, config.match_mode, config.case_sensitive)) {
|
if (matchesFilter(opt, filter_text, config.match_mode, config.case_sensitive)) {
|
||||||
|
|
@ -410,6 +418,7 @@ pub fn autocompleteRect(
|
||||||
filtered_count += 1;
|
filtered_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle keyboard input when focused
|
// Handle keyboard input when focused
|
||||||
if (is_focused and !config.disabled) {
|
if (is_focused and !config.disabled) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue