Skip to content

Commit

Permalink
feat: implementing x as delete character
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 9, 2024
1 parent feea9c3 commit 25fb925
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions reqtui/src/text_object/text_object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Add;

use crate::text_object::cursor::Cursor;
use ropey::Rope;

Expand Down Expand Up @@ -55,6 +57,12 @@ impl TextObject<Write> {
.ok();
}

pub fn erase_current_char(&mut self, cursor: &Cursor) {
let line = self.content.line_to_char(cursor.row());
let col_offset = line + cursor.col();
self.content.try_remove(col_offset..col_offset.add(1)).ok();
}

pub fn current_line(&self, cursor: &Cursor) -> Option<&str> {
self.content.line(cursor.row()).as_str()
}
Expand Down
5 changes: 5 additions & 0 deletions tui/src/components/api_explorer/req_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct ReqEditor<'a> {
editor_mode: EditorMode,
row_scroll: usize,
layout: ReqEditorLayout,
buffered_keys: String,
}

impl<'a> ReqEditor<'a> {
Expand Down Expand Up @@ -136,6 +137,7 @@ impl<'a> ReqEditor<'a> {
editor_mode: EditorMode::Normal,
row_scroll: 0,
layout: build_layout(size),
buffered_keys: String::default(),
}
}

Expand Down Expand Up @@ -361,6 +363,9 @@ impl Eventful for ReqEditor<'_> {
self.cursor.move_right(1);
}
}
(EditorMode::Normal, KeyCode::Char('x'), KeyModifiers::NONE) => {
self.body.erase_current_char(&self.cursor);
}
(EditorMode::Normal, KeyCode::Char('a'), KeyModifiers::NONE) => {
let current_line_len = self.body.line_len(self.cursor.row());
if current_line_len.gt(&0) {
Expand Down

0 comments on commit 25fb925

Please sign in to comment.