Closed gchp closed 9 years ago
Couldn't really debug this, but i have a guess:
As the last char gets removed, the mark is is at text.len(). As of this, get_line_end will return None, and shift_mark will refuse to alter the marks position. The crash will happen on the next backspace, probably because the mark is outside of text.
pub fn delete_chars(&mut self, direction: Direction, num_chars: usize) {
let chars = self.buffer.remove_chars(self.cursor, direction, num_chars);
// mark is now outside of the text
match (chars, direction) {
(Some(chars), Direction::Left) => {
self.move_cursor(Direction::Left, chars.len());
}
(Some(chars), Direction::LeftWord(..)) => {
self.move_cursor(Direction::Left, chars.len());
}
_ => {}
}
}
/// Shift a mark relative to its position according to the direction given.
pub fn shift_mark(&mut self, mark: Mark, direction: Direction, amount: usize) {
let last = self.len() - 1;
let text = &self.text;
if let Some(tuple) = self.marks.get_mut(&mark) {
let (idx, line_idx) = *tuple;
/**
* get_line_end will return None
*/
if let (Some(line), Some(line_end)) = (get_line(idx, text), get_line_end(idx, text)) {
*tuple = match direction {
//For every relative motion of a mark, should return this tuple:
// value 0: the absolute index of the mark in the file
// value 1: the index of the mark in its line (unchanged by direct verticle
// traversals)
Direction::Left => {
let n = amount;
if idx >= n { (idx - n, idx - n - get_line(idx - n, text).unwrap()) }
else { (0, 0) }
}
....
/// Returns the index of the newline character at the end of the line mark is in.
/// Newline after mark (INCLUSIVE).
/// None if mark is outside the len of text.
fn get_line_end(mark: usize, text: &GapBuffer<u8>) -> Option<usize> {
if mark <= text.len() { // <-- never true in our case
range(mark, text.len() + 1).filter(|idx| *idx == text.len() ||text[*idx] == b'\n')
.take(1)
.next()
} else { None }
}
Please, see this PR https://github.com/gchp/iota/pull/86
When you try to delete backwards from the end of a buffer, Iota will crash with the following error:
Seems as if the cursor position is one greater than the length of the buffer.