need to fix this later
This commit is contained in:
parent
3120f8781d
commit
e7d30e7213
@ -87,9 +87,10 @@ 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) {
|
||||
let mut output_string: String = self.raw_func_str.clone();
|
||||
self.autocomplete.ui(ui, &mut output_string, i);
|
||||
self.autocomplete.update(&self.raw_func_str);
|
||||
self.autocomplete.ui(ui, i);
|
||||
|
||||
let output_string = self.autocomplete.string.clone();
|
||||
self.update_string(output_string.as_str());
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::misc::chars_take;
|
||||
|
||||
const HINTENUM_EMPTY: HintEnum = HintEnum::Single("x^2");
|
||||
pub const HINTENUM_EMPTY: HintEnum = HintEnum::Single("x^2");
|
||||
const HINTENUM_CLOSED_PARENS: HintEnum = HintEnum::Single(")");
|
||||
|
||||
/// Generate a hint based on the input `input`, returns an `Option<String>`
|
||||
@ -39,7 +39,7 @@ pub fn generate_hint<'a>(input: &str) -> &'a HintEnum<'a> {
|
||||
&HintEnum::None
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(PartialEq)]
|
||||
pub enum HintEnum<'a> {
|
||||
Single(&'a str),
|
||||
Many(&'a [&'a str]),
|
||||
|
||||
@ -16,30 +16,27 @@ pub struct AutoComplete<'a> {
|
||||
pub i: usize,
|
||||
pub hint: &'a HintEnum<'a>,
|
||||
pub string: String,
|
||||
pub first: bool,
|
||||
}
|
||||
|
||||
impl Default for Movement {
|
||||
fn default() -> Movement { Movement::None }
|
||||
fn default() -> Self { Self::None }
|
||||
}
|
||||
|
||||
impl<'a> Default for AutoComplete<'a> {
|
||||
fn default() -> AutoComplete<'a> {
|
||||
AutoComplete {
|
||||
i: 0,
|
||||
hint: &HintEnum::None,
|
||||
hint: &crate::suggestions::HINTENUM_EMPTY,
|
||||
string: String::new(),
|
||||
first: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AutoComplete<'a> {
|
||||
fn update(&mut self, string: &str) {
|
||||
if (&self.string != string) | self.first {
|
||||
pub fn update(&mut self, string: &str) {
|
||||
if &self.string != string {
|
||||
self.string = string.to_string();
|
||||
self.hint = generate_hint(string);
|
||||
self.first = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,12 +48,11 @@ impl<'a> AutoComplete<'a> {
|
||||
match self.hint {
|
||||
HintEnum::Many(hints) => {
|
||||
if movement == &Movement::Complete {
|
||||
println!("applying multicomplete");
|
||||
self.string += hints[self.i];
|
||||
return;
|
||||
}
|
||||
|
||||
// maximum i value
|
||||
// maximum index value
|
||||
let max_i = hints.len() - 1;
|
||||
|
||||
match movement {
|
||||
@ -83,13 +79,10 @@ impl<'a> AutoComplete<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, string: &mut String, func_i: i32) {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui, func_i: i32) {
|
||||
let mut movement: Movement = Movement::default();
|
||||
|
||||
// update self
|
||||
self.update(string);
|
||||
|
||||
let mut func_edit = egui::TextEdit::singleline(string)
|
||||
let mut func_edit = egui::TextEdit::singleline(&mut self.string)
|
||||
.hint_forward(true) // Make the hint appear after the last text in the textbox
|
||||
.lock_focus(true);
|
||||
|
||||
@ -166,7 +159,6 @@ impl<'a> AutoComplete<'a> {
|
||||
},
|
||||
})));
|
||||
TextEdit::store_state(ui.ctx(), te_id, state);
|
||||
*string = self.string.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user