Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Implement Kakoune's A-S #9459

Closed
kirawi opened this issue Jan 28, 2024 · 9 comments · May be fixed by #9483
Closed

Implement Kakoune's A-S #9459

kirawi opened this issue Jan 28, 2024 · 9 comments · May be fixed by #9483
Labels
A-command Area: Commands C-enhancement Category: Improvements E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR

Comments

@kirawi
Copy link
Member

kirawi commented Jan 28, 2024

In Kakoune, it selects the first and last characters of each selection.

Where [] denotes a selection, [helix] becomes [h]eli[x]

It would look similar to

fn split_selection_on_newline(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
// only compile the regex once
#[allow(clippy::trivial_regex)]
static REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\r\n|[\n\r\u{000B}\u{000C}\u{0085}\u{2028}\u{2029}]").unwrap());
let selection = selection::split_on_matches(text, doc.selection(view.id), &REGEX);
doc.set_selection(view.id, selection);
}
but use
pub fn transform_iter<F, I>(mut self, f: F) -> Self
where
F: FnMut(Range) -> I,
I: Iterator<Item = Range>,
{
self.ranges = self.ranges.into_iter().flat_map(f).collect();
self.normalize()
}
instead

@kirawi kirawi added C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors A-command Area: Commands E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR labels Jan 28, 2024
@scdailey
Copy link

Is anyone working on this one at the moment? I'd like to make my first contribution

@kirawi
Copy link
Member Author

kirawi commented Jan 29, 2024

Nobody has announced that they're working on this, so it's probably fine?

@scdailey
Copy link

Cool! Ill give it a shot

@woojiq
Copy link
Contributor

woojiq commented Jan 30, 2024

I'm not against this, just asking what is a usecase? The only situation I can see is something like selecting parentheses/brackets and delete them, but for that I can use existing keybinds.

@scdailey
Copy link

#9483

Just created a pull request for this one

@the-mikedavis
Copy link
Member

Did you have something specific in mind for this command @kirawi? I also wonder if we need a command for this given that we have surround tools builtin while Kakoune does not

@kirawi
Copy link
Member Author

kirawi commented Jan 30, 2024

It was requested by https://matrix.to/#/!zMuVRxoqjyxyjSEBXc:matrix.org/$bFvOW3o-qWGL_cSdJWwK1wE86NXUz8LFq7rBJtO6VMA?via=matrix.org&via=mozilla.org&via=envs.net and I thought it was simple enough (and because Kakoune included it).

mawww/kakoune#550 is the issue that motivated it in Kakoune. I think right now it could also be useful for basic multi-character pairs.

Overall, I agree that it is a niche command and if you guys don't want to include the command I'd be indifferent to it.

@the-mikedavis
Copy link
Member

The use-cases mentioned later in the issue are covered by surround tools. The original use-case I'm not sure I fully understand but it seems like it wouldn't come up often so I bet it could be covered instead by subselecting with a regex of ^.|.$. I've asked on matrix what the commenter's use-case is - I'm leaning towards not adding this unless there's something compelling

@the-mikedavis the-mikedavis removed E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors labels Feb 15, 2024
@totallyuniquelily
Copy link

totallyuniquelily commented Feb 22, 2024

so I bet it could be covered instead by subselecting with a regex of ^.|.$.

for selections that span across lines, \A.|.\z can be used instead to not match beginning/end of line

@helix-editor helix-editor locked and limited conversation to collaborators Apr 8, 2024
@pascalkuthe pascalkuthe converted this issue into discussion #10287 Apr 8, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
A-command Area: Commands C-enhancement Category: Improvements E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants