Skip to content

Conversation

@girishji
Copy link
Contributor

Refactor

  • Simplified and rewrote horizontal positioning logic (was overly complex).
  • Split horizontal and vertical positioning into separate functions.

Bug fixes

  • Fixed missing truncation marker (e.g. >) when items were truncated and pummaxwidth was not set.
  • Fixed occasional extra space being added to menu items.

- Simplified and rewrote horizontal positioning logic (was overly
  complex).
- Split horizontal and vertical positioning into separate functions.
- Fixed missing truncation marker (e.g. >) when items were truncated and
  pummaxwidth was not set.
- Fixed occasional extra space being added to menu items.
M  src/popupmenu.c
M  src/testdir/test_popupwin.vim
M  src/testdir/test_popupwin.vim
@girishji
Copy link
Contributor Author

Test_popupwin_infopopup_6.dump and Test_popupwin_infopopup_7.dump are already incorrect:
they show the info window but not the popup menu.

This issue occurs only in the test; I cannot reproduce it otherwise.
In Test_popupmenu_info_border(), setting of pumheight=3 causes the problem.
Without pumheight, the popup menu displays correctly, but pumheight is needed for the test.

If anyone has suggestions, please let me know.
Otherwise I’ll work around it by adding :set completepopup=border:off, which avoids the issue.

`Test_popupwin_infopopup_6.dump` and `Test_popupwin_infopopup_7.dump` are
already incorrect: they show the info window but not the popup menu.

This issue occurs only in the test; I cannot reproduce it otherwise.
In `Test_popupmenu_info_border()`, setting of `pumheight=3` causes the
problem. Without `pumheight`, the popup menu displays correctly, but
`pumheight` is needed for the test.

Work around is to add `:set completepopup=border:off` to failing tests.
@chrisbra
Copy link
Member

chrisbra commented Oct 1, 2025

thanks

@chrisbra chrisbra closed this in e3ed558 Oct 1, 2025
@girishji
Copy link
Contributor Author

girishji commented Oct 2, 2025

thanks.

@girishji girishji deleted the refactor branch October 2, 2025 05:38
@zeertzjq
Copy link
Member

zeertzjq commented Oct 2, 2025

This regresses the following change from #17081:

diff --git a/src/testdir/dumps/Test_pum_maxwidth_07.dump b/src/testdir/dumps/Test_pum_maxwidth_07.dump
index ada8acb0d..112e1f588 100644
--- a/src/testdir/dumps/Test_pum_maxwidth_07.dump
+++ b/src/testdir/dumps/Test_pum_maxwidth_07.dump
@@ -1,7 +1,7 @@
 |1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_> @44
 |1+0#0000001#e0e0e08|2|3|4|5|6|7|8|9|>| +0#4040ff13#ffffff0@64
 |一*0#0000001#ffd7ff255|二|三|四| +&|>| +0#4040ff13#ffffff0@64
-|a+0#0000001#ffd7ff255|b|c|d|e|f|g|h|i|>| +0#4040ff13#ffffff0@64
+|a+0#0000001#ffd7ff255|b|c|d|e|f|g|h|i|j| +0#4040ff13#ffffff0@64
 |上*0#0000001#ffd7ff255|下|左|右| +&@1| +0#4040ff13#ffffff0@64
 |~| @73
 |~| @73
diff --git a/src/testdir/dumps/Test_pum_maxwidth_08.dump b/src/testdir/dumps/Test_pum_maxwidth_08.dump
index aa41b76d1..9f92ae706 100644
--- a/src/testdir/dumps/Test_pum_maxwidth_08.dump
+++ b/src/testdir/dumps/Test_pum_maxwidth_08.dump
@@ -1,7 +1,7 @@
 | +0&#ffffff0@43> |_|9|8|7|6|5|4|3|2|1|_|9|8|7|6|5|4|3|2|1|_|9|8|7|6|5|4|3|2|1
 | +0#4040ff13&@64|<+0#0000001#e0e0e08|9|8|7|6|5|4|3|2|1
 | +0#4040ff13#ffffff0@64|<+0#0000001#ffd7ff255| |四*&|三|二|一
-| +0#4040ff13#ffffff0@64|<+0#0000001#ffd7ff255|i|h|g|f|e|d|c|b|a
+| +0#4040ff13#ffffff0@64|j+0#0000001#ffd7ff255|i|h|g|f|e|d|c|b|a
 | +0#4040ff13#ffffff0@64| +0#0000001#ffd7ff255@1|右*&|左|下|上
 | +0#4040ff13#ffffff0@73|~
 | @73|~

Now abcdefghij is truncated even though it fits within 'pummaxwidth'.

@girishji
Copy link
Contributor Author

girishji commented Oct 2, 2025

There’s currently an extra space (or truncation character) after each item. If j is included, that space won’t appear. I wasn’t entirely sure how to handle this, but since pummaxwidth is set to 10, I think it’s fine to skip the extra space. I’ll address this in a separate PR.

@zeertzjq
Copy link
Member

zeertzjq commented Oct 2, 2025

The regression is more obvious in the right-click menu (seen in the two Test_mouse_popup_position dumps in this PR, where the last character of the longest menu item is truncated). The following script (where all menu items has the same length) makes it even more obvious:

menu PopUp.aaaaaaaaaafoo :echo 'foo'<CR>
menu PopUp.bbbbbbbbbbfoo :echo 'foo'<CR>
menu PopUp.ccccccccccfoo :echo 'foo'<CR>
set mousemodel=popup

Right click near the right edge of the window, and you'll see that all of them are truncated at the last character:
Screenshot

@girishji
Copy link
Contributor Author

girishji commented Oct 2, 2025

It's the same issue. I think removing - 1 will fix this.

    truncated = width_limit - totwidth - 1 < cells + pad;

girishji added a commit to girishji/vim that referenced this pull request Oct 3, 2025
This PR introduces a new global option, `'pumborder'` (`'pb'`), that allows
users to define borders and optional decorations for the completion popup
menu.

```
						*'pumborder'* *'pb'*
'pumborder' 'pb'	number	(default 0)
			global
	Defines a border and optional decorations for the popup menu in
	completion.  The value is a comma-separated list of keywords.

	Border styles (at most one):
	"single"	use thin box-drawing characters
	"double"	use double-line box-drawing characters
	"round"		use rounded corners
	"ascii"		use ASCII characters (-, |, +)
	"custom:XXXXXXXX"
			use eight characters given after "custom:",
			in order: top, right, bottom, left,
			topleft, topright, botright, botleft

	Additional flags:
	"margin"	adds one-cell spacing inside the left and right border
	"shadow"	draws a shadow at the right and bottom edges

	Highlight groups:
	|hl-PmenuBorder|	used for the border characters
	|hl-PmenuShadow|	used for the shadow

	Examples: >
		:set pumborder=single
		:set pumborder=double,margin,shadow
		:set pumborder=custom:─│─│┌┐┘└,shadow
<
	Border styles using box-drawing characters ("single", "double",
	"round") are only available when |'encoding'| is "utf-8" and
	|'ambiwidth'| is "single".  "margin" requires a border style.
	See also: |ins-completion-menu|.
```

Also, fixes vim#18441 (comment)

*(Add screenshot)*
girishji added a commit to girishji/vim that referenced this pull request Oct 4, 2025
This PR introduces a new global option, `'pumborder'` (`'pb'`), that allows
users to define borders and optional decorations for the completion popup
menu.

```
						*'pumborder'* *'pb'*
'pumborder' 'pb'	number	(default 0)
			global
	Defines a border and optional decorations for the popup menu in
	completion.  The value is a comma-separated list of keywords.

	Border styles (at most one):
	"single"	use thin box-drawing characters
	"double"	use double-line box-drawing characters
	"round"		use rounded corners
	"ascii"		use ASCII characters (-, |, +)
	"custom:XXXXXXXX"
			use eight characters given after "custom:",
			in order: top, right, bottom, left,
			topleft, topright, botright, botleft

	Additional flags:
	"margin"	adds one-cell spacing inside the left and right border
	"shadow"	draws a shadow at the right and bottom edges

	Highlight groups:
	|hl-PmenuBorder|	used for the border characters
	|hl-PmenuShadow|	used for the shadow

	Examples: >
		:set pumborder=single
		:set pumborder=double,margin,shadow
		:set pumborder=custom:─│─│┌┐┘└,shadow
<
	Border styles using box-drawing characters ("single", "double",
	"round") are only available when |'encoding'| is "utf-8" and
	|'ambiwidth'| is "single".  "margin" requires a border style.
	See also: |ins-completion-menu|.
```

Also, fixes vim#18441 (comment)
chrisbra pushed a commit that referenced this pull request Oct 7, 2025
Problem:  not possible to style popup borders globally
Solution: Add the 'pumborder' option (Girish Palya)

This commit introduces a new global option, 'pumborder' ('pb'), that
allows users to define borders and optional decorations for the
completion popup menu.

```
Defines a border and optional decorations for the popup menu in
completion.  The value is a comma-separated list of keywords.

Border styles (at most one):
"single"singleuse thin box-drawing characters
"double"doubleuse double-line box-drawing characters
"round"rounduse rounded corners
"ascii"asciiuse ASCII characters (-, |, +)
"custom:XXXXXXXX"
    use eight characters given after "custom:",
    in order: top, right, bottom, left,
    topleft, topright, botright, botleft

Additional flags:
"margin"marginadds one-cell spacing inside the left and right border
"shadow"shadowdraws a shadow at the right and bottom edges

Highlight groups:
|hl-PmenuBorder|hl-PmenuBorderused for the border characters
|hl-PmenuShadow|hl-PmenuShadowused for the shadow

Examples: >
  :set pumborder=single
  :set pumborder=double,margin,shadow
  :set pumborder=custom:─│─│┌┐┘└,shadow

Border styles using box-drawing characters ("single", "double",
"round") are only available when |'encoding'| is "utf-8" and
|'ambiwidth'| is "single".  "margin" requires a border style.
See also: |ins-completion-menu|.
```

fixes: #18441 (comment)
closes: #18486
closes: #17091

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
bennyyip pushed a commit to bennyyip/vim that referenced this pull request Oct 7, 2025
Problem:  not possible to style popup borders globally
Solution: Add the 'pumborder' option (Girish Palya)

This commit introduces a new global option, 'pumborder' ('pb'), that
allows users to define borders and optional decorations for the
completion popup menu.

```
Defines a border and optional decorations for the popup menu in
completion.  The value is a comma-separated list of keywords.

Border styles (at most one):
"single"singleuse thin box-drawing characters
"double"doubleuse double-line box-drawing characters
"round"rounduse rounded corners
"ascii"asciiuse ASCII characters (-, |, +)
"custom:XXXXXXXX"
    use eight characters given after "custom:",
    in order: top, right, bottom, left,
    topleft, topright, botright, botleft

Additional flags:
"margin"marginadds one-cell spacing inside the left and right border
"shadow"shadowdraws a shadow at the right and bottom edges

Highlight groups:
|hl-PmenuBorder|hl-PmenuBorderused for the border characters
|hl-PmenuShadow|hl-PmenuShadowused for the shadow

Examples: >
  :set pumborder=single
  :set pumborder=double,margin,shadow
  :set pumborder=custom:─│─│┌┐┘└,shadow

Border styles using box-drawing characters ("single", "double",
"round") are only available when |'encoding'| is "utf-8" and
|'ambiwidth'| is "single".  "margin" requires a border style.
See also: |ins-completion-menu|.
```

fixes: vim#18441 (comment)
closes: vim#18486
closes: vim#17091

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 8, 2025
Problem:  popup: there are some position logic bugs
Solution: Refactor position logic and fix a few bugs
          (Girish Palya).

This change does the following:

- Simplified and rewrote horizontal positioning logic (was overly
  complex).
- Split horizontal and vertical positioning into separate functions.
- Fixed missing truncation marker (e.g. `>`) when items were truncated
  and `pummaxwidth` was not set.
- Fixed occasional extra space being added to menu items.
- Update tests

closes: vim/vim#18441

vim/vim@e3ed558

Cherry-pick pum_display_{rtl,ltr}_text() changes from patch 9.1.1835.

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 8, 2025
Problem:  popup: there are some position logic bugs
Solution: Refactor position logic and fix a few bugs
          (Girish Palya).

This change does the following:

- Simplified and rewrote horizontal positioning logic (was overly
  complex).
- Split horizontal and vertical positioning into separate functions.
- Fixed missing truncation marker (e.g. `>`) when items were truncated
  and `pummaxwidth` was not set.
- Fixed occasional extra space being added to menu items.
- Update tests

closes: vim/vim#18441

vim/vim@e3ed558

Cherry-pick pum_display_{rtl,ltr}_text() changes from patch 9.1.1835.

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request Oct 8, 2025
Problem:  popup: there are some position logic bugs
Solution: Refactor position logic and fix a few bugs
          (Girish Palya).

This change does the following:

- Simplified and rewrote horizontal positioning logic (was overly
  complex).
- Split horizontal and vertical positioning into separate functions.
- Fixed missing truncation marker (e.g. `>`) when items were truncated
  and `pummaxwidth` was not set.
- Fixed occasional extra space being added to menu items.
- Update tests

closes: vim/vim#18441

vim/vim@e3ed558

Cherry-pick pum_display_{rtl,ltr}_text() changes from patch 9.1.1835.

Co-authored-by: Girish Palya <girishji@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants