stuff for ime positioning
This commit is contained in:
@@ -126,26 +126,35 @@ impl<'a> TextEditCtx<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn replace(&mut self, len: usize, text: &str) {
|
||||
for _ in 0..len {
|
||||
self.delete();
|
||||
}
|
||||
self.insert_inner(text, false);
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, text: &str) {
|
||||
let mut lines = text.split('\n');
|
||||
let Some(first) = lines.next() else {
|
||||
return;
|
||||
};
|
||||
self.insert_inner(first);
|
||||
self.insert_inner(first, true);
|
||||
for line in lines {
|
||||
self.newline();
|
||||
self.insert_inner(line);
|
||||
self.insert_inner(line, true);
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_inner(&mut self, text: &str) {
|
||||
fn insert_inner(&mut self, text: &str, mov: bool) {
|
||||
if let Some(cursor) = &mut self.text.cursor {
|
||||
let line = &mut self.text.view.buf.lines[cursor.line];
|
||||
let mut line_text = line.text().to_string();
|
||||
line_text.insert_str(cursor.index, text);
|
||||
line.set_text(line_text, line.ending(), line.attrs_list().clone());
|
||||
for _ in 0..text.len() {
|
||||
self.motion(Motion::Right);
|
||||
if mov {
|
||||
for _ in 0..text.chars().count() {
|
||||
self.motion(Motion::Right);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user