seperate move_cursor_to_end
This commit is contained in:
parent
beed4b4fc9
commit
b06a9ca384
@ -8,16 +8,11 @@ use crate::widgets::{AutoComplete, Movement};
|
|||||||
use eframe::{egui, emath, epaint};
|
use eframe::{egui, emath, epaint};
|
||||||
use egui::{
|
use egui::{
|
||||||
plot::{BarChart, PlotUi, Value},
|
plot::{BarChart, PlotUi, Value},
|
||||||
text::CCursor,
|
|
||||||
text_edit::CursorRange,
|
|
||||||
widgets::plot::Bar,
|
widgets::plot::Bar,
|
||||||
Button, Checkbox, Context, Key, Modifiers, TextEdit,
|
Button, Checkbox, Context, Key, Modifiers,
|
||||||
};
|
};
|
||||||
use emath::{pos2, vec2};
|
use emath::{pos2, vec2};
|
||||||
use epaint::{
|
use epaint::Color32;
|
||||||
text::cursor::{Cursor, PCursor, RCursor},
|
|
||||||
Color32,
|
|
||||||
};
|
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::ops::BitXorAssign;
|
use std::ops::BitXorAssign;
|
||||||
|
|
||||||
@ -196,20 +191,7 @@ impl FunctionEntry {
|
|||||||
|
|
||||||
// Push cursor to end if needed
|
// Push cursor to end if needed
|
||||||
if movement == Movement::Complete {
|
if movement == Movement::Complete {
|
||||||
let mut state = TextEdit::load_state(ui.ctx(), te_id).unwrap();
|
crate::widgets::move_cursor_to_end(ui.ctx(), te_id);
|
||||||
state.set_cursor_range(Some(CursorRange::one(Cursor {
|
|
||||||
ccursor: CCursor {
|
|
||||||
index: 0,
|
|
||||||
prefer_next_row: false,
|
|
||||||
},
|
|
||||||
rcursor: RCursor { row: 0, column: 0 },
|
|
||||||
pcursor: PCursor {
|
|
||||||
paragraph: 0,
|
|
||||||
offset: 10000,
|
|
||||||
prefer_next_row: false,
|
|
||||||
},
|
|
||||||
})));
|
|
||||||
TextEdit::store_state(ui.ctx(), te_id, state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
use crate::suggestions::{generate_hint, Hint};
|
use crate::suggestions::{generate_hint, Hint};
|
||||||
|
|
||||||
|
use eframe::{egui, epaint};
|
||||||
|
use egui::{text::CCursor, text_edit::CursorRange, TextEdit};
|
||||||
|
use epaint::text::cursor::{Cursor, PCursor, RCursor};
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum Movement {
|
pub enum Movement {
|
||||||
Complete,
|
Complete,
|
||||||
@ -78,6 +82,24 @@ impl<'a> AutoComplete<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Moves cursor of TextEdit `te_id` to the end
|
||||||
|
pub fn move_cursor_to_end(ctx: &egui::Context, te_id: egui::Id) {
|
||||||
|
let mut state = TextEdit::load_state(ctx, te_id).unwrap();
|
||||||
|
state.set_cursor_range(Some(CursorRange::one(Cursor {
|
||||||
|
ccursor: CCursor {
|
||||||
|
index: 0,
|
||||||
|
prefer_next_row: false,
|
||||||
|
},
|
||||||
|
rcursor: RCursor { row: 0, column: 0 },
|
||||||
|
pcursor: PCursor {
|
||||||
|
paragraph: 0,
|
||||||
|
offset: 10000,
|
||||||
|
prefer_next_row: false,
|
||||||
|
},
|
||||||
|
})));
|
||||||
|
TextEdit::store_state(ctx, te_id, state);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod autocomplete_tests {
|
mod autocomplete_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user