Improved backspace
This commit is contained in:
parent
ac31fa8284
commit
601547b83d
2 changed files with 17 additions and 7 deletions
|
|
@ -137,6 +137,8 @@ fn main() {
|
||||||
|
|
||||||
//TODO: support bidi
|
//TODO: support bidi
|
||||||
for line in text.lines() {
|
for line in text.lines() {
|
||||||
|
log::debug!("Line {:?}", line);
|
||||||
|
|
||||||
for c in line.chars() {
|
for c in line.chars() {
|
||||||
if c.is_control() {
|
if c.is_control() {
|
||||||
log::warn!("Ignoring control character {:?}", c);
|
log::warn!("Ignoring control character {:?}", c);
|
||||||
|
|
@ -167,8 +169,6 @@ fn main() {
|
||||||
buffer.action(TextAction::Insert(c));
|
buffer.action(TextAction::Insert(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
log::debug!("Line '{}': {:?}", line, line);
|
|
||||||
|
|
||||||
// Test backspace of newline
|
// Test backspace of newline
|
||||||
{
|
{
|
||||||
let cursor = buffer.cursor();
|
let cursor = buffer.cursor();
|
||||||
|
|
|
||||||
|
|
@ -473,21 +473,31 @@ impl<'a> TextBuffer<'a> {
|
||||||
text_line.remove(glyph.start);
|
text_line.remove(glyph.start);
|
||||||
self.reshape_line(line.line_i);
|
self.reshape_line(line.line_i);
|
||||||
} else if self.cursor.line > 0 {
|
} else if self.cursor.line > 0 {
|
||||||
self.cursor.glyph = self.layout_lines[self.cursor.line - 1].glyphs.len();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let line = &self.layout_lines[self.cursor.line];
|
let line = &self.layout_lines[self.cursor.line];
|
||||||
let old_line = self.text_lines.remove(line.line_i.get());
|
let prev_line = &self.layout_lines[self.cursor.line - 1];
|
||||||
self.text_lines[line.line_i.get() - 1].push_str(&old_line);
|
if prev_line.line_i.get() < line.line_i.get() {
|
||||||
|
let old_line = self.text_lines.remove(line.line_i.get());
|
||||||
|
self.text_lines[prev_line.line_i.get()].push_str(&old_line);
|
||||||
|
} else {
|
||||||
|
match prev_line.glyphs.last() {
|
||||||
|
Some(glyph) => {
|
||||||
|
let text_line = &mut self.text_lines[line.line_i.get()];
|
||||||
|
text_line.remove(glyph.end);
|
||||||
|
},
|
||||||
|
None => (), // There should always be a last glyph
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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() - 1);
|
self.shape_lines.truncate(prev_line.line_i.get());
|
||||||
self.relayout();
|
self.relayout();
|
||||||
self.shape_until_scroll();
|
self.shape_until_scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.cursor.line -= 1;
|
self.cursor.line -= 1;
|
||||||
|
self.cursor.glyph = self.layout_lines[self.cursor.line].glyphs.len();
|
||||||
|
|
||||||
let lines = self.lines();
|
let lines = self.lines();
|
||||||
if (self.cursor.line as i32) < self.scroll
|
if (self.cursor.line as i32) < self.scroll
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue