aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/highlight.c
Commit message (Collapse)AuthorAge
* fix(ui): too many win_float_pos events for the popupmenu (partial fix)bfredl2026-08-27
| | | | | | | | | | | | | | | | | | | | I got annoyed about so many repeated `win_float_pos` events for the popupmenu. This fixes some of them but not all of them. vibe-less explanation: `need_highlight_changed = true` is very expensive should not be needed when using a window-local highlight namespace. This was only necessary when overriding the global highlight namespace. This can instead be handled by using the correct `hl_attr_active` instead of `highlight_attr`. Also `pum_grid.pending_comp_index_update` can be cleared when using win_float_pos prior to redraw. I wanted to add a test for no repeated win_float_pos event in the same redraw:flush cycle but that requires deeper cleanups, like getting rid of crazy redraw panic intermingled deep into insexpand.c (if "state" is correct, a single update_screen() after the weird multilayer recursive dance should be enough.)
* fix(highlight): keep guisp underline color in float with 'winblend' #40283glepnir2026-06-16
| | | | | | | | | Problem: A colored (guisp) underline showing through a 'winblend' float lost its special color and followed the foreground instead. Solution: In the blend-through case, blend the underline's special color only when the cell below sets sp explicitly; otherwise clear it.
* fix(api): keep highlight font through set/get and redraws #40200glepnir2026-06-15
| | | | | | | | | | | | Problem: a font set via nvim_set_hl is lost or corrupted with font-only groups, attribute combining, and update=true, and is dropped on any attr-table rebuild. nvim__inspect_cell also frees the font name while a returned dict still borrows it. Solution: register font-only groups, carry font through hl_combine_attr, inherit it on update, and persist sg_font so a rebuild can restore it. Keep interned font names across a rebuild instead of clearing them. Add the missing font field to get_hl_info. Co-authored-by: Ryan Patterson <cgamesplay@cgamesplay.com>
* fix(style): some clang-tidy 22 fixesbfredl2026-05-11
| | | | | | | | | | | | | | | | | | | | | | CI currently uses clang-tidy 20, but this affects local builds and CI is going to be upgraded sooner or later. Some remaining systematic issues: - clang-tidy warns agains any atoi() or atol() usage (because of no error handling) - functions which takes (char *fmt, char *only_string_arg) and expect fmt to contain exactly one "%s" usage. - error: initializing non-local variable with non-const expression depending on uninitialized non-local variable (cppcoreguidelines-interfaces-global-init) This is a much worse problem in C++ (hence C++ core guidelines) where initialization is intermingled with arbitrary code execution. I "think" in plain C, the linker will either resolve all these deterministically or barf an error. But with some restructuring we could make all static initialization actually static..
* fix(api): expose fg_indexed/bg_indexed in nvim_get_hl #39210glepnir2026-04-20
| | | | | | | | | Problem: fg_indexed/bg_indexed were dropped from nvim_get_hl output due to a wrong short_keys guard. HL_FG_INDEXED also wasn't cleared in hl_blend_attrs, and HLATTRS_DICT_SIZE was too small. Solution: Remove the short_keys guard, clear HL_FG_INDEXED in hl_blend_attrs, bump HLATTRS_DICT_SIZE to 24, and clarify docs that these flags mean rgb is an approximation of the cterm palette index.
* feat(api): nvim_set_hl can set "font" #37668glepnir2026-04-12
| | | | | | Problem: Cannot set highlight group fonts via API, only via :highlight command. Solution: Add font parameter in nvim_set_hl().
* fix(api): nvim_get_hl drops groups defined with link_global #38492glepnir2026-04-12
| | | | | | | | | Problem: hlgroup2dict passes &ns_id to ns_get_hl twice. The first call (link=true) sets *ns_hl = 0 when link_global is set, so the second call and the sg_cleared guard both see ns_id == 0 and bail out. The group is silently dropped from the result. Solution: use a temporary copy of ns_id for each ns_get_hl call so the original value is preserved.
* fix(api): nvim_set_hl boolean false corrupts underline styles (#38504)glepnir2026-03-28
| | | | | | | | | | Problem: setting one underline style to false clears bits belonging to another style. `{underdouble = true, underdashed = false}` results in undercurl because CHECK_FLAG_WITH_KEY does `m &= ~flag` which doesn't work for multi-bit encoded values sharing HL_UNDERLINE_MASK. Solution: use a local variable to derive the correct clear mask from the flag. Clear the whole HL_UNDERLINE_MASK field instead of individual bits, and only clear on false when the current style actually matches.
* feat(api): nvim_set_hl{update:boolean} #37546glepnir2026-03-25
| | | | | | | Problem: nvim_set_hl always replaces all attributes. Solution: Add update field. When true, merge with existing attributes instead of replacing. Unspecified attributes are preserved. If highlight group doesn't exist, falls back to reset mode.
* fix(highlight): avoid null deref, misc issues #38164glepnir2026-03-10
| | | | | | | | Problem: update_window_hl dereferenced the pmap_get result without a NULL check. Also `tmp` had the wrong type and attr_id==0 was rejected twice. Solution: check the pointer before dereferencing, change `tmp` to bool, and update the attr_id check to `< 0`.
* feat(highlight): support more SGR attributes #37901Riccardo Mazzarini2026-02-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: TUI does not support several standard SGR text attributes: - dim/faint (SGR 2) - blink (SGR 5) - conceal (SGR 8) - overline (SGR 53) This means that when a program running in the embedded terminal emits one of these escape codes, we drop it and don't surface it to the outer terminal. Solution: - Add support for those attributes. - Also add corresponding flags to `nvim_set_hl` opts, so users can set these attributes in highlight groups. - refactor(highlight): widen `HlAttrFlags` from `int16_t` to `int32_t` Widen the `rgb_ae_attr` and `cterm_ae_attr` fields in HlAttrs from int16_t to int32_t to make room for new highlight attribute flags, since there was only one spare bit left. - The C flag is named HL_CONCEALED to avoid colliding with the existing HL_CONCEAL in syntax.h (which is a syntax group flag, not an SGR attribute). - Also note that libvterm doesn't currently support the dim and overline attributes, so e.g. `printf '\e[2mThis should be dim\n'` and `printf '\e[53mThis should have an overline\n'` are still not rendered correctly when run from the embedded terminal.
* fix(highlight): blend underline check and use struct key for attr cacheglepnir2026-02-17
| | | | | | | | | | | Problem: hl_blend_attrs() through-blend path only checked HL_UNDERLINE | HL_UNDERCURL for sp_color blending, missing underdotted, combine/blend attr cache used (a << 16) + b as map key which could overflow if attr IDs ever exceed 16 bits. Solution: Use HL_UNDERLINE_MASK in the through-blend path to match all underline styles. Use uint64_t with (a << 32) | b as map key via HlAttrKey macro so each attr ID gets its full 32-bit range. Use HLATTRS_INIT in hl_get_underline() to avoid duplicating default field values.
* fix(api): cterm type in highlight keyset #37802glepnir2026-02-10
| | | | | | | | Problem: cterm field in Dict(highlight) is declared as Union(Integer, String) but it actually expects a Dict(highlight_cterm). Solution: change cterm type to DictAs(highlight__cterm) and simplify the handling in dict2hlattrs since type validation and empty array compat are already handled by api_dict_to_keydict.
* fix(pumblend): do not apply special highlight attrs from bg layer #36186Tomasz N2025-10-14
| | | | | | | | | | Problem: if pumblend >= 50, non-whitespace menu character gets italic, bold, underline (or similar) attribute from the cell underneath, which is not really useful and can't be "blended". Solution: drop highlight combination for that special case (@zeertzjq on #36133). Co-authored-by: zeertzjq <zeertzjq@outlook.com>
* feat(ui): 'pumborder' (popup menu border) #25541glepnir2025-10-10
| | | | | | | | | Problem: Popup menu cannot have a border. Solution: Support 'pumborder' option. Generalize `win_redr_border` to `grid_redr_border`, which redraws border for window grid and pum grid.
* refactor(build): remove INCLUDE_GENERATED_DECLARATIONS guardsbfredl2025-08-14
| | | | | | | | | These are not needed after #35129 but making uncrustify still play nice with them was a bit tricky. Unfortunately `uncrustify --update-config-with-doc` breaks strings with backslashes. This issue has been reported upstream, and in the meanwhile auto-update on every single run has been disabled.
* fix(highlight): preserve bg transparency with winblend=100 #34825glepnir2025-07-10
| | | | | | | Problem: When winblend=100 is set on floating windows with transparent background, the desktop background is not visible through the window. Solution: Add special case to preserve transparency (-1) when blend ratio is 100% and background was originally transparent.
* fix(highlight): spurious underline in 'winblend' floating window #34614glepnir2025-06-27
| | | | | | | | Problem: When a floating window with high winblend uses a highlight group with underline (but without guisp), the underline appears red. Solution: Only blend the special color (for underline/undercurl) if the foreground highlight actually has underline or undercurl set. Otherwise, ignore the special color.
* fix(highlight): preserve background transparency in 'winblend' #34302glepnir2025-06-09
| | | | | | | | | | Problem: When using 'winblend', transparent backgrounds (-1) are forced to default colors (usually black) during attribute blending, breaking the transparency effect. Solution: Check original background colors before blending in hl_blend_attrs(). If both background and foreground originally had transparent backgrounds, preserve transparency instead of forcing default colors.
* fix(compositor): don't blend uninitialized background cells #34364luukvbaal2025-06-09
| | | | | | Problem: A 'winblend' window floating over uninitialized cells loses its highlighting. Solution: Return the front attribute for uninitialized background cells.
* fix(api): make `nvim_set_hl()` respect all `cterm` attributes (#31390)Evgeni Chasnovski2024-12-02
|
* feat(keysets): teach Union and LuaRefOfLewis Russell2024-11-25
|
* refactor(highlight): make enum of builtin highlights start with 1bfredl2024-11-13
| | | | | This makes it possible to use HLF_ values directly as highlight id:s and avoids +1 adjustments especially around messages.
* refactor(api)!: rename Dictionary => DictJustin M. Keyes2024-09-23
| | | | | | | | | | | | | | In the api_info() output: :new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val') ... {'return_type': 'ArrayOf(Integer, 2)', 'name': 'nvim_win_get_position', 'method': v:true, 'parameters': [['Window', 'window']], 'since': 1} The `ArrayOf(Integer, 2)` return type didn't break clients when we added it, which is evidence that clients don't use the `return_type` field, thus renaming Dictionary => Dict in api_info() is not (in practice) a breaking change.
* fix(highlight): floating windows inherit NormalFloat from global-nsglepnir2024-09-10
| | | | | | | | | | | | | | Problem: floating windows did not correctly inherit the NormalFloat highlight group from the global namespace when it was not defined in the window-specific namespace. This led to floating windows losing their background highlight when switching between namespaces. Solution: Updated the window highlight logic in update_window_hl() to handle the fallback. This fix resolves issues with floating window backgrounds not displaying as expected in certain namespace configurations.
* refactor(ui): remove outdated UI vs UIData distinctionbfredl2024-03-08
| | | | | | | | Just some basic spring cleaning. In the distant past, not all UI:s where remote UI:s. They still aren't, but both of the "UI" and "UIData" structs are now only for remote UI:s. Thus join them as "RemoteUI".
* refactor(lua): use Arena when converting from lua stack to API argsbfredl2024-02-13
| | | | | | | | | | | | and for return value of nlua_exec/nlua_call_ref, as this uses the same family of functions. NB: the handling of luaref:s is a bit of a mess. add api_luarefs_free_XX functions as a stop-gap as refactoring luarefs is a can of worms for another PR:s. as a minor feature/bug-fix, nvim_buf_call and nvim_win_call now preserves arbitrary return values.
* refactor: rename w_float_config to w_config #27419Will Hopkins2024-02-10
| | | Follows up on rename of `FloatConfig` to `WinConfig` in #27397.
* refactor(api): use arena for hlstate inspectionbfredl2024-02-09
|
* refactor(api): make cstr_as_string accept "const char*"bfredl2024-02-09
| | | | | In the context a String inside an Object/Dictionary etc is consumed, it is considered to be read-only.
* docs: various fixes (#27063)dundargoc2024-01-25
| | | | | | Co-authored-by: lmenou <menl94629@gmail.com> Co-authored-by: altermo <107814000+altermo@users.noreply.github.com> Co-authored-by: VanaIgr <vanaigranov@gmail.com> Co-authored-by: Gregory Anders <greg@gpanders.com>
* feat(ui): add support for OSC 8 hyperlinks (#27109)Gregory Anders2024-01-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extmarks can contain URLs which can then be drawn in any supporting UI. In the TUI, for example, URLs are "drawn" by emitting the OSC 8 control sequence to the TTY. On terminals which support the OSC 8 sequence this will create clickable hyperlinks. URLs are treated as inline highlights in the decoration subsystem, so are included in the `DecorSignHighlight` structure. However, unlike other inline highlights they use allocated memory which must be freed, so they set the `ext` flag in `DecorInline` so that their lifetimes are managed along with other allocated memory like virtual text. The decoration subsystem then adds the URLs as a new highlight attribute. The highlight subsystem maintains a set of unique URLs to avoid duplicating allocations for the same string. To attach a URL to an existing highlight attribute we call `hl_add_url` which finds the URL in the set (allocating and adding it if it does not exist) and sets the `url` highlight attribute to the index of the URL in the set (using an index helps keep the size of the `HlAttrs` struct small). This has the potential to lead to an increase in highlight attributes if a URL is used over a range that contains many different highlight attributes, because now each existing attribute must be combined with the URL. In practice, however, URLs typically span a range containing a single highlight (e.g. link text in Markdown), so this is likely just a pathological edge case. When a new highlight attribute is defined with a URL it is copied to all attached UIs with the `hl_attr_define` UI event. The TUI manages its own set of URLs (just like the highlight subsystem) to minimize allocations. The TUI keeps track of which URL is "active" for the cell it is printing. If no URL is active and a cell containing a URL is printed, the opening OSC 8 sequence is emitted and that URL becomes the actively tracked URL. If the cursor is moved while in the middle of a URL span, we emit the terminating OSC sequence to prevent the hyperlink from spanning multiple lines. This does not support nested hyperlinks, but that is a rare (and, frankly, bizarre) use case. If a valid use case for nested hyperlinks ever presents itself we can address that issue then.
* refactor(IWYU): fix headersdundargoc2024-01-11
| | | | | | Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want.
* refactor(IWYU): move decor provider types to decoration_defs.h (#26692)zeertzjq2023-12-21
|
* docs: add style rule regarding initializationdundargoc2023-12-18
| | | | | Specifically, specify that each initialization should be done on a separate line.
* refactor: move function macros out of vim_defs.h (#26300)zeertzjq2023-11-29
|
* refactor: fix headers with IWYUdundargoc2023-11-28
|
* refactor: rename types.h to types_defs.hdundargoc2023-11-27
|
* refactor: fix includes for api/autocmd.hdundargoc2023-11-27
|
* refactor: move Arena and ArenaMem to memory_defs.h (#26240)zeertzjq2023-11-27
|
* build: remove PVSdundargoc2023-11-12
| | | | | | | We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable.
* fix(float): apply 'winblend' to title/footer highlight (#25999)zeertzjq2023-11-12
|
* fix(highlight): apply 'winblend' to float border (#25981)zeertzjq2023-11-11
|
* build(lint): remove unnecessary clint.py rulesdundargoc2023-10-23
| | | | | Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py.
* fix(PVS/V547): expression is always true/falsedundargoc2023-10-08
|
* build(iwyu): add a few more _defs.h mappings (#25435)zeertzjq2023-09-30
|
* refactor(grid): change schar_T representation to be more compactbfredl2023-09-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, a screen cell would occupy 28+4=32 bytes per cell as we always made space for up to MAX_MCO+1 codepoints in a cell. As an example, even a pretty modest 50*80 screen would consume 50*80*2*32 = 256000, i e a quarter megabyte With the factor of two due to the TUI side buffer, and even more when using msg_grid and/or ext_multigrid. This instead stores a 4-byte union of either: - a valid UTF-8 sequence up to 4 bytes - an escape char which is invalid UTF-8 (0xFF) plus a 24-bit index to a glyph cache This avoids allocating space for huge composed glyphs _upfront_, while still keeping rendering such glyphs reasonably fast (1 hash table lookup + one plain index lookup). If the same large glyphs are using repeatedly on the screen, this is still a net reduction of memory/cache consumption. The only case which really gets worse is if you blast the screen full with crazy emojis and zalgo text and even this case only leads to 4 extra bytes per char. When only <= 4-byte glyphs are used, plus the 4-byte attribute code, i e 8 bytes in total there is a factor of four reduction of memory use. Memory which will be quite hot in cache as the screen buffer is scanned over in win_line() buffer text drawing A slight complication is that the representation depends on host byte order. I've tested this manually by compling and running this in qemu-s390x and it works fine. We might add a qemu based solution to CI at some point.
* refactor(highlight): merge redundant attr_entries and attr_entry_ids structsbfredl2023-09-13
| | | | | An insert-only set now defines a monotonically increasing ordering by itself. It can be used to both lookup the key from index, and vice versa.
* refactor(map): enhanced implementation, Clean Codeā„¢, etc etcbfredl2023-09-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type.
* refactor(api): use typed keysetsbfredl2023-08-07
| | | | | Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata