adsr / mle

flexible terminal-based text editor (C)
Apache License 2.0
827 stars 53 forks source link

Block edit and overtype #50

Closed smartmic closed 1 year ago

smartmic commented 3 years ago

By using drop cursor column and anchor it is possible to select a rectangluar area. It would be great if I can filter only this specific column selection through a shell command but currently this did not work for me. While cat worked as expected, sort just inserts (multi) newlines and other commands fail completely. Also, copying such blocks and pasting them somewhere else yields to strange results (no linebreaks, mixed order). I must admit, multi-cursor editing is new to me, so maybe I just did it wrong?

My typical use case here is doing quick calculations/aggregations with e.g. awk for certain columns holding numbers in text tables.

Is there a way to do this or will be possible in the future?

adsr commented 3 years ago

Hi @smartmic I have a block select implementation on a branch somewhere, but never merged it because it did not feel very elegant. I would like to take it in a different direction, specifically to combine it with a replace (overtype) mode, which is also currently lacking from mle:

Curious to hear your thoughts on this. It is a very broad change so I'm sure there will be bugs. I would want to flag it as experimental for at least a version or two.

By the way, to clarify what is going on with your example, using cmd_drop_cursor_column then cmd_toggle_anchor results in N selections, one per line. If you then use cmd_shell in this state, the command will run multiple times applied to each selection individually. For the type of thing you want to do, this approach does not work. To get back to one cursor from there, use cmd_remove_extra_cursors.

smartmic commented 3 years ago

Thanks, @adsr for sharing your ideas. Since I am not used to multi cursor editing, my first thought was: deleting a selected block should really delete the text and not fill up the selection with white space. But after some reflection, I agree, this can be done with multiple cursors. And your idea to preserve the text shape while in block mode makes sense. So yes, the whole mode description sounds very compelling to me.

Maybe it makes sense to add a function so that one can easily switch to multiple cursor if in block mode (and back), e.g. if one decides to insert, delete etc. instead of replace? I think a challenge will be the distinction between multiple (column) cursors and block mode, both should not overlap in functionality and confuse the user. With your suggestion, I think this is solved really elegantly. And I have a reason to look forward to sending the block selection to shell ;)

adsr commented 3 years ago

I recorded a short demo here https://webm.red/view/vAdy.webm. I still don't like the implementation as it required a bunch of if (is_block) ... special cases. I'll explore writing individual cmd_block_(cut|copy|paste|shell) commands next. While not perfectly correct or consistent, it is way simpler.

smartmic commented 3 years ago

Looks great in the demo! Can we try it out already?

adsr commented 2 years ago

I haven't come up with a satisfying implemenation for this. I do think it'd be useful however and remains on the backlog.

adsr commented 1 year ago

Added in bffa40f. insert (by default) toggles block mode.