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 bracketed paste #3233

Merged
merged 1 commit into from
Aug 29, 2022
Merged

Conversation

groves
Copy link
Contributor

@groves groves commented Jul 28, 2022

This adds bracketed paste support to fix #2239. It's based on this PR on crossterm, so that will need to land and be released before this can be merged.

I haven't done any serious benchmarking, but I tried the Moby Dick Workout. Pasting with this enabled took maybe a tenth of a second to get the whole meg of book in there. Without this, I think it would've taken a day or so.

helix-term/src/application.rs Outdated Show resolved Hide resolved
helix-term/src/ui/editor.rs Outdated Show resolved Hide resolved

Some(transaction)
pub(crate) fn paste_bracketed_value(cx: &mut Context, contents: String) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't function as an actual command as I didn't see a good way to pass the contents through the Context. I think it's nicer to have it as a standalone function, but maybe I'm missing a way to make it work more like a regular command?

Because it's not a command, it doesn't set editor.last_insert and won't be repeated with .. Since you can spam your paste key as easily as ., I didn't think that was a big deal.

{
Ok(Some(transaction)) => {
doc.apply(&transaction, view.id);
doc.append_changes_to_history(view.id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't needed here as it's done in editor's event handling.

@@ -1126,6 +1138,13 @@ impl Component for EditorView {
};

match event {
Event::Paste(contents) => {
cx.count = cx.editor.count;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt like it made more sense to use a pending count here, though I could also see leaving it for an upcoming command.

@@ -6,10 +6,13 @@ use std::fmt;

pub use crate::keyboard::{KeyCode, KeyModifiers};

#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy, Hash)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the paste data is on the heap, we have to lose this Copy. That's why there's all this introduction of references through the rest of the PR.

@groves groves marked this pull request as ready for review August 11, 2022 19:17
@sfarq
Copy link

sfarq commented Aug 22, 2022

Is there a need for Space-p after this is merged?

@archseer
Copy link
Member

Yes, not all terminals support bracketed paste (I also prefer space+p over ctrl+v)

@archseer
Copy link
Member

Looks like Windows sends paste events regardless, so we need to get this merged before 22.08 is released (ctrl+v panics on windows)

@archseer archseer added this to the 22.08 milestone Aug 23, 2022
@the-mikedavis the-mikedavis linked an issue Aug 23, 2022 that may be closed by this pull request
@groves
Copy link
Contributor Author

groves commented Aug 23, 2022

That's frustrating that Windows sends bracketed pastes regardless. This is ready to go as far as I know.

If this PR needs additional work, we could also disable the bracketed-paste feature in crossterm. That would turn off the parsing entirely. I'd prefer getting the PR in, naturally 😅

@groves groves force-pushed the add-bracketed-paste branch 2 times, most recently from 50394bf to a9f57fa Compare August 24, 2022 11:13
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 for working on this! It fixes a longstanding papercut for new users that didn't know about space+p.

@archseer archseer merged commit f38ede8 into helix-editor:master Aug 29, 2022
AlexanderBrevig pushed a commit to AlexanderBrevig/helix that referenced this pull request Aug 29, 2022
@groves groves deleted the add-bracketed-paste branch August 29, 2022 10:53
AlexanderBrevig pushed a commit to AlexanderBrevig/helix that referenced this pull request Aug 29, 2022
thomasskk pushed a commit to thomasskk/helix that referenced this pull request Sep 9, 2022
jdrst pushed a commit to jdrst/helix that referenced this pull request Sep 13, 2022
herkhinah pushed a commit to herkhinah/helix that referenced this pull request Dec 11, 2022
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.

App crash on ctrl-v Bracketed paste
4 participants