fix autocomplete menu
This commit is contained in:
parent
e056211671
commit
2fcc5c4372
@ -1,6 +1,6 @@
|
|||||||
use crate::suggestions::{generate_hint, HintEnum};
|
use crate::suggestions::{generate_hint, HintEnum};
|
||||||
use eframe::{egui, epaint};
|
use eframe::{egui, epaint};
|
||||||
use egui::{text::CCursor, text_edit::CursorRange, Key, Label, Modifiers, TextEdit, Widget};
|
use egui::{text::CCursor, text_edit::CursorRange, Key, Modifiers, TextEdit, Widget};
|
||||||
use epaint::text::cursor::{Cursor, PCursor, RCursor};
|
use epaint::text::cursor::{Cursor, PCursor, RCursor};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -72,12 +72,11 @@ impl<'a> AutoComplete<'a> {
|
|||||||
}
|
}
|
||||||
self.i = i as usize;
|
self.i = i as usize;
|
||||||
}
|
}
|
||||||
HintEnum::Single(hint) => match movement {
|
HintEnum::Single(hint) => {
|
||||||
Movement::Complete => {
|
if movement == &Movement::Complete {
|
||||||
*new_string += hint;
|
*new_string += hint;
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
},
|
|
||||||
HintEnum::None => {}
|
HintEnum::None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,6 +93,7 @@ impl<'a> AutoComplete<'a> {
|
|||||||
.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
|
||||||
.lock_focus(true);
|
.lock_focus(true);
|
||||||
|
|
||||||
|
let popup_id = ui.make_persistent_id("autocomplete_popup");
|
||||||
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));
|
||||||
|
|
||||||
if self.hint.is_none() {
|
if self.hint.is_none() {
|
||||||
@ -118,8 +118,6 @@ impl<'a> AutoComplete<'a> {
|
|||||||
|
|
||||||
let func_edit_focus = re.has_focus();
|
let func_edit_focus = re.has_focus();
|
||||||
|
|
||||||
// If in focus and right arrow key was pressed, apply hint
|
|
||||||
if func_edit_focus {
|
|
||||||
if ui.input().key_pressed(Key::ArrowDown) {
|
if ui.input().key_pressed(Key::ArrowDown) {
|
||||||
movement = Movement::Down;
|
movement = Movement::Down;
|
||||||
} else if ui.input().key_pressed(Key::ArrowUp) {
|
} else if ui.input().key_pressed(Key::ArrowUp) {
|
||||||
@ -135,37 +133,27 @@ impl<'a> AutoComplete<'a> {
|
|||||||
// TODO: fix clicking on labels (no clue why it doesn't work, time to take a walk)
|
// TODO: fix clicking on labels (no clue why it doesn't work, time to take a walk)
|
||||||
if movement != Movement::Complete && let HintEnum::Many(hints) = self.hint {
|
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
|
// Doesn't need to have a number in id as there should only be 1 autocomplete popup in the entire gui
|
||||||
let popup_id = ui.make_persistent_id("autocomplete_popup");
|
let mut clicked = false;
|
||||||
|
|
||||||
// let mut clicked = false;
|
|
||||||
|
|
||||||
egui::popup_below_widget(ui, popup_id, &re, |ui| {
|
egui::popup_below_widget(ui, popup_id, &re, |ui| {
|
||||||
hints.iter().enumerate().for_each(|(i, candidate)| {
|
hints.iter().enumerate().for_each(|(i, candidate)| {
|
||||||
/*
|
|
||||||
if ui.selectable_label(i == self.i, *candidate).clicked() {
|
if ui.selectable_label(i == self.i, *candidate).clicked() {
|
||||||
clicked = true;
|
clicked = true;
|
||||||
self.i = i;
|
self.i = i;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// placeholder for now
|
|
||||||
ui.add_enabled(i == self.i, Label::new(*candidate));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.memory().open_popup(popup_id)
|
|
||||||
/*
|
|
||||||
if clicked {
|
if clicked {
|
||||||
new_string += hints[self.i];
|
new_string += hints[self.i];
|
||||||
|
|
||||||
// don't need this here as it simply won't be display next frame in `math_app.rs`
|
// don't need this here as it simply won't be display next frame
|
||||||
// ui.memory().close_popup();
|
// ui.memory().close_popup();
|
||||||
|
|
||||||
movement = Movement::Complete;
|
movement = Movement::Complete;
|
||||||
} else {
|
} else {
|
||||||
ui.memory().open_popup(popup_id);
|
ui.memory().open_popup(popup_id);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push cursor to end if needed
|
// Push cursor to end if needed
|
||||||
@ -185,7 +173,6 @@ impl<'a> AutoComplete<'a> {
|
|||||||
})));
|
})));
|
||||||
TextEdit::store_state(ui.ctx(), te_id, state);
|
TextEdit::store_state(ui.ctx(), te_id, state);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
(new_string, func_edit_focus)
|
(new_string, func_edit_focus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user