Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple text properties with 'text_align' right render on separate lines #10906

Closed
puremourning opened this issue Aug 13, 2022 · 6 comments
Closed
Labels

Comments

@puremourning
Copy link
Contributor

Steps to reproduce

hi SpellBad gui=underline cterm=underline
call prop_type_add( 'MyErrorText', #{ highlight: 'SpellBad' } )
" Used for padding - without error highlight
call prop_type_add( 'MyPadding', #{ highlight: 'Normal' } )
call prop_add( 6, 0, #{ type: 'MyPadding', text: '   ', text_wrap: 'wrap', text_align: 'right' } )
call prop_add( 6, 0, #{ type: 'MyErrorText', text: 'This is the error', text_wrap: 'wrap', text_align: 'right' } )
  • vim --clean test.vim test.vim
  • See that the 'This is the error' is rendered on the following line.

Screenshot 2022-08-13 at 13 54 38

I'm not sure this is strictly a bug (maybe a feature request?) but wanted to share the use case in case it's worth changing. I'm trying to implement some "padding" so that a diagnostic message rendered on the right of the screen is separated from the text, but without it having the "Error" formatting applied to it (in this case, SpellBad with underline). The error formatting applying to the 'text' attribute looks weird. Here's the above where the padding is just added as the text (like the docs suggest):

hi SpellBad gui=underline cterm=underline
call prop_type_add( 'MyErrorText', #{ highlight: 'SpellBad' } )
" Used for padding - without error highlight
" call prop_type_add( 'MyPadding', #{ highlight: 'Normal' } )
" call prop_add( 6, 0, #{ type: 'MyPadding', text: '   ', text_wrap: 'wrap', text_align: 'right' } )
call prop_add( 6, 0, #{ type: 'MyErrorText', text: '    This is the error', text_wrap: 'wrap', text_align: 'right' } )

Screenshot 2022-08-13 at 13 53 32

Expected behaviour

I was hoping to use an 'invisible' padding property with a different highlight such that the "padding" is inserted with Normal highlight, then the error with SpellBad highlight but all on the same line without the second property going on to a new line (unless it required for wrapping).

One option might be to have a pad-left and/or 'pad-right' option in the dict for virtual text properties; that would cover the use case and might be simpler to implement than "arbitrary" stacking.

Version of Vim

9.0.193

Environment

macOS arm64

Logs and stack traces

No response

@puremourning
Copy link
Contributor Author

PS. There is a workaround which is to make the 'padding' property "after" rather than "right":

hi SpellBad gui=underline cterm=underline
call prop_type_add( 'MyErrorText', #{ highlight: 'SpellBad' } )
" Used for padding - without error highlight
call prop_type_add( 'MyPadding', #{ highlight: 'Normal' } )
call prop_add( 6, 0, #{ type: 'MyPadding', text: '   ', text_wrap: 'wrap', text_align: 'after' } )
call prop_add( 6, 0, #{ type: 'MyErrorText', text: 'This is the error', text_wrap: 'wrap', text_align: 'right' } )

Screenshot 2022-08-13 at 13 59 11

so this isn't a huge deal.

@brammool
Copy link
Contributor

We can add a "padding" argument to the text property. It would add that many spaces, without highlighting, to the left of the text.

@puremourning
Copy link
Contributor Author

I have a use-case for padding on the right side too, where you have an inlay hint. In LSP, they have bools to say if the UI should render padding on left/right. so if it's simple enough to have padding-left/padding-right or for padding to be a list [ left, right ], that would be nice if it's not too much harder to implement.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint

	/**
	 * Render padding before the hint.
	 *
	 * Note: Padding should use the editor's background color, not the
	 * background color of the hint itself. That means padding can be used
	 * to visually align/separate an inlay hint.
	 */
	paddingLeft?: boolean;

	/**
	 * Render padding after the hint.
	 *
	 * Note: Padding should use the editor's background color, not the
	 * background color of the hint itself. That means padding can be used
	 * to visually align/separate an inlay hint.
	 */
	paddingRight?: boolean;
```

brammool added a commit that referenced this issue Aug 13, 2022
…texts

Problem:    Cursor position wrong with two right-aligned virtual texts.
Solution:   Add the padding for right-alignment. (issue #10906)
@brammool
Copy link
Contributor

brammool commented Aug 13, 2022 via email

@puremourning
Copy link
Contributor Author

puremourning commented Aug 13, 2022

That's a solid reasoning, and yeah I agree.

I've been playing with multiple properties (one for left-pad, one for argument name, one for right pad), and I've noticed an interesting redraw case when changing properties on WinScrolled: the screen is redrawn (sometimes) in between 2 calls to prop_add, (or perhaps prop_delete) meaning that the virtual text moves around on the screen.

https://asciinema.org/a/WqzLSJiXU5kToyF762w6HQjGZ

I tried to capture with writedelay to show what was being drawn, but it seems not to happen in that case. I think it might be to do with background timers, but I could be way off on that.

I haven't yet been able to narrow it down to a repro case, yet but will let you know if I do. I also can't rule out a bug in my code here of course!

@puremourning
Copy link
Contributor Author

ignore the above, there was a problem in my code. It's interesting though - the problem was I was creating too many properties and not removing them correctly. Strange manifestation, but easily solved on my end. I think we can close this with the fix in 9.0.199.

brammool added a commit that referenced this issue Aug 23, 2022
Problem:    Cannot add padding to virtual text without highlight.
Solution:   Add the "text_padding_left" argument. (issue #10906)
jamespeapen pushed a commit to jamespeapen/vim that referenced this issue Sep 21, 2022
…texts

Problem:    Cursor position wrong with two right-aligned virtual texts.
Solution:   Add the padding for right-alignment. (issue vim#10906)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants