Skip to content
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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions src/utils/ui/mode/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是当前行首还是前一行的行首?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是当前行首,没有直接对应的函数,但是用这个函数参数为0可以实现

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是否用移动到第0列的语义更加合适

return Ok(WarpUiCallBackType::ChangMode(ModeType::Insert));
}

b"a" => {
// 切换Insert模式,在光标后开始输入文本
ui.cursor.move_right(1)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有没有考虑如果光标后没有内容时行为是否正确

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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));
}

Expand Down Expand Up @@ -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);
Expand Down
Loading