seperate move_cursor_to_end

This commit is contained in:
Simon Gardling 2022-04-20 09:02:25 -04:00
parent beed4b4fc9
commit b06a9ca384
2 changed files with 25 additions and 21 deletions

View File

@ -8,16 +8,11 @@ use crate::widgets::{AutoComplete, Movement};
use eframe::{egui, emath, epaint};
use egui::{
plot::{BarChart, PlotUi, Value},
text::CCursor,
text_edit::CursorRange,
widgets::plot::Bar,
Button, Checkbox, Context, Key, Modifiers, TextEdit,
Button, Checkbox, Context, Key, Modifiers,
};
use emath::{pos2, vec2};
use epaint::{
text::cursor::{Cursor, PCursor, RCursor},
Color32,
};
use epaint::Color32;
use std::fmt::{self, Debug};
use std::ops::BitXorAssign;
@ -196,20 +191,7 @@ impl FunctionEntry {
// Push cursor to end if needed
if movement == Movement::Complete {
let mut state = TextEdit::load_state(ui.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(ui.ctx(), te_id, state);
crate::widgets::move_cursor_to_end(ui.ctx(), te_id);
}
}

View File

@ -1,5 +1,9 @@
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)]
pub enum Movement {
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)]
mod autocomplete_tests {
use super::*;