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

增加按键功能 #6

Merged
merged 10 commits into from
Jul 25, 2024
Merged

Conversation

trv3wood
Copy link
Contributor

实现了一系列与Vim类似的功能:

  • hjkl上下左右移动光标
  • '0'与'$'行首行末跳转
  • ‘w'与'e'单词跳转
  • 'dd'删除行等
  • 'x'删除字符

@trv3wood
Copy link
Contributor Author

添加'b'跳转至前一单词,'dw'删除单词的功能


/// 返回下一个单词的起始位置
/// 如果为该行最后一单词,返回该行长度
pub fn search_nextw_beg(&self, x: u16, y: u16) -> usize {
Copy link
Member

Choose a reason for hiding this comment

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

命名写全会更好,这里的beg最好写全begin

}

/// 返回前一单词首字母位置,如果是当前行首单词,返回 None
pub fn search_prevw_beg(&self, x: u16, y: u16) -> Option<usize> {
Copy link
Member

Choose a reason for hiding this comment

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

同理

let linesize = ui.buffer.get_linesize(y) as usize;

// 如果光标已经在当前行的末尾,则尝试移动到下一行的末尾或单词末尾
if x as usize == linesize - 1 {
if x as usize >= linesize - 2 {
Copy link
Member

Choose a reason for hiding this comment

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

这种减2的操作,这个2代表什么,应该尽量避免这种魔数

@trv3wood trv3wood marked this pull request as ready for review July 21, 2024 15:21
@trv3wood trv3wood changed the title Zys patch 增加按键功能 Jul 21, 2024
@GnoCiYeH GnoCiYeH merged commit ec52bc2 into DragonOS-Community:master Jul 25, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants