borrow string here
This commit is contained in:
parent
6efeba38dd
commit
3aee254de2
@ -1,7 +1,7 @@
|
|||||||
use crate::misc::chars_take;
|
use crate::misc::chars_take;
|
||||||
|
|
||||||
/// Generate a hint based on the input `input`, returns an `Option<String>`
|
/// Generate a hint based on the input `input`, returns an `Option<String>`
|
||||||
pub fn generate_hint(input: String) -> HintEnum<'static> {
|
pub fn generate_hint(input: &str) -> HintEnum<'static> {
|
||||||
if input.is_empty() {
|
if input.is_empty() {
|
||||||
return HintEnum::Single("x^2");
|
return HintEnum::Single("x^2");
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ mod tests {
|
|||||||
|
|
||||||
for (key, value) in values {
|
for (key, value) in values {
|
||||||
println!("{} + {:?}", key, value);
|
println!("{} + {:?}", key, value);
|
||||||
assert_eq!(generate_hint(key.to_string()), value);
|
assert_eq!(generate_hint(key), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,10 @@ impl Default for AutoComplete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AutoComplete {
|
impl AutoComplete {
|
||||||
fn changed(&mut self, string: String) {
|
fn changed(&mut self, string: &str) {
|
||||||
if self.func_str != Some(string.clone()) {
|
if self.func_str != Some(string.to_string()) {
|
||||||
self.changed = true;
|
self.changed = true;
|
||||||
self.func_str = Some(string.clone());
|
self.func_str = Some(string.to_string());
|
||||||
self.hint = generate_hint(string);
|
self.hint = generate_hint(string);
|
||||||
} else {
|
} else {
|
||||||
self.changed = false;
|
self.changed = false;
|
||||||
@ -42,7 +42,7 @@ impl AutoComplete {
|
|||||||
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", func_i));
|
let te_id = ui.make_persistent_id(format!("text_edit_ac_{}", func_i));
|
||||||
|
|
||||||
// update self
|
// update self
|
||||||
self.changed(string.clone());
|
self.changed(&string);
|
||||||
|
|
||||||
let mut func_edit = egui::TextEdit::singleline(&mut new_string)
|
let mut func_edit = egui::TextEdit::singleline(&mut new_string)
|
||||||
.hint_forward(true) // Make the hint appear after the last text in the textbox
|
.hint_forward(true) // Make the hint appear after the last text in the textbox
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user