Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Enable linewise edit-command when in visual-line
- X-seq: zsh-workers 52101
- From: Christoffer Lundell <christofferlundell@xxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] Enable linewise edit-command when in visual-line
- Date: Sun, 27 Aug 2023 11:38:55 +0000
- Archived-at: <https://zsh.org/workers/52101>
- Feedback-id: 3930316:user:proton
- In-reply-to: <CAH+w=7YVMoScFFsvycqZh5n5Eu2QiG4kBrxsHVOEEfNa5fD8gw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <PEEOyknRLLWFRjtZRcuxXrkHEqQYs6bxEPs_PEMqZNVbYD3QjR0HgbERrKA6gpZqMODFfgwDZMe6Nw2GM0f9JbtSN4bcaxrkp6bYsxTR7ZQ=@protonmail.com> <CAH+w=7aCqvj0p=9JBXwRiZNDeJdW0yrbvErciUqCATs0bMfUqA@mail.gmail.com> <XyFbtVQZPqS2ohsFK-alrnKKiX2lVU7t_wvfzgTHnSlUABXLKvdp7Bi4_97ZeDH0aUx7v_nd5MZwnTwKW6WwpimMnxRxsQDghQmZGRtjKfU=@protonmail.com> <CAH+w=7YVMoScFFsvycqZh5n5Eu2QiG4kBrxsHVOEEfNa5fD8gw@mail.gmail.com>
Thank you for your fast response, I did a bit of testing and have a couple
uncertainties that I hope you can assist me with.
> > > > + offset_right=${(SB)${BUFFER[mark_right+1,-1]}#$'\n'}
> > >
> > > This I'm not sure of -- why mark_right+1 ?
> >
> > This is because CURSOR and MARK are 0-indexed, according to zshzle(1).
>
> They're 0-based because position 0 represents an empty line, the
> non-character before $LBUFFER. The BUFFER and LBUFFER arrays
> themselves are still 1-indexed (unless you're crazed enough to be
> using zle with ksharrays).
> BUFFER[CURSOR] is always the character to the left of the visible
> cursor position. To make this work, CURSOR is decremented when
> entering vicmd mode (unless it's already zero), but that doesn't
> change MARK.
>
> So ... I think this means that in vi-cmd-mode it is necessary to use
> CURSOR+1 when MARK <= CURSOR, but not MARK+1 when CURSOR < MARK? And
> never add one when in emacs mode?
>
This makes me think I am missing something, because even when setting bindkey -e
in my .zshrc and entering visual-line-mode, a cursor/mark on column 1 on a 2nd
line to the right of the other cursor/mark never includes said 2nd line, despite
it being visually highlighted. That is, while using the suggested:
right=${${BUFFER[CURSOR,-1]}[(i)$nl]} for MARK <= CURSOR
and
right=${${BUFFER[MARK,-1]}[(i)$nl]} for CURSOR < MARK
I had to use CURSOR+1 and MARK+1 from the lines above to fix that edge case.
Which does not wrongfully include the following line when the cursor to the far
right of the first line in emacs mode, as might be expected.
> > lbuffer=$lbuffer[++left,-1]
>
> That's equivalent to lbuffer= when left=$CURSOR because by definition
> everything after LBUFFER[CURSOR] is empty (and lbuffer=$LBUFFER at
> that point). I believe ((right-left == left+1)) when right=$CURSOR,
> so should be a no-op compared to the original ((REGION_HIGHLIGHT ==
> 1)) case. Disagree?
You are right in that lbuffer= is equivalent for left=$CURSOR, however
lbuffer[right-left,-1]= leaves the leading part of $lbuffer intact even if the
visual selection does not start at the beginning of $BUFFER. And as I
understand, $lbuffer is supposed to represent only the highlighted text before
the cursor, to later figure out cursor positioning for the opened editor.
The only thing that has been working consistently, and what fixes cursor
positioning for me, is the previous:
lbuffer=${lbuffer[++left,-1]}
In both blocks for (( REGION_HIGHLIGHT == 1 )) and (( REGION_HIGHLIGHT == 2 ))
Please let me know if I am missing something.
Christoffer
Messages sorted by:
Reverse Date,
Date,
Thread,
Author