Skip to content
Open
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
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dirs = "5.0"
shellexpand = "3.1"
ureq = "2.9"
syntect = { version = "5.2", default-features = false, features = ["default-fancy"] }
arboard = "3.4"
unicode-width = "0.2"
htmd = "0.5"
clipboard-rs = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
];

buildInputs = with pkgs; [
# Clipboard support (arboard/clipboard-rs)
# Clipboard support (clipboard-rs)
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
xorg.libxcb
xorg.libX11
Expand Down
40 changes: 21 additions & 19 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, HashSet};
use unicode_width::UnicodeWidthChar;

use clipboard_rs::{Clipboard as ClipboardTrait, ClipboardContext};

#[inline]
fn char_display_width(ch: char, tab_width: u16) -> u16 {
if ch == '\t' {
Expand Down Expand Up @@ -586,8 +588,8 @@ impl Editor {
if let Some(text) = self.visual_line_selected_text() {
self.clipboard = Some(text.clone());
self.clipboard_linewise = true;
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&text);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(text.clone());
}
}
}
Expand All @@ -612,8 +614,8 @@ impl Editor {
let clipboard_text = deleted_lines.join("\n") + "\n";
self.clipboard = Some(clipboard_text.clone());
self.clipboard_linewise = true;
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&clipboard_text);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(clipboard_text.clone());
}

let cursor_before = self.cursor.pos();
Expand Down Expand Up @@ -678,8 +680,8 @@ impl Editor {
if let Some(text) = self.visual_block_selected_text() {
self.clipboard = Some(text.clone());
self.clipboard_linewise = false;
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&text);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(text.clone());
}
}
}
Expand Down Expand Up @@ -718,8 +720,8 @@ impl Editor {
let clipboard_text = deleted_lines.join("\n");
self.clipboard = Some(clipboard_text.clone());
self.clipboard_linewise = false;
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&clipboard_text);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(clipboard_text.clone());
}

let cursor_before = self.cursor.pos();
Expand Down Expand Up @@ -1969,8 +1971,8 @@ impl Editor {
if let Some(text) = self.selected_text() {
self.clipboard = Some(text.clone());
self.clipboard_linewise = false;
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&text);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(text.clone());
}
}
}
Expand All @@ -1981,8 +1983,8 @@ impl Editor {
let deleted = self.buffer.delete_text_range(start.row, start.col, end.row, end.col);
self.clipboard = Some(deleted.clone());
self.clipboard_linewise = false;
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&deleted);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(deleted.clone());
}
self.wrap_cache.invalidate_from(start.row);

Expand Down Expand Up @@ -2010,8 +2012,8 @@ impl Editor {

// Copy to clipboard
self.clipboard = Some(deleted_text.clone());
if let Ok(mut clipboard) = arboard::Clipboard::new() {
let _ = clipboard.set_text(&deleted_text);
if let Ok(ctx) = ClipboardContext::new() {
let _ = ctx.set_text(deleted_text.clone());
}

// Delete the line
Expand Down Expand Up @@ -2042,7 +2044,7 @@ impl Editor {

pub fn paste(&mut self) {
let text = self.clipboard.clone().or_else(|| {
arboard::Clipboard::new().ok()?.get_text().ok()
ClipboardContext::new().ok()?.get_text().ok()
});
if let Some(text) = text {
self.insert_str(&text);
Expand All @@ -2056,8 +2058,8 @@ impl Editor {
// Try internal clipboard first, then fall back to system clipboard
let (text, linewise) = if let Some(text) = self.clipboard.clone() {
(text, self.clipboard_linewise)
} else if let Ok(mut clipboard) = arboard::Clipboard::new() {
if let Ok(text) = clipboard.get_text() {
} else if let Ok(ctx) = ClipboardContext::new() {
if let Ok(text) = ctx.get_text() {
// For system clipboard, detect linewise by checking if ends with newline
let linewise = text.ends_with('\n');
(text, linewise)
Expand Down Expand Up @@ -2108,8 +2110,8 @@ impl Editor {
pub fn paste_before(&mut self) {
let (text, linewise) = if let Some(text) = self.clipboard.clone() {
(text, self.clipboard_linewise)
} else if let Ok(mut clipboard) = arboard::Clipboard::new() {
if let Ok(text) = clipboard.get_text() {
} else if let Ok(ctx) = ClipboardContext::new() {
if let Ok(text) = ctx.get_text() {
// For system clipboard, detect linewise by checking if ends with newline
let linewise = text.ends_with('\n');
(text, linewise)
Expand Down