Scroll if enter goes beyond end of screen

This commit is contained in:
Jeremy Soller 2022-10-19 11:12:34 -06:00
parent c29eed3a94
commit e1c670440a
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE

View file

@ -412,6 +412,7 @@ impl<'a> TextBuffer<'a> {
TextAction::Insert(character) => match character { TextAction::Insert(character) => match character {
'\r' | '\n' => { '\r' | '\n' => {
//TODO: handle Enter //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() {
String::new() String::new()
@ -426,9 +427,18 @@ impl<'a> TextBuffer<'a> {
self.shape_lines.truncate(line.line_i.get()); self.shape_lines.truncate(line.line_i.get());
self.relayout(); self.relayout();
self.shape_until_scroll(); self.shape_until_scroll();
}
self.cursor.glyph = 0; self.cursor.glyph = 0;
self.cursor.line += 1; self.cursor.line += 1;
let lines = self.lines();
if (self.cursor.line as i32) < self.scroll
|| (self.cursor.line as i32) >= self.scroll + lines
{
self.scroll = self.cursor.line as i32 - (lines - 1);
self.shape_until_scroll();
}
}, },
_ => { _ => {
let line = &self.layout_lines[self.cursor.line]; let line = &self.layout_lines[self.cursor.line];