Commit 2e4ae134 authored by bobogei81123's avatar bobogei81123

Fix a bug in insert_line

Assuming that insert_line(n) shall insert the string
into nth-line (0 based).
- Fix a bug in insert_line when insert into after buffer
- Do corresponding changes in other place
parent 86fc7661
......@@ -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