-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support commands from command mode to insert mode #7
Merged
GnoCiYeH
merged 2 commits into
DragonOS-Community:master
from
zhuweihao12138:zwh/support_insert_mode
Aug 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有没有考虑如果光标后没有内容时行为是否正确 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move_right函数已经考虑了详尽的情况 |
||
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); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是当前行首还是前一行的行首?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是当前行首,没有直接对应的函数,但是用这个函数参数为0可以实现
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是否用移动到第0列的语义更加合适