Commit 06a43e31 authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #71 from bobogei81123/fix_insert_line

Fix a bug in insert_line
parents 86fc7661 2e4ae134
......@@ -70,7 +70,7 @@ impl Editor {
String::new()
};
let last = ind.len();
self.buffers.current_buffer_mut().insert_line(y, ind.into());
self.buffers.current_buffer_mut().insert_line(y + 1, ind.into());
self.goto((last, y + 1));
self.cursor_mut().mode =
Mode::Primitive(PrimitiveMode::Insert(InsertOptions {
......
......@@ -155,8 +155,8 @@ impl<'a> TextBuffer<'a> for SplitBuffer {
fn insert_line(&mut self, n: usize, line: String) {
if n < self.before.len() {
self.before.insert(n, line);
} else if n < self.len() {
let n = self.len() - 1 - n;
} else if n <= self.len() {
let n = self.len() - n;
self.after.insert(n, line);
} else {
panic!("Out of bound");
......
......@@ -38,7 +38,7 @@ impl Editor {
};
let begin = nl.len();
self.buffers.current_buffer_mut().insert_line(y, nl + &second_part);
self.buffers.current_buffer_mut().insert_line(y + 1, nl + &second_part);
self.redraw_task = RedrawTask::LinesAfter(y);
self.goto((begin, y + 1));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment