-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Key remappings for mouse configuration #9469
Open
Nilsia
wants to merge
4
commits into
helix-editor:master
Choose a base branch
from
Nilsia:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
38afca4
Feature: key remappings for mouse in configuration
Nilsia d5a32d9
Merge branch 'tmp'
Nilsia cb7a6b1
modified the commands generation macro, in order to join mouse and ke…
Nilsia 871ef80
added scroll left and rigth to default mappings for mouse
Nilsia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
use crate::ui::{ | ||
editor::{gutter_coords_and_view, pos_and_view}, | ||
EditorView, | ||
}; | ||
use anyhow::anyhow; | ||
use helix_core::{movement::Direction, Range, Selection}; | ||
use helix_view::{input::MouseEvent, Document, ViewId}; | ||
|
||
use super::{ | ||
move_next_long_word_end, move_next_word_end, move_prev_long_word_start, move_prev_word_start, | ||
paste_primary_clipboard_before, yank_primary_selection_impl, Context, | ||
}; | ||
|
||
#[derive(Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Copy)] | ||
pub struct StaticMouseCommand { | ||
pub name: &'static str, | ||
pub(crate) fun: fn(&mut Context, &MouseEvent, &mut EditorView), | ||
pub doc: &'static str, | ||
} | ||
|
||
impl std::str::FromStr for StaticMouseCommand { | ||
type Err = anyhow::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
StaticMouseCommand::STATIC_COMMAND_LIST | ||
.iter() | ||
.find(|cmd| cmd.name() == s) | ||
.cloned() | ||
.ok_or_else(|| anyhow!("No command named '{}'", s)) | ||
} | ||
} | ||
|
||
impl StaticMouseCommand { | ||
pub fn execute(&self, cx: &mut Context, event: &MouseEvent, editor_view: &mut EditorView) { | ||
(self.fun)(cx, event, editor_view); | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
self.name | ||
} | ||
|
||
pub fn doc(&self) -> &str { | ||
self.doc | ||
} | ||
} | ||
|
||
fn handle_selection_in_buffer( | ||
cx: &mut Context, | ||
evt: &MouseEvent, | ||
ev: &mut EditorView, | ||
callback: impl Fn(&mut Document, &ViewId, usize), | ||
) -> bool { | ||
let editor = &mut cx.editor; | ||
|
||
if let Some((pos, view_id)) = pos_and_view(editor, evt.row, evt.column, true) { | ||
let prev_view_id = view!(editor).id; | ||
let doc = doc_mut!(editor, &view!(editor, view_id).doc); | ||
|
||
callback(doc, &view_id, pos); | ||
|
||
if view_id != prev_view_id { | ||
ev.clear_completion(editor); | ||
} | ||
|
||
editor.focus(view_id); | ||
editor.ensure_cursor_in_view(view_id); | ||
|
||
return true; | ||
} | ||
false | ||
} | ||
|
||
pub fn handle_main_button_mouse(cx: &mut Context, evt: &MouseEvent, ev: &mut EditorView) { | ||
if !handle_selection_in_buffer( | ||
cx, | ||
evt, | ||
ev, | ||
|doc: &mut Document, view_id: &ViewId, pos: usize| { | ||
doc.set_selection(*view_id, Selection::point(pos)); | ||
}, | ||
) { | ||
add_breakpoint_mouse(cx, evt, ev); | ||
} | ||
} | ||
|
||
pub fn set_mouse_selection(cx: &mut Context, evt: &MouseEvent, ev: &mut EditorView) { | ||
handle_selection_in_buffer( | ||
cx, | ||
evt, | ||
ev, | ||
|doc: &mut Document, view_id: &ViewId, pos: usize| { | ||
doc.set_selection(*view_id, Selection::point(pos)); | ||
}, | ||
); | ||
} | ||
|
||
pub fn select_word_mouse(cx: &mut Context, _: &MouseEvent, _: &mut EditorView) { | ||
move_prev_word_start(cx); | ||
move_next_word_end(cx); | ||
} | ||
|
||
pub fn select_long_word_mouse(cx: &mut Context, _: &MouseEvent, _: &mut EditorView) { | ||
move_prev_long_word_start(cx); | ||
move_next_long_word_end(cx); | ||
} | ||
|
||
pub fn scroll_mouse_impl(cx: &mut Context, evt: &MouseEvent, dir: Direction, _: &mut EditorView) { | ||
let current_view = cx.editor.tree.focus; | ||
match pos_and_view(cx.editor, evt.row, evt.column, false) { | ||
Some((_, view_id)) => cx.editor.tree.focus = view_id, | ||
None => return, | ||
} | ||
super::scroll(cx, cx.editor.config().scroll_lines.unsigned_abs(), dir); | ||
cx.editor.tree.focus = current_view; | ||
cx.editor.ensure_cursor_in_view(current_view); | ||
} | ||
|
||
pub fn scroll_up_mouse(cx: &mut Context, evt: &MouseEvent, ev: &mut EditorView) { | ||
scroll_mouse_impl(cx, evt, Direction::Backward, ev) | ||
} | ||
|
||
pub fn scroll_down_mouse(cx: &mut Context, evt: &MouseEvent, ev: &mut EditorView) { | ||
scroll_mouse_impl(cx, evt, Direction::Forward, ev) | ||
} | ||
|
||
pub fn paste_primary_clipboard_before_mouse( | ||
cx: &mut Context, | ||
evt: &MouseEvent, | ||
_: &mut EditorView, | ||
) { | ||
// if !config.middle_click_paste { | ||
// return; | ||
// } | ||
let editor = &mut cx.editor; | ||
if let Some((pos, view_id)) = pos_and_view(editor, evt.row, evt.column, true) { | ||
let doc = doc_mut!(editor, &view!(editor, view_id).doc); | ||
doc.set_selection(view_id, Selection::point(pos)); | ||
cx.editor.focus(view_id); | ||
paste_primary_clipboard_before(cx) | ||
} | ||
} | ||
|
||
pub fn yank_main_selection_to_primary_clipboard_mouse( | ||
cx: &mut Context, | ||
_: &MouseEvent, | ||
_: &mut EditorView, | ||
) { | ||
let editor = &mut cx.editor; | ||
let (view, doc) = current!(editor); | ||
if doc | ||
.selection(view.id) | ||
.primary() | ||
.slice(doc.text().slice(..)) | ||
.len_chars() | ||
<= 1 | ||
{ | ||
return; | ||
} | ||
|
||
yank_primary_selection_impl(cx.editor, '*'); | ||
} | ||
|
||
pub fn add_breakpoint_mouse(cx: &mut Context, evt: &MouseEvent, _: &mut EditorView) { | ||
log::info!("called breakpoint adder"); | ||
let editor = &mut cx.editor; | ||
if let Some((coords, view_id)) = gutter_coords_and_view(editor, evt.row, evt.column) { | ||
editor.focus(view_id); | ||
|
||
let (view, doc) = current!(cx.editor); | ||
|
||
let path = match doc.path() { | ||
Some(path) => path.clone(), | ||
None => return, | ||
}; | ||
|
||
if let Some(char_idx) = | ||
view.pos_at_visual_coords(doc, coords.row as u16, coords.col as u16, true) | ||
{ | ||
let line = doc.text().char_to_line(char_idx); | ||
super::dap_toggle_breakpoint_impl(cx, path, line); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
pub fn add_selection_mouse(cx: &mut Context, evt: &MouseEvent, ev: &mut EditorView) { | ||
handle_selection_in_buffer( | ||
cx, | ||
evt, | ||
ev, | ||
|doc: &mut Document, view_id: &ViewId, pos: usize| { | ||
let selection = doc.selection(*view_id).clone(); | ||
doc.set_selection(*view_id, selection.push(Range::point(pos))); | ||
}, | ||
); | ||
} | ||
|
||
fn dap_impl_mouse(cx: &mut Context, evt: &MouseEvent, callback: impl Fn(&mut Context)) { | ||
let editor = &mut cx.editor; | ||
if let Some((coords, view_id)) = gutter_coords_and_view(editor, evt.row, evt.column) { | ||
editor.focus(view_id); | ||
|
||
let (view, doc) = current!(editor); | ||
if let Some(pos) = | ||
view.pos_at_visual_coords(doc, coords.row as u16, coords.col as u16, true) | ||
{ | ||
doc.set_selection(view_id, Selection::point(pos)); | ||
callback(cx); | ||
} | ||
} | ||
} | ||
|
||
pub fn dap_edit_condition_mouse(cx: &mut Context, evt: &MouseEvent, _: &mut EditorView) { | ||
dap_impl_mouse(cx, evt, |cx| { | ||
super::dap_edit_condition(cx); | ||
}) | ||
} | ||
|
||
pub fn dap_edit_log_mouse(cx: &mut Context, evt: &MouseEvent, _: &mut EditorView) { | ||
dap_impl_mouse(cx, evt, |cx: &mut Context| { | ||
super::dap_edit_log(cx); | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check if a picker has the focus?
currently the mouse wheel does not scroll the code preview in the picker, but the code in the current buffer.