micro icon indicating copy to clipboard operation
micro copied to clipboard

Shift+Del adds characters in text

Open skontar opened this issue 9 years ago • 17 comments

I have recently discovered that Control+Ins, Shift+Del, and Shift+Ins works as expected (copy, cut and paste) which is nice touch! However, Shift+Del also adds [3;2~ text in the text buffer.

Commit hash: 8f06e51 OS: Fedora 24 Terminal: xfce4-terminal

skontar avatar Sep 12 '16 11:09 skontar

incase anyone starts looking into this:

tcell doesn't recognise the (shift/control)+del escape sequences ("\x1b[3:2~", "\x1b[3:5~") for X terms (xterm, kterm, gnome-term)

http://www.manmrk.net/tutorials/ISPF/XE/xehelp/html/HID00000579.htm

For unrecognised escapes, it strips the escape char and sends the sequence as a 'paste' event to the application: https://github.com/zyedidia/tcell/blob/master/tscreen.go#L1206

on micro's end, we can catch the escape sequence and interpret it manually, but this seems hacky

scyptnex avatar Oct 05 '16 01:10 scyptnex

@scyptnex Interesting. You say that the tcell does not recognize that escape sequence. How come that micro does the right thing on both shortcuts then?

skontar avatar Oct 05 '16 22:10 skontar

The fact that it works is actually kind of interesting:

  • neither ctl+ins nor shift+del actually copies text, but you probably had to select text (with your mouse or shift+arrows), which copies the text to the system keyboard.
  • shift+del and ctl+del both cause an EventPaste to fire in tcell, so they may look like cuts, because they remove the selected text (and that text was copied to system clipboard when you selected it). Actually what they are doing is pasting the unrecognised escape sequence over the selected text.
  • shift+ins causes a bracketed paste to occur (in tcell), but on my version (i dont have clipboard support) it should paste the internal clipboard, but instead it actually does get paste text from the system keyboard (so my shift+ins pastes a different thing to my middle-click/ctl+v).

Ive looked at the tcell (and termbox-go) libraries and both of them fail miserably to recognise shift/control + ins/del combos. termbox-go has a little 'keyboard' demo, which tells me that when i press "ctrl+del" it thinks ive pressed "shift+~", i.e. the last character in the sequence [3:2~:

go get github.com/nsf/termbox-go
cd $GOPATH/src/github.com/nsf/termbox-go
go run _demos/keyboard.go

scyptnex avatar Oct 05 '16 23:10 scyptnex

@zyedidia

i have made a pull request in gdamore/tcell which fixes this.

We can either wait for them to merge and then you can pull it to your fork, or i can make a pull request to your fork of tcell directly.

scyptnex avatar Oct 07 '16 04:10 scyptnex

I was trying to bind CtrlDelete and it did not work pasting [3;5~ instead. The research into the issue led me here. I was wondering if there has been any progress in getting the fix merged into the editor. micro is the editor I have been waiting for as I really just want to use a linux editor that I don't have to retrain my Windows muscle memory for like I would have to for emacs and vi.

WingGithub avatar Mar 11 '17 15:03 WingGithub

Hi, any news on this? I’m stuck not being able to bind Ctrl-Delete in Micro (even though I can in my shell).

ariasuni avatar Dec 31 '18 16:12 ariasuni

Maybe at some point tcell will support these events (or I'll implement it in my fork of tcell). Currently though, if you want this to work you would need to use micro's raw events. I would suggest running > raw in micro and pressing Ctrl-Delete to see what escape sequence is sent (and if your terminal even supports it). Then bind that escape sequence as a raw event (I think > help keybindings has a section on binding raw escape sequences).

zyedidia avatar Dec 31 '18 19:12 zyedidia

I managed to do it, thank you!

fish_key_reader reports \e\[3\;5~ for Ctrl-Delete but that didn’t work; > raw reported \x1b[3;5~ and that worked.

ariasuni avatar Jan 01 '19 17:01 ariasuni

So should Ctrl+Ins (copy) & Shift+Ins (paste) be working or not? Currently (Win, 2.0.2) they don’t.

sergeevabc avatar Feb 26 '20 20:02 sergeevabc

Is this issue still observed by anyone with a recent version of micro?

Shift-Del works fine for me with the newest micro.

dmaluka avatar Apr 14 '24 23:04 dmaluka

Is this issue still observed by anyone with a recent version of micro? Shift-Del works fine for me with the newest micro.

I don't know where to get the newest binary for Windows, but neither Ctrl+Ins (to copy) nor Shift+Del (to delete) work with Micro 2.0.14-dev.8 622c4d0c 2024-02-14.

sergeevabc avatar Apr 15 '24 11:04 sergeevabc

Ok, 2.0.14-dev.8 is new enough.

The original issue was reported for Linux, and was not just about copy/cut/paste not working but about Shift+Del unexpectedly inserting some characters (i.e. about Shift+Del event not handled properly). I'm not seeing that specific issue in Linux on a recent micro: Shift+Del doesn't insert any unexpected characters, and also when run raw command in micro and press Shift+Del, it shows that micro successfully receives and recognizes Shift-Delete event.

So the issue you are seeing may be a different issue and may be Windows specific. What do you see if you run raw command and then press Ctrl+Ins or Shift+Del?

(Note also that even if Shift+Del works, it doesn't do anything by default, and that is expected, since Shift+Del is not among the default keybindings (see help defaultkeys). But if you run bind Shift-Delete Cut or manually add "Shift-Delete": "Cut" to bindings.json, then Shift+Del will cut text.)

dmaluka avatar Apr 15 '24 13:04 dmaluka

I launch micro.exe, then type hello, select it and press Ctrl+C, then press Enter to go to the next line and press Ctrl+V. It works as expected, since hello is pasted. Now I type bye, select it and press Ctrl+Ins, then ... Shift+Ins and get hello again, so Ctrl+Ins does not work in my case.

sergeevabc avatar May 13 '24 13:05 sergeevabc

Could you run the raw command in micro? (i.e. press Ctrl+E, type raw in the command prompt, and press Enter) After you run it, what does it show when you press Ctrl+Ins and Shift+Ins?

dmaluka avatar May 13 '24 15:05 dmaluka

After you run it, what does it show when you press Ctrl+Ins and Shift+Ins?

2024-0513-2042 micro ctrlshiftins

  • Ctrl+Ins, see line 1, nothing happens
  • Shift+ins, see lines 2-4, pastes the contents of the clipboard which is “abc”

sergeevabc avatar May 13 '24 17:05 sergeevabc

Ok, I think it's clear what's going on: both Ctrl+Ins and Shift+Ins work, but since Ctrl+Ins is not bound to any action by default, it does nothing.

Could you run the following command:

bind Ctrl-Insert Copy

and check if it works after that?

dmaluka avatar May 13 '24 17:05 dmaluka

Yes, Dmitry, it works as expected after binding.

sergeevabc avatar May 13 '24 18:05 sergeevabc