Implement Enter

This commit is contained in:
Jeremy Soller 2022-10-19 11:04:26 -06:00
parent ad6555e79f
commit 369c265646
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE

View file

@ -392,8 +392,28 @@ impl<'a> TextBuffer<'a> {
self.redraw = true; self.redraw = true;
self.shape_until_scroll(); self.shape_until_scroll();
}, },
TextAction::Insert(character) => { TextAction::Insert(character) => match character {
'\r' | '\n' => {
//TODO: handle Enter //TODO: handle Enter
let line = &self.layout_lines[self.cursor.line];
let new_line = if self.cursor.glyph >= line.glyphs.len() {
String::new()
} else {
let glyph = &line.glyphs[self.cursor.glyph];
self.text_lines[line.line_i.get()].split_off(glyph.start)
};
self.text_lines.insert(line.line_i.get() + 1, new_line);
// Reshape all lines after new line
//TODO: improve performance
self.shape_lines.truncate(line.line_i.get());
self.relayout();
self.shape_until_scroll();
self.cursor.glyph = 0;
self.cursor.line += 1;
},
_ => {
let line = &self.layout_lines[self.cursor.line]; let line = &self.layout_lines[self.cursor.line];
if self.cursor.glyph >= line.glyphs.len() { if self.cursor.glyph >= line.glyphs.len() {
match line.glyphs.last() { match line.glyphs.last() {
@ -417,6 +437,7 @@ impl<'a> TextBuffer<'a> {
self.cursor.glyph += 1; self.cursor.glyph += 1;
self.reshape_line(line.line_i); self.reshape_line(line.line_i);
} }
}
}, },
TextAction::Click { x, y } => { TextAction::Click { x, y } => {
self.select_opt = None; self.select_opt = None;