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

Add command to extend to line start or end #717

Merged

Conversation

pbzweihander
Copy link
Contributor

Currently, goto_line_{start,end,end_newline} commands works as extend when in select mode. This PR adds extend_to_line_{start,end,end_newline} commands that always extend to regardless of current mode.

let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);

let selection = doc.selection(view.id).clone().transform(|range| {
let line = range.cursor_line(text);
let pos = line_end_char_index(&text, line);

range.put_cursor(text, pos, doc.mode == Mode::Select)
range.put_cursor(text, pos, always_extend || doc.mode == Mode::Select)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather see this parameter called extend, then you can map to the new extend_ commands inside the keymap

select.merge_nodes(keymap!({ "Select mode"

(So two sets of commands, one that always moves, one that always extends)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better than a bool would be if we reused this enum:

#[derive(Copy, Clone, PartialEq, Eq)]
pub enum Movement {
Extend,
Move,
}

@pbzweihander pbzweihander force-pushed the extend-to-line-start-end branch from 918bde0 to 471de01 Compare September 7, 2021 04:28
@pbzweihander
Copy link
Contributor Author

@archseer I've updated PR!

Copy link
Member

@archseer archseer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants