zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
25.13k stars 1.17k forks source link

Shift+Del adds characters in text #353

Open skontar opened 8 years ago

skontar commented 8 years ago

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

scyptnex commented 8 years ago

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

skontar commented 8 years ago

@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?

scyptnex commented 8 years ago

The fact that it works is actually kind of interesting:

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 commented 8 years ago

@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.

WingGithub commented 7 years ago

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.

ariasuni commented 5 years ago

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

zyedidia commented 5 years ago

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).

ariasuni commented 5 years ago

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.

sergeevabc commented 4 years ago

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

dmaluka commented 6 months ago

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

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

sergeevabc commented 6 months ago

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.

dmaluka commented 6 months ago

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.)

sergeevabc commented 5 months ago

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.

dmaluka commented 5 months ago

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?

sergeevabc commented 5 months ago

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

2024-0513-2042 micro ctrlshiftins

dmaluka commented 5 months ago

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?

sergeevabc commented 5 months ago

Yes, Dmitry, it works as expected after binding.