This commit is contained in:
Simon Gardling 2022-04-08 09:21:10 -04:00
parent 82263b8ea7
commit 2eda085fda
2 changed files with 8 additions and 11 deletions

View File

@ -87,7 +87,8 @@ impl Default for FunctionEntry {
impl FunctionEntry {
/// Create autocomplete ui and handle user input
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, Option<String>) {
let output_string = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
let mut output_string: String = self.raw_func_str.clone();
self.autocomplete.ui(ui, &mut output_string, i);
let changed = output_string != self.raw_func_str;
if changed {

View File

@ -83,15 +83,13 @@ impl<'a> AutoComplete<'a> {
}
}
pub fn ui(&mut self, ui: &mut egui::Ui, string: String, func_i: i32) -> String {
let mut new_string = string.clone();
pub fn ui(&mut self, ui: &mut egui::Ui, string: &mut String, func_i: i32) {
let mut movement: Movement = Movement::None;
// update self
self.changed(&string);
self.changed(string);
let mut func_edit = egui::TextEdit::singleline(&mut new_string)
let mut func_edit = egui::TextEdit::singleline(string)
.hint_forward(true) // Make the hint appear after the last text in the textbox
.lock_focus(true);
@ -100,8 +98,7 @@ impl<'a> AutoComplete<'a> {
if self.hint.is_none() {
let _ = func_edit.id(te_id).ui(ui);
let return_string = (&new_string).to_string();
return return_string;
return;
}
// Put here so these key presses don't interact with other elements
@ -124,7 +121,7 @@ impl<'a> AutoComplete<'a> {
movement = Movement::Up;
}
self.interact_back(&mut new_string, &movement);
self.interact_back(string, &movement);
if movement != Movement::Complete && let HintEnum::Many(hints) = self.hint {
// Doesn't need to have a number in id as there should only be 1 autocomplete popup in the entire gui
@ -140,7 +137,7 @@ impl<'a> AutoComplete<'a> {
});
if clicked {
new_string += hints[self.i];
*string += hints[self.i];
// don't need this here as it simply won't be display next frame
// ui.memory().close_popup();
@ -168,7 +165,6 @@ impl<'a> AutoComplete<'a> {
})));
TextEdit::store_state(ui.ctx(), te_id, state);
}
new_string
}
}