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

Support primary clipboard #548

Merged
merged 31 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
75fed68
clipboard-none: add in-memory fallback buffer
dsseng Aug 4, 2021
2c20d35
view: add Wayland primary clipboard
dsseng Aug 4, 2021
5b88151
Format
dsseng Aug 4, 2021
8ccbe36
helix-term: copy to primary selection after mouse move stops
dsseng Aug 4, 2021
c938a7b
helix-term: don't update primary selection if it is a single character
dsseng Aug 4, 2021
684b8dc
helix-term: discard result of setting primary selection
dsseng Aug 4, 2021
71eb635
helix-term: add commands for interaction with primary clipboard
dsseng Aug 4, 2021
fb06c20
editor: implement primary selection copy/paste using commands
dsseng Aug 4, 2021
74681bd
clipboard: support xsel for primary selection
dsseng Aug 4, 2021
f898fad
clipboard: support xclip for primary selection
dsseng Aug 4, 2021
19f6c94
helix-term: multiple cursor support for middle click paste
dsseng Aug 4, 2021
05ae650
rename primary selection to primary clipboard in scope of PR
dsseng Aug 4, 2021
1e8162e
helix-term: make middle click paste optional
dsseng Aug 4, 2021
db0d5d5
Format
dsseng Aug 4, 2021
b273396
Update helix-term/src/ui/editor.rs
dsseng Aug 5, 2021
ffef3ea
fix formatting
dsseng Aug 5, 2021
b76b8e7
config: correct defaults if terminal prop is not set
dsseng Aug 5, 2021
2316230
refactor: merge clipboard and primary selection implementations
dsseng Aug 5, 2021
d16eab4
Merge branch 'master' into primary-clipboard
dsseng Aug 5, 2021
7e4a85b
Tidy up code
dsseng Aug 5, 2021
ada6b9d
view: remove names for different clipboard/selection providers
dsseng Aug 5, 2021
a530f88
Update helix-view/src/clipboard.rs
dsseng Aug 7, 2021
b363b0b
helix-view: tidy macros
dsseng Aug 7, 2021
7e82895
helix-term: refactor paste-replace commands
dsseng Aug 7, 2021
bded2fd
Merge branch 'master' into primary-clipboard
dsseng Aug 8, 2021
9294835
helix-term: use new config for middle-click-paste
dsseng Aug 8, 2021
13c8a0c
clipboard: remove memory fallback for command and windows providers
dsseng Aug 8, 2021
cbd58f1
clipboard-win: fix build
dsseng Aug 8, 2021
79a79c5
clipboard: return empty string when primary clipboard is missing
dsseng Aug 8, 2021
5ba6241
clipboard: fix errors in Windows build
dsseng Aug 8, 2021
7fbc25a
Merge branch 'master' into primary-clipboard
dsseng Aug 10, 2021
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
2 changes: 1 addition & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Application {

let mut editor = Editor::new(size, theme_loader.clone(), syn_loader.clone());

let editor_view = Box::new(ui::EditorView::new(std::mem::take(&mut config.keys)));
let editor_view = Box::new(ui::EditorView::new(std::mem::take(&mut config.keys), config.terminal.middle_click_paste));
dsseng marked this conversation as resolved.
Show resolved Hide resolved
compositor.push(editor_view);

if !args.files.is_empty() {
Expand Down
15 changes: 10 additions & 5 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ pub struct LspConfig {
pub display_messages: bool,
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct TerminalConfig {
#[serde(default = "mouse_default")]
pub mouse: bool,
#[serde(default = "middle_click_paste_default")]
pub middle_click_paste: bool,
}

fn mouse_default() -> bool {
true
}

impl Default for TerminalConfig {
fn default() -> Self {
Self { mouse: true }
}
fn middle_click_paste_default() -> bool {
true
}
sudormrfbin marked this conversation as resolved.
Show resolved Hide resolved

#[test]
Expand Down
14 changes: 12 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use tui::buffer::Buffer as Surface;

pub struct EditorView {
keymaps: Keymaps,
middle_click_paste: bool,
on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
last_insert: (commands::Command, Vec<KeyEvent>),
completion: Option<Completion>,
Expand All @@ -40,14 +41,15 @@ const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter

impl Default for EditorView {
fn default() -> Self {
Self::new(Keymaps::default())
Self::new(Keymaps::default(), true)
}
}

impl EditorView {
pub fn new(keymaps: Keymaps) -> Self {
pub fn new(keymaps: Keymaps, middle_click_paste: bool) -> Self {
Self {
keymaps,
middle_click_paste,
on_next_key: None,
last_insert: (commands::Command::normal_mode, Vec::new()),
completion: None,
Expand Down Expand Up @@ -861,6 +863,10 @@ impl Component for EditorView {
kind: MouseEventKind::Up(MouseButton::Left),
..
}) => {
if !self.middle_click_paste {
return EventResult::Ignored;
}

let (view, doc) = current!(cx.editor);
let range = doc.selection(view.id).primary();

Expand Down Expand Up @@ -889,6 +895,10 @@ impl Component for EditorView {
modifiers,
..
}) => {
if !self.middle_click_paste {
return EventResult::Ignored;
}

let editor = &mut cx.editor;
dsseng marked this conversation as resolved.
Show resolved Hide resolved

if modifiers == crossterm::event::KeyModifiers::ALT {
Expand Down