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: 复制粘贴 #14

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ serde_yaml = "0.9"

# 定义标志位
bitflags = "2.4.2"

# 剪贴板
arboard = "3.4.0"
33 changes: 23 additions & 10 deletions src/utils/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl EditBuffer {
}
}

/// 删除 y 行 0..x 的字符
pub fn delete_until_line_beg(&self, x: usize, y: usize) -> Option<usize> {
let mut buffer = self.buf.write().unwrap();
let line = buffer.get_mut(y).unwrap();
Expand All @@ -400,6 +401,7 @@ impl EditBuffer {
return Some(x - 1);
}

/// 删除 y 行 x..end 的字符
pub fn delete_until_endl(&self, x: usize, y: usize) -> Option<usize> {
let mut buffer = self.buf.write().unwrap();
let line = buffer.get_mut(y).unwrap();
Expand All @@ -418,13 +420,17 @@ impl EditBuffer {
let mut right = left;
let linesize = self.get_linesize(y) as usize;
let buf = self.buf.read().unwrap();
let line = buf
.get(self.offset.load(Ordering::SeqCst) + y as usize)
.unwrap();
let line = match buf.get(self.offset.load(Ordering::SeqCst) + y as usize) {
Some(line) => line,
None => return x as usize,
};

while left <= right && right < linesize {
let lchar = line[left] as char;
let rchar = line[right] as char;
if rchar.is_ascii_punctuation() && right != x.into() {
break;
}
if !(lchar == ' ' || lchar == '\t') {
left += 1;
right += 1;
Expand All @@ -446,13 +452,17 @@ impl EditBuffer {
let mut right = left;
let linesize = self.get_linesize(y) as usize;
let buf = self.buf.read().unwrap();
let line = buf
.get(self.offset.load(Ordering::SeqCst) + y as usize)
.unwrap();
let line = match buf.get(self.offset.load(Ordering::SeqCst) + y as usize) {
Some(line) => line,
None => return x as usize,
};

while left <= right && right < linesize {
let lchar = line[left] as char;
let rchar = line[right] as char;
if rchar.is_ascii_punctuation() && right != x.into() {
break;
}
if lchar == ' ' || lchar == '\t' {
left += 1;
right += 1;
Expand All @@ -477,14 +487,17 @@ impl EditBuffer {
let mut left = x as i32;
let mut right = left;
let buf = self.buf.read().unwrap();
let line = buf
.get(self.offset.load(Ordering::SeqCst) + y as usize)
.unwrap();

let line = match buf.get(self.offset.load(Ordering::SeqCst) + y as usize) {
Some(line) => line,
None => return Some(x as usize),
};
while left <= right && left >= 0 {
let lchar = line[left as usize] as char;
let rchar = line[right as usize] as char;

if rchar.is_ascii_punctuation() && right != x.into() {
break;
}
if rchar == ' ' || rchar == '\t' {
left -= 1;
right -= 1;
Expand Down
1 change: 1 addition & 0 deletions src/utils/ui/mode/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod mode;
pub mod reg;
Loading
Loading