Scroll if enter goes beyond end of screen
This commit is contained in:
parent
c29eed3a94
commit
e1c670440a
1 changed files with 23 additions and 13 deletions
|
|
@ -412,23 +412,33 @@ 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 new_line = if self.cursor.glyph >= line.glyphs.len() {
|
let line = &self.layout_lines[self.cursor.line];
|
||||||
String::new()
|
let new_line = if self.cursor.glyph >= line.glyphs.len() {
|
||||||
} else {
|
String::new()
|
||||||
let glyph = &line.glyphs[self.cursor.glyph];
|
} else {
|
||||||
self.text_lines[line.line_i.get()].split_off(glyph.start)
|
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);
|
};
|
||||||
|
self.text_lines.insert(line.line_i.get() + 1, new_line);
|
||||||
|
|
||||||
// Reshape all lines after new line
|
// Reshape all lines after new line
|
||||||
//TODO: improve performance
|
//TODO: improve performance
|
||||||
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];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue