Skip to content

Add bracketed paste#3233

Merged
archseer merged 1 commit into
helix-editor:masterfrom
groves:add-bracketed-paste
Aug 29, 2022
Merged

Add bracketed paste#3233
archseer merged 1 commit into
helix-editor:masterfrom
groves:add-bracketed-paste

Conversation

@groves

@groves groves commented Jul 28, 2022

Copy link
Copy Markdown
Contributor

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.

Comment thread helix-term/src/application.rs Outdated
Comment thread helix-term/src/ui/editor.rs Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
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.


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

Copy link
Copy Markdown
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.

Comment thread helix-view/src/input.rs

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

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

Copy link
Copy Markdown
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
@groves
groves force-pushed the add-bracketed-paste branch from 89f6790 to 8cb1d29 Compare August 22, 2022 10:44
@sfarq

sfarq commented Aug 22, 2022

Copy link
Copy Markdown

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

@archseer

Copy link
Copy Markdown
Member

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

@archseer

Copy link
Copy Markdown
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

groves commented Aug 23, 2022

Copy link
Copy Markdown
Contributor Author

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 😅

Comment thread helix-term/src/ui/editor.rs Outdated
@groves
groves force-pushed the add-bracketed-paste branch 2 times, most recently from 50394bf to a9f57fa Compare August 24, 2022 11:13
Comment thread helix-term/src/ui/editor.rs Outdated
@groves
groves force-pushed the add-bracketed-paste branch from a9f57fa to f9e2700 Compare August 24, 2022 21:31

@archseer archseer left a comment

Copy link
Copy Markdown
Member

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