zsh-workers
 help / color / mirror / code / Atom feed
From: Samy Dulor <samy.dulor@orange.fr>
To: zsh-workers@zsh.org
Subject: Re: [BUG] complist interactive mode overwrites command line
Date: Mon, 4 Mar 2024 02:44:14 +0100	[thread overview]
Message-ID: <90469bbe-acdf-6dad-baaa-fbf3d1e7ed6c@orange.fr> (raw)
In-Reply-To: <CAHLkEDtHWh46ViP3LCd82E6YWujBKZTx-qLt18+QPqWwFe34jA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2371 bytes --]


On 04/08/2021 18:30, Marlon Richert wrote:
> % zmodload zsh/complist
> % bindkey '^I' menu-select
> % MENUMODE=interactive
> % touch test{1,2}
> % : ; foobar
>      ^ 1. Type the above line in its entirety.
>        2. Place the cursor before the ;
>        3. Press Tab.
>        4. Press Enter.
> % : test1 bar
>      ^ Completion is written over existing buffer contents.


Hello,

I think I have an acceptable solution to this issue, although I’m quite 
unaware of all the intricacies of the Zsh source code,
and had 0 knowledge of Zsh internals until 2 days ago...
All I can say is that it doesn’t cause the tests to fail,
And that after a day of usage it doesn’t seem to break anything else (in 
my limited use-cases).

Basically, when entering an interactive select completion menu, the 
first completion in the list gets “selected” (it’s highlighted) but not 
inserted in the command line.
In the above test case, that would be “test1”.
At that time, compresult.c:do_single was called with “test1” completion, 
then complist.c:domenuselect restored the command line to its original 
content.
That means the minfo struct was updated by do_single. In that case, we 
would get minfo { .len = 5, .end = 7 }.

When leaving the interactive mode (pressing Enter to accept the first 
completion, or selecting another completion like using arrow keys),
minfo.lencharacters are removed to “insert the next” completion (5 
characters, but in fact our command line is still “: ; foobar”, so only 
1 character should be erased).

So I just tried fixing it by correcting the values in minfo when 
domenuselect restores the command line content,
Which seems to me, is what should happen as far as I understand :

diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 9cb89a60d..f2eb3837d 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -2443,6 +2443,8 @@ domenuselect(Hookdef dummy, Chdata dat)
              strncpy(zlemetaline, origline, l);
              zlemetacs = origcs;
              setmstatus(status, NULL, 0 , 0, NULL, NULL, NULL);
+           minfo.len = origlpre;
+           minfo.end = minfo.pos + minfo.len;
          } else if (strpfx("search", s)) {
              mode = (strstr(s, "back") ? MM_BSEARCH : MM_FSEARCH);
          }

[-- Attachment #2: Type: text/html, Size: 4073 bytes --]

  reply	other threads:[~2024-03-04  1:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04 16:30 Marlon Richert
2024-03-04  1:44 ` Samy Dulor [this message]
2024-03-04  2:05   ` Bart Schaefer
2024-03-04  6:33     ` Bart Schaefer
2024-03-04 11:30       ` Samy Dulor
2024-03-04 22:38         ` Bart Schaefer
     [not found] <8964126.CDJkKcVGEf.ref@phy-nordri>
2022-07-15 13:39 ` Andrea Manenti
2022-07-16 18:11   ` Bart Schaefer
2022-07-16 22:57     ` Bart Schaefer
     [not found]       ` <2844417.e9J7NaK4W3@phy-nordri>
2022-07-22 16:32         ` Bart Schaefer
2022-07-22 17:55           ` Bart Schaefer
2022-07-22 18:23             ` Bart Schaefer
2022-07-22 19:10               ` Andrea Manenti
2023-11-17  3:35     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=90469bbe-acdf-6dad-baaa-fbf3d1e7ed6c@orange.fr \
    --to=samy.dulor@orange.fr \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).