diff --git a/core/src/editor_buffer/mod.rs b/core/src/editor_buffer/mod.rs index c6a0616..1e4249f 100644 --- a/core/src/editor_buffer/mod.rs +++ b/core/src/editor_buffer/mod.rs @@ -98,9 +98,26 @@ impl EditorBuffer { } fn insert_char(&self, c: char) -> CommandResult { + let newline = c == '\n'; CommandResult::ok(Self { buffer: self.buffer.insert_char(c, self.cursor), - cursor: self.cursor.advance(), + cursor: match self.cursor { + Point::Start => { + if newline { + Point::LineColumn(1, 0) + } else { + Point::LineColumn(0, 1) + } + } + Point::LineColumn(line, column) => { + if newline { + Point::LineColumn(line + 1, 0) + } else { + Point::LineColumn(line, column + 1) + } + } + Point::End => Point::End, + }, ..self.clone() }) } diff --git a/core/src/text_buffer/mod.rs b/core/src/text_buffer/mod.rs index c208bbf..f2a0b63 100644 --- a/core/src/text_buffer/mod.rs +++ b/core/src/text_buffer/mod.rs @@ -26,16 +26,6 @@ pub enum Point { End, } -impl Point { - pub fn advance(self) -> Self { - match self { - Self::Start => Self::LineColumn(0, 1), - Self::LineColumn(l, c) => Self::LineColumn(l, c + 1), - Self::End => Self::End, - } - } -} - impl TextBuffer { /// Create a new empty [TextBuffer] pub fn new() -> Self {