From a55c2c4ebe09239e859a31d0a9f52f6f6d772b5e Mon Sep 17 00:00:00 2001 From: zhuweihao12138 Date: Mon, 22 Jul 2024 16:25:10 +0000 Subject: [PATCH 1/2] support commands from command mode to insert mode --- src/utils/ui/mode/mode.rs | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/utils/ui/mode/mode.rs b/src/utils/ui/mode/mode.rs index c9cdd2f..b49cae7 100644 --- a/src/utils/ui/mode/mode.rs +++ b/src/utils/ui/mode/mode.rs @@ -213,8 +213,43 @@ impl KeyEventCallback for Command { return Ok(WarpUiCallBackType::ChangMode(ModeType::LastLine)); } - b"i" | b"I" => { - // 切换Insert模式 + b"i" => { + // 切换Insert模式,从光标前开始插入字符 + return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); + } + + b"I" => { + // 切换Insert模式,从行首开始插入字符 + ui.cursor.move_to_previous_line(0)?; + return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); + } + + b"a" => { + // 切换Insert模式,在光标后开始输入文本 + ui.cursor.move_right(1)?; + return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); + } + + b"A" => { + // 切换Insert模式,在行尾开始输入文本 + let linesize = ui.buffer.get_linesize(ui.cursor.y()); + ui.cursor.move_to_columu(linesize - 1)?; + return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); + } + + b"o" => { + // 切换Insert模式,在当前行的下方插入一个新行开始输入文本 + let linesize = ui.buffer.get_linesize(ui.cursor.y()); + ui.cursor.move_to_columu(linesize - 1)?; + ui.buffer.input_enter(ui.cursor.x(), ui.cursor.y()); + ui.cursor.move_to_nextline(1)?; + return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); + } + + b"O" => { + // 切换Insert模式,在当前行的上方插入一个新行开始输入文本 + ui.cursor.move_to_previous_line(0)?; + ui.buffer.input_enter(ui.cursor.x(), ui.cursor.y()); return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); } @@ -263,11 +298,6 @@ impl KeyEventCallback for Command { return Ok(WarpUiCallBackType::None); } - b"a" | b"A" => { - self.jump_to_previous_flag(ui, LineState::LOCKED)?; - return Ok(WarpUiCallBackType::None); - } - b"s" | b"S" => { self.jump_to_next_flag(ui, LineState::LOCKED)?; return Ok(WarpUiCallBackType::None); From 014d7c8c4a86321d3b37a63993931aad6d7e8b71 Mon Sep 17 00:00:00 2001 From: zhuweihao12138 Date: Wed, 7 Aug 2024 04:17:24 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=E7=AC=AC0=E5=88=97=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/ui/mode/mode.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ui/mode/mode.rs b/src/utils/ui/mode/mode.rs index b49cae7..43208b5 100644 --- a/src/utils/ui/mode/mode.rs +++ b/src/utils/ui/mode/mode.rs @@ -220,7 +220,7 @@ impl KeyEventCallback for Command { b"I" => { // 切换Insert模式,从行首开始插入字符 - ui.cursor.move_to_previous_line(0)?; + ui.cursor.move_to_columu(0)?; return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); } @@ -248,7 +248,7 @@ impl KeyEventCallback for Command { b"O" => { // 切换Insert模式,在当前行的上方插入一个新行开始输入文本 - ui.cursor.move_to_previous_line(0)?; + ui.cursor.move_to_columu(0)?; ui.buffer.input_enter(ui.cursor.x(), ui.cursor.y()); return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert)); }