aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorDmitry Sharshakov2021-08-12 02:53:48 +0000
committerGitHub2021-08-12 02:53:48 +0000
commit7d51805e94a461834ce34e0829da5859d1f9db32 (patch)
tree08ce918cab9d5d0cc09e43910c79a6f73673664a /helix-term/src/ui
parentd03982ee432bb418e1e74d490ae66371e201cee2 (diff)
Support primary clipboard (#548)
* clipboard-none: add in-memory fallback buffer Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * view: add Wayland primary clipboard Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * Format Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: copy to primary selection after mouse move stops Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: don't update primary selection if it is a single character Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: discard result of setting primary selection Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: add commands for interaction with primary clipboard Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * editor: implement primary selection copy/paste using commands Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * clipboard: support xsel for primary selection Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * clipboard: support xclip for primary selection Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: multiple cursor support for middle click paste Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * rename primary selection to primary clipboard in scope of PR Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: make middle click paste optional Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * Format Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * Update helix-term/src/ui/editor.rs * fix formatting Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * config: correct defaults if terminal prop is not set Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * refactor: merge clipboard and primary selection implementations Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * Tidy up code Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * view: remove names for different clipboard/selection providers Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * Update helix-view/src/clipboard.rs Co-authored-by: Gokul Soumya <gokulps15@gmail.com> * helix-view: tidy macros Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: refactor paste-replace commands Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * helix-term: use new config for middle-click-paste Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * clipboard: remove memory fallback for command and windows providers Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * clipboard-win: fix build Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * clipboard: return empty string when primary clipboard is missing Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> * clipboard: fix errors in Windows build Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com> Co-authored-by: Gokul Soumya <gokulps15@gmail.com>
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/editor.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index aa21a389..96a4afe8 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -785,6 +785,61 @@ impl EditorView {
EventResult::Consumed(None)
}
+
+ MouseEvent {
+ kind: MouseEventKind::Up(MouseButton::Left),
+ ..
+ } => {
+ if !cxt.editor.config.middle_click_paste {
+ return EventResult::Ignored;
+ }
+
+ let (view, doc) = current!(cxt.editor);
+ let range = doc.selection(view.id).primary();
+
+ if range.to() - range.from() <= 1 {
+ return EventResult::Ignored;
+ }
+
+ commands::Command::yank_main_selection_to_primary_clipboard.execute(cxt);
+
+ EventResult::Consumed(None)
+ }
+
+ MouseEvent {
+ kind: MouseEventKind::Up(MouseButton::Middle),
+ row,
+ column,
+ modifiers,
+ ..
+ } => {
+ let editor = &mut cxt.editor;
+ if !editor.config.middle_click_paste {
+ return EventResult::Ignored;
+ }
+
+ if modifiers == crossterm::event::KeyModifiers::ALT {
+ commands::Command::replace_selections_with_primary_clipboard.execute(cxt);
+
+ return EventResult::Consumed(None);
+ }
+
+ let result = editor.tree.views().find_map(|(view, _focus)| {
+ view.pos_at_screen_coords(&editor.documents[view.doc], row, column)
+ .map(|pos| (pos, view.id))
+ });
+
+ if let Some((pos, view_id)) = result {
+ let doc = &mut editor.documents[editor.tree.get(view_id).doc];
+ doc.set_selection(view_id, Selection::point(pos));
+ editor.tree.focus = view_id;
+ commands::Command::paste_primary_clipboard_before.execute(cxt);
+ return EventResult::Consumed(None);
+ }
+
+ EventResult::Ignored
+ }
+
_ => EventResult::Ignored,
}
}