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

Paste multi-line #191

Closed
pboling opened this issue Dec 20, 2024 · 18 comments
Closed

Paste multi-line #191

pboling opened this issue Dec 20, 2024 · 18 comments

Comments

@pboling
Copy link

pboling commented Dec 20, 2024

What is the bug?

Unable to paste text that has new lines.

What did you do to get the bug?

Copy text with new lines... such as this random example:

➕ rubocop-capybara, rubocop-factory_bot

Error: The `RSpec/Capybara/FeatureMethods` cop has been removed since this cop has migrated to `RSpec/Dialect`. Please use `RSpec/Dialect` instead.
(obsolete configuration found in config/default.yml, please update it)
`RSpec/Capybara/*` has been extracted to the `rubocop-capybara` gem.
(obsolete configuration found in config/default.yml, please update it)
Error: unrecognized cop or department FactoryBot/AssociationStyle found in config/default.yml
unrecognized cop or department FactoryBot/ConsistentParenthesesStyle found in config/default.yml
unrecognized cop or department FactoryBot/SyntaxMethods found in config/default.yml

And attempt to paste into ox.

What behaviour were you expecting?

I expect the paste to not strip new lines.

Screenshots (if applicable)

Screenshot 2024-12-20 at 15 29 01
@curlpipe
Copy link
Owner

curlpipe commented Dec 20, 2024

Thank you for the bug report. I've been unable to reproduce this on my system so far.

May I ask the following questions, just so I can further investigate:

  • What version of Ox are you using?
  • What terminal emulator are you using?
  • What operating system are you using?

I have the following theories

  • Terminal Emulator
    • Duplicate key bindings for paste combination e.g. ctrl+v pastes and does something else?
    • Behaviour is different on your terminal emulator to the ones I've tested
    • Somehow it's ignoring bracketed paste, or messing with it?
  • Operating System
    • macOS can be a bit strange when it comes to input because crossterm can report different things as input from Linux / Windows
  • Ox itself
    • Some bug caused by the contents of the paste text (like different newline endings, or strange characters)
    • Some strange edge case where it breaks that hasn't been discovered yet
    • An Ox plug-in that is interfering with the text

Hopefully I can reproduce this bug, rule these out one by one and find and fix the root cause

@pboling
Copy link
Author

pboling commented Dec 20, 2024

Answering the easy ones first:

❯ ox -v
0.7.4

I use iTerm2, and the (old, basic) RubyMine terminal, and I run zsh. The behavior is the same in both.

❯ echo $TERM
xterm-256color
❯ zsh --version
zsh --version
zsh 5.9 (arm-apple-darwin22.1.0)

I also use oh-my-zsh, and powerline 10k, a zsh theme: https://github.com/romkatv/powerlevel10k?tab=readme-ov-file#oh-my-zsh.

Note: The key bindings suggested by the ox runtime are often incorrect / confusing, as suggestions are usually uppercase, but only work when lower case. (e.g. ctrl+s, not ctrl+S).

Also of note, I generally use the standard MacOS keybinding for paste, cmd+v, not ctrl+v.

@curlpipe
Copy link
Owner

Thanks for your response, I'm pretty confident this is something to do with macOS input, I'll fire up my test machine and get debugging. Hopefully this can get patched ready for the next release!

@pboling
Copy link
Author

pboling commented Dec 21, 2024

Also, FWIW, I'm on the latest MacOS, Sequoia 15.2.

I have tried bouncing the copied text through a basic GUI text editor (like Smultron, or Text Edit), pasting it there, and recopying, just to be sure it isn't an artifact from the source of the copy. It has not made any difference.

@kachick
Copy link

kachick commented Dec 23, 2024

I can reproduce this problem in Windows Terminal.

  • ox 0.7.5 runs in WSL2
  • alacritty 0.14.0
  • Windows Terminal 1.21.3231.0

Both terminals correctly cut multi-line text with Ctrl+x. I checked the clipboard history.
However, when pasting, Windows Terminal trims the line endings.

It occurs with every text. Both of LF/CRLF.
For example

a
b

to

ab

@curlpipe
Copy link
Owner

curlpipe commented Dec 23, 2024

@kachick Thank you for the info. I think I have managed to reproduce this on my windows machine in windows terminal.

In Alacritty: when I copy some text with newlines from an external editor (notepad++) , it pastes in perfectly. The only time it starts removing newlines is when I copy and paste within Ox itself.

Very strange behaviour. I'll look into this.

@pboling
Copy link
Author

pboling commented Dec 23, 2024

It may be worth looking into what vim does with its set paste mode. I'm no expert on vim, but I know that when pasting things if I have bad results, I just need to set paste, to enter paste mode, and it works better.

@curlpipe
Copy link
Owner

curlpipe commented Dec 23, 2024

I think vim might interact with the system's clipboard directly whereas Ox just piggybacks on the terminal emulator feeding it the paste text. I originally added vim-style clipboard management, but it was removed because it was quite heavy and didn't work over SSH.

@pboling @kachick do you happen to get a warning message immediately after pasting text with newlines that says something like ctrl+enter not bound? I have a suspicion that the terminal emulator is somehow feeding in the paste text, treating newlines as a ctrl+enter key press, thus it is ignoring it because of that ctrl modifier.

@pboling
Copy link
Author

pboling commented Dec 23, 2024

I haven't seen that on Mac, no.

@curlpipe
Copy link
Owner

curlpipe commented Dec 23, 2024

Ok, so I might have found the error.

Ox always enables something called bracketed paste, which helps speed up pasting and prevents weird behaviour.

Not all terminals support bracketed paste, but strangely, when alacritty on windows doesn't support it, and it is enabled, it messes with pasted \n characters by making them show up as ctrl+enter instead of enter, Ox thinks "ctrl+enter" is a key binding, not a newline, so it doesn't insert it into the document.

Luckily, when I don't enable bracketed paste on alacritty, \n shows up as enter, which is exactly what it should show up as, and will be placed into the document.

I'll open an issue in the crossterm crate (what Ox uses for terminal interaction) to see if they have any information as to whether this is a bug with crossterm, or just a weird quirk of terminals.

If that doesn't lead to anything I might be able to work out a way to intelligently switch it off if it detects it isn't working, thus restoring normal paste behaviour on systems where bracketed paste is not supported.

@curlpipe
Copy link
Owner

curlpipe commented Dec 23, 2024

On further research, I found some existing issues that are related to this:

This one indicates that some terminals send \r instead of \n:
crossterm-rs/crossterm#780

This one hints at the issue I discovered in my previous comment - windows doesn't support it at all anyway, so it might as well be completely disabled on windows:
crossterm-rs/crossterm#737

So there might be 2 different issues at play here. Very interesting.

So I will implement 2 fixes:

  • I will simply replace all \r with \n in the paste handler
  • On windows, I will disable bracketed paste

hopefully these work?

@curlpipe
Copy link
Owner

Issue opened here crossterm-rs/crossterm#962

@pboling
Copy link
Author

pboling commented Dec 23, 2024

Looking forward to testing it out!

@curlpipe
Copy link
Owner

curlpipe commented Dec 24, 2024

These changes should be published with 0.7.6

Let me know if they work!

I'll keep this issue open until everything works 100% 👍

@pboling @kachick

@kachick
Copy link

kachick commented Dec 24, 2024

Thank you for the ⚡ quick fix!
It looks like working with Windows Terminal, alacritty and kitty 🎉

@pboling
Copy link
Author

pboling commented Dec 24, 2024

Not available in homebrew yet, but will try it when it is!

https://formulae.brew.sh/formula/ox

Update:

brew unlink ox
brew install ox --HEAD
# ...
==> Cloning https://github.com/curlpipe/ox.git
Cloning into '/Users/pboling/Library/Caches/Homebrew/ox--git'...
# ... Dependencies ... blah blah blah
==> Installing ox --HEAD
==> cargo install
# ...
Removing: /Users/pboling/Library/Caches/Homebrew/ox_bottle_manifest--0.7.5... (7.2KB)
Removing: /Users/pboling/Library/Caches/Homebrew/ox--0.7.5... (1.8MB)

@pboling
Copy link
Author

pboling commented Dec 24, 2024

❯ ox -v
0.7.6

Working for me! I can paste multi-line.

@curlpipe
Copy link
Owner

Fantastic news! 🎉 Thank you to you both for your help.

Happy editing!

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

No branches or pull requests

3 participants