From 25fb92502e030235d22b8bd0288fa52f7cd8ad46 Mon Sep 17 00:00:00 2001 From: Willians Faria Date: Wed, 8 May 2024 21:50:08 -0300 Subject: [PATCH] feat: implementing x as delete character --- reqtui/src/text_object/text_object.rs | 8 ++++++++ tui/src/components/api_explorer/req_editor.rs | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/reqtui/src/text_object/text_object.rs b/reqtui/src/text_object/text_object.rs index a745956..582e84a 100644 --- a/reqtui/src/text_object/text_object.rs +++ b/reqtui/src/text_object/text_object.rs @@ -1,3 +1,5 @@ +use std::ops::Add; + use crate::text_object::cursor::Cursor; use ropey::Rope; @@ -55,6 +57,12 @@ impl TextObject { .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() } diff --git a/tui/src/components/api_explorer/req_editor.rs b/tui/src/components/api_explorer/req_editor.rs index 75d2578..2cf53c2 100644 --- a/tui/src/components/api_explorer/req_editor.rs +++ b/tui/src/components/api_explorer/req_editor.rs @@ -105,6 +105,7 @@ pub struct ReqEditor<'a> { editor_mode: EditorMode, row_scroll: usize, layout: ReqEditorLayout, + buffered_keys: String, } impl<'a> ReqEditor<'a> { @@ -136,6 +137,7 @@ impl<'a> ReqEditor<'a> { editor_mode: EditorMode::Normal, row_scroll: 0, layout: build_layout(size), + buffered_keys: String::default(), } } @@ -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) {