Skip to content

Commit

Permalink
Replace use of insert_char_at with insert_char
Browse files Browse the repository at this point in the history
  • Loading branch information
nixypanda committed Jun 21, 2021
1 parent 7ba6136 commit f1ffa23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
13 changes: 3 additions & 10 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ impl Reedline {
}

fn insert_char(&mut self, c: char) {
let insertion_point = self.line_buffer.insertion_point();
self.line_buffer.insert_char_at(insertion_point, c);
self.line_buffer.insert_char(c)
}

fn backspace(&mut self) {
Expand Down Expand Up @@ -826,10 +825,7 @@ impl Reedline {
};
if self.maybe_wrap(terminal_size.0, line_start, c) {
let (original_column, original_row) = position()?;
self.run_edit_commands(&[
EditCommand::InsertChar(c),
EditCommand::MoveRight,
]);
self.run_edit_commands(&[EditCommand::InsertChar(c)]);
self.buffer_paint(prompt_offset)?;

let (new_column, _) = position()?;
Expand All @@ -844,10 +840,7 @@ impl Reedline {
line_count += 1;
}
} else {
self.run_edit_commands(&[
EditCommand::InsertChar(c),
EditCommand::MoveRight,
]);
self.run_edit_commands(&[EditCommand::InsertChar(c)]);
}
}
(KeyModifiers::NONE, KeyCode::Enter, x) if x != EditMode::ViNormal => {
Expand Down
6 changes: 1 addition & 5 deletions src/line_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,13 @@ impl LineBuffer {
self.insertion_point.offset
}

///Insert a single character at the insertion point and move right
pub fn insert_char(&mut self, c: char) {
let pos = self.insertion_point();
self.lines[pos.line].insert(pos.offset, c);
self.move_right();
}

/// Insert a single character at the given cursor postion
pub fn insert_char_at(&mut self, pos: InsertionPoint, c: char) {
self.lines[pos.line].insert(pos.offset, c)
}

pub fn insert_str(&mut self, string: &str) {
let pos = self.insertion_point();
self.lines[pos.line].insert_str(pos.offset, string);
Expand Down

0 comments on commit f1ffa23

Please sign in to comment.