randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.39k stars 82 forks source link

Select & Delete text feature #28

Open brupelo opened 6 years ago

brupelo commented 6 years ago

Terminals like conemu allows you to select & delete text quite easily, example here, any chance to implement it on terminus?

randy3k commented 6 years ago

Are you running cmd.exe?

randy3k commented 6 years ago

I guess we just need to implement ctrl+home and ctrl+end.

Ps: closed by accident

randy3k commented 6 years ago

7dd50b7 add ctrl+home and ctrl+end ultilities to remove text.

brupelo commented 6 years ago

Are you running cmd.exe?

You mean in the posted video? Yeah, that one was recorded spawning cmd on top of conemu.

I've pulled master and tried the new shortcuts... mmm... how difficult would be to implement something like this?

randy3k commented 6 years ago

In theory, it is doable. The implementation won't be standard, so there are a few things that we need to address. What if the selected text is read-only? How conemu handles it? Does it only delete text in the current line?

brupelo commented 6 years ago

Mmm, it seems conemu has 2 section modes:

1) When using shift+arrow_keys it seems internally conemu is detecting what's readonly and non-readonly 2) Selection mode is made with the mouse, in this case it seems Conemu wont' allow to delete any kind of text.

Here's a little demo... In any case, maybe terminus could do much better as SublimeText text management is much better than conemu's one. Guess the idea will be to figure out which parts of the view are editable and which ones are not. For instance:

In fact, maybe it's a matter of knowing all the time what are these 2 regions, ie:

funny_explanation

I guess if were able to track from the very beginning the intersection point to discard non-readonly content you'd be able to use the whole SublimeText power to manage/edit views really well... even using multiselection would become feasible... :)

Dunno, maybe just talking nonsense... in any case, you're the expert here so you'll know the best way to tackle this useful feature.

randy3k commented 6 years ago

It looks more tricky than I originally thought. Your best bet for now is to use ctrl+arrow, ctrl+backspace, ctrl+delete and ctrl+home/end.

cow1337killer3 commented 3 months ago

The only real way to do this is to have an intercepting process that relays input/output between the underlying terminal and a Sublime view/display panel with a text input that's debounced to receive autocompletions. Then you delete the selection from the Sublime input panel.

conemu doesn't even do that, so it's limited to being able to delete input buffer text that's manually selected with selection shortcut keys. A terminal actually has 2 selections. You can use the mouse to select any text in the window, including history + input line. Or you can use shortcut keys/commands to select a portion of the input line only. I don't think there's any current way, in any terminal, to retrieve the window mouse selection. You can only copy it to the clipboard. And even then, you don't know the coordinates of the text that was copied... so you could have copied "xyz", but the history + input line could be:

downloads> xyz xyz
Unknown command: xyz
downloads> xyz xyz█

You can easily do what conemu does in PowerShell 7 with PSReadLine. But that's still not a good solution because you have to manually designate the cursor selection on the input line and can't just select it with the mouse.

But I honestly think the intercept/relay text panel is a great idea. Then we can have all of our own customized text editing shortcuts from Sublime. Along with replacing selection with chars/pasted text. Terminal editing is so archaic I can't believe nobody's done this yet.

PSReadLine is very very powerful. You can basically map any key combination to a function. I have Ctrl+Left mapped to cd to parent directory, Ctrl+Right mapped to cd to the first child directory, Ctrl+Up/Down cds to the previous/next sibling directory. But it has no window selection features unfortunately.