Clean up text insertion
This commit is contained in:
parent
e1c670440a
commit
07a832efd4
1 changed files with 10 additions and 20 deletions
|
|
@ -411,7 +411,6 @@ impl<'a> TextBuffer<'a> {
|
||||||
},
|
},
|
||||||
TextAction::Insert(character) => match character {
|
TextAction::Insert(character) => match character {
|
||||||
'\r' | '\n' => {
|
'\r' | '\n' => {
|
||||||
//TODO: handle Enter
|
|
||||||
{
|
{
|
||||||
let line = &self.layout_lines[self.cursor.line];
|
let line = &self.layout_lines[self.cursor.line];
|
||||||
let new_line = if self.cursor.glyph >= line.glyphs.len() {
|
let new_line = if self.cursor.glyph >= line.glyphs.len() {
|
||||||
|
|
@ -442,28 +441,19 @@ impl<'a> TextBuffer<'a> {
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let line = &self.layout_lines[self.cursor.line];
|
let line = &self.layout_lines[self.cursor.line];
|
||||||
if self.cursor.glyph >= line.glyphs.len() {
|
let insert_i = if self.cursor.glyph >= line.glyphs.len() {
|
||||||
match line.glyphs.last() {
|
match line.glyphs.last() {
|
||||||
Some(glyph) => {
|
Some(glyph) => glyph.end,
|
||||||
let text_line = &mut self.text_lines[line.line_i.get()];
|
None => self.text_lines[line.line_i.get()].len()
|
||||||
text_line.insert(glyph.end, character);
|
|
||||||
self.cursor.glyph += 1;
|
|
||||||
self.reshape_line(line.line_i);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let text_line = &mut self.text_lines[line.line_i.get()];
|
|
||||||
text_line.push(character);
|
|
||||||
self.cursor.glyph += 1;
|
|
||||||
self.reshape_line(line.line_i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let glyph = &line.glyphs[self.cursor.glyph];
|
line.glyphs[self.cursor.glyph].start
|
||||||
let text_line = &mut self.text_lines[line.line_i.get()];
|
};
|
||||||
text_line.insert(glyph.start, character);
|
|
||||||
self.cursor.glyph += 1;
|
let text_line = &mut self.text_lines[line.line_i.get()];
|
||||||
self.reshape_line(line.line_i);
|
text_line.insert(insert_i, character);
|
||||||
}
|
self.cursor.glyph += 1;
|
||||||
|
self.reshape_line(line.line_i);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TextAction::Click { x, y } => {
|
TextAction::Click { x, y } => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue