Closed smartmic closed 1 year 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:
cmd_toggle_block
which toggles a new field cursor_t/mark_t.is_block
.is_block==1
:
cmd_replace
, cmd_insert_data
(newlines, auto-indent), and any other stuff that does not respect the block illusion.is_block==1 && is_anchored==1
(block select):
mark_*
and cursor_*
functions for block select. At the very least this will be all mark_*between*
and mark_insert|delete|replace*
functions. Any intent to delete should instead replace with whitespace. (For example, cmd_cut
should replace with whitespace instead of deleting text.) Inserting content with newlines, for example with cmd_uncut
, should block paste instead of pasting as normal.cmd_swap_anchor
which swaps the cursor's mark with its anchor. (This is the equivalent of o
in vim's visual block mode.)is_block==0
cursors and 1 big is_block==1
cursor.is_block
.is_block==1
cursors should be possible, which will be fun to show off at least.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
.
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 ;)
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.
Looks great in the demo! Can we try it out already?
I haven't come up with a satisfying implemenation for this. I do think it'd be useful however and remains on the backlog.
Added in bffa40f. insert
(by default) toggles block mode.
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?