Skip to content

Conversation

@glepnir
Copy link
Member

@glepnir glepnir commented Apr 8, 2025

Problem: Popup menu had memory alloc and incorrect truncation logic.

Solution: Replaced string allocation with direct screen rendering and fixed RTL/LTR truncation calculations.

Problem: Popup menu had memory alloc and incorrect truncation logic.

Solution: Replaced string allocation with direct screen rendering and fixed RTL/LTR truncation calculations.
@h-east
Copy link
Member

h-east commented Apr 9, 2025

@glepnir
Stop hiding threads that aren't yet resolved by marking them as "Resolved".

#17081 (comment)

@h-east
Copy link
Member

h-east commented Apr 9, 2025

Note: Tested on the latest master branch, not this PR.

Is this Bug?

$ cat test.vim
func Omni_test(findstart, base)
  if a:findstart
    return col(".")
  endif
  return [
    \ #{word: "foo", menu: "fooMenu", kind: "fooKind"},
    \ #{word: "bar", menu: "barMenu", kind: "barKind"},
    \ #{word: "baz", menu: "bazMenu", kind: "bazKind"},
    \ ]
endfunc
set omnifunc=Omni_test
set pummaxwidth=20
$ vim --clean -S test.vim -c 'call feedkeys("i\<C-X>\<C-O>")'

Result:

  • It's just the right width, but the trunc character is displayed.
    image

@glepnir
Copy link
Member Author

glepnir commented Apr 10, 2025

This is not reproducible on this PR. So why don't you test it with PR.

Stop hiding threads that aren't yet resolved by marking them as "Resolved".

Please search for the English meaning of fill, and then check the purpose of fcs. I don't think there is anything wrong with adding trunc here.

about you mean draw part i think you mean something like your commit 4c42c7e . you hardcode U+2026 then check encode and fallback to > when fail, In my opinion this is wrong design. Some string operations are slow and secondly why hardcode it. It should be configurable in vim itself. trunc solves this problem you can use it to refactor your before commit. I think it will be better.
I don't want to spend time discussing this. . If you have any questions, please open an issue to discuss. thanks

@h-east
Copy link
Member

h-east commented Apr 10, 2025

Stop hiding threads that aren't yet resolved by marking them as "Resolved".

Please search for the English meaning of fill, and then check the purpose of fcs. I don't think there is anything wrong with adding trunc here.

Please take a moment to calm down. You are not correctly understanding what I said. That's why it feels like you are wasting your time.
Please take a moment to calmly reread the following comment and the related responses.
#17006 (comment)

about you mean draw part i think you mean something like your commit 4c42c7e . you hardcode U+2026 then check encode and fallback to > when fail, In my opinion this is wrong design. Some string operations are slow and secondly why hardcode it. It should be configurable in vim itself. trunc solves this problem you can use it to refactor your before commit. I think it will be better.

I was not opposed to adding 'trunc' to the 'fcs' option. In fact, I am in favor of it.

I think is a good idea.

Again, I want to emphasize that I never said to hardcode it. I brought up the implementation location for the ellipsis character in textproperty only as reference information, and I do not recommend hardcoding.
#17006 (comment)

I only showed existing information regarding the text property issue, and I never once said to "hardcode it".

Also, it was my initial suggestion that the ellipsis character in textproperty should be able to use 'trunc' from the 'fcs' option.

I don't want to spend time discussing this. . If you have any questions, please open an issue to discuss. thanks

@chrisbra and ALL,
Is my English not getting through at all? Is it so poorly written that the meaning is being misunderstood?
I have been careful and thoughtful in my translations, but is it really that bad?

@h-east
Copy link
Member

h-east commented Apr 10, 2025

#17081 (comment)

What I am asserting in the comment above is as follows:

  • Is it not problematic that "trunc" in 'fcs' is referencing '>' within the popupmenu code?
  • Is it not problematic to change '>' to '<' within the popup menu code for 'rightLeft'? How about handling it in the processing of the 'fcs' option or in the drawing process (i.e., drawline.c)?

@glepnir
Copy link
Member Author

glepnir commented Apr 10, 2025

I have been careful and thoughtful in my translations, but is it really that bad?

Maybe I'm also using translation software so the tone may be ambiguous lol ?

Is it not problematic that "trunc" in 'fcs' is referencing '>' within the popupmenu code?

This is borrowed from the existing code. If the screen space is not enough, use >. RL uses <. So the default trunc symbol for fcs is >.. The truncation logic is here so truncation at a col can be handled directly by screen_put. Isn't it more troublesome for win_line to handle this? Can wlv handle pum code? rendering of pum is handled in the popupmenu. If you have better suggestions for the default value of trunc can change it in the subsequent PR. I have no opinion.

@h-east
Copy link
Member

h-east commented Apr 10, 2025

@glepnir
When you receive a suggestion like "What do you think?", I assume it's an invitation for discussion. However, you seem to misunderstand my intent and react in an extreme way, which ends up making me spend more time than necessary (bitter laugh).

There are times when your PR execution or specifications seem a bit off, so I comment to initiate a discussion. However, you often misunderstand my intent. I don’t think this is a matter of my English being unclear or anything like that. I'll consult with other maintainers, so if you don’t understand, there’s no need to force yourself to reply.

@h-east
Copy link
Member

h-east commented Apr 10, 2025

This is borrowed from the existing code. If the screen space is not enough, use >. RL uses <. So the default trunc symbol for fcs is >.. The truncation logic is here so truncation at a col can be handled directly by screen_put. Isn't it more troublesome for win_line to handle this? Can wlv handle pum code? rendering of pum is handled in the popupmenu. If you have better suggestions for the default value of trunc can change it in the subsequent PR. I have no opinion.

Yes, the translation is strange and it seems that you don't understand after all.

@chrisbra
Copy link
Member

Please calm down 🙏
Let's focus on improving this PR here. The drawing logic for the pum is in pum_display(), so it makes sense to flip the (default) character when drawing it (I should document it). Do we need this in drawline? I don't know, perhaps for some text properties, not sure here. Also we don't seem to handle flipping the character when using a custom trunc char (and this probably doesn't even make sense for other characters). Perhaps we need also a truncrl char specifically instead?

@glepnir
Copy link
Member Author

glepnir commented Apr 11, 2025

it seems that you don't understand after all.

To be honest, I really don't understand why the win_line function is not responsible for rendering the pum code. What can I do in drawline? pum is handled in popupmenu.c.

Also we don't seem to handle flipping the character when using a custom trunc char (and this probably doesn't even make sense for other characters). Perhaps we need also a truncrl char specifically instead?

There is no inversion for the text property of a single cell. It's just that we use it by default > it exists < as part. so check it here. This is also the way it was done before. truncrl maybe don't need. U+2026 is a good value of trunc.

@h-east
Copy link
Member

h-east commented Apr 11, 2025

@chrisbra
How about a proposal where 'rightleft' affects 'fillchars'?

Example:

:set fillchars=eob:~,trunc:> norightleft
:set fillchars? rightleft?
  fillchars=eob:~,trunc:>
norightleft

:set rightleft
:set fillchars?
  fillchars=eob:~,trunc:<

@chrisbra
Copy link
Member

I thought about it, but we would need to update fillchars whenever we set rightleft option for any window. And when we set fillchars option, need to check if rightleft needs is set. And need to make sure we handle it correctly if it is setup for one window but not for another.

And I am still not sure, if mirroring the trunc char makes sense in the general case. I would think it only makes sense for very specific characters, like > -> <, but probably not for all. So I thought a truncrl might be simpler.

@h-east

This comment was marked as off-topic.

@glepnir

This comment was marked as off-topic.

@chrisbra chrisbra closed this in d4dbf82 Apr 12, 2025
@chrisbra
Copy link
Member

Thanks all, especially for trying to stay professional 🙇

LuMarquesIlva pushed a commit to LuMarquesIlva/vim that referenced this pull request Apr 12, 2025
Problem:  completion: incorrect truncation logic (after: v9.1.1284)
Solution: replace string allocation with direct screen rendering and
          fixe RTL/LTR truncation calculations (glepnir)

closes: vim#17081

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
@zeertzjq
Copy link
Member

Do we need this in drawline? I don't know, perhaps for some text properties, not sure here.

And from #17006 (comment)

So like trunc: so that we can re-use this for all kinds of truncation variables

This may raise another question, because there are two types of truncation:

  1. Truncation of overlong text is what is mentioned in this PR
  2. Truncation of half of a double-width char at the window edge is a bit different

In drawline.c, apart from type 1 truncation of text properties, there is type 2 truncation of double-width chars, where < is used for truncation on the left and > is used for truncation on the right:

		// If a double-width char doesn't fit at the left side display
		// a '<' in the first column.  Don't do this for unprintable
		// characters.
		if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
		{
		    wlv.n_extra = 1;
		    wlv.c_extra = MB_FILLER_CHAR;
		    wlv.c_final = NUL;
		// If a double-width char doesn't fit at the left side display
		// a '<' in the first column.  Don't do this for unprintable
		// characters.
		if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
		{
		    wlv.n_extra = 1;
		    wlv.c_extra = MB_FILLER_CHAR;
		    wlv.c_final = NUL;

However, here the truncation character is not flipped when 'rightleft' is set, but < is used in drawline.c for truncation (type 2) on the left even without 'rightleft'.

And in screen.c, there is also > truncation character for truncation on the right:

		if (col + mbyte_cells > screen_Columns)
		{
		    // Only 1 cell left, but character requires 2 cells:
		    // display a '>' in the last column to avoid wrapping.
		    c = '>';
		    mbyte_cells = 1;
		}

Now, the question is whether the same 'fillchars' character(s) should be used for these two types of truncation, since some may think that an ellipsis makes sense for type 1 but not for type 2.

  • If yes, trunc and truncrl may have to be renamed to rtrunc and ltrunc, since < is used for type 2 trunction on the left even without 'rightleft'.
  • If no, two other 'fillchars' fields may need to be added in the future if one wants to configure type 2 truncation characters, and having 4 fields (e.g. trunc, truncrl, ltrunc and rtrunc) related to truncation will be a bit confusing.

@glepnir
Copy link
Member Author

glepnir commented Apr 12, 2025

makes sense. It's much more useful than some people's ridiculous remarks. ltrunc rtrunc seems good thanks @zeertzjq

zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Apr 15, 2025
Problem:  completion: incorrect truncation logic (after: v9.1.1284)
Solution: replace string allocation with direct screen rendering and
          fixe RTL/LTR truncation calculations (glepnir)

closes: vim/vim#17081

vim/vim@d4dbf82

Co-authored-by: glepnir <glephunter@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Apr 15, 2025
Problem:  completion: incorrect truncation logic (after: v9.1.1284)
Solution: replace string allocation with direct screen rendering and
          fixe RTL/LTR truncation calculations (glepnir)

closes: vim/vim#17081

vim/vim@d4dbf82

Co-authored-by: glepnir <glephunter@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Apr 16, 2025
Problem:  completion: incorrect truncation logic (after: v9.1.1284)
Solution: replace string allocation with direct screen rendering and
          fixe RTL/LTR truncation calculations (glepnir)

closes: vim/vim#17081

vim/vim@d4dbf82

Co-authored-by: glepnir <glephunter@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.

4 participants