diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 6a7fa3b590..3aa41db21a 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -1,4 +1,4 @@ -*filetype.txt* For Vim version 9.2. Last change: 2026 Mar 24 +*filetype.txt* For Vim version 9.2. Last change: 2026 Apr 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -652,6 +652,13 @@ One command, :DiffGitCached, is provided to show a diff of the current commit in the preview window. It is equivalent to calling "git diff --cached" plus any arguments given to the command. + +The length of the first line of the commit message used for +syntax highlighting can be configured via `g:gitcommit_summary_length`. +The default is 50. Example: > + + let g:gitcommit_summary_length = 70 + GIT REBASE *ft-gitrebase-plugin* The gitrebase filetype defines the following buffer-local commands, to help diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index 23d96b9b75..dde63e9cac 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -1,4 +1,4 @@ -*gui.txt* For Vim version 9.2. Last change: 2026 Feb 14 +*gui.txt* For Vim version 9.2. Last change: 2026 Apr 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1184,11 +1184,22 @@ For the Win32 GUI *E244* *E245* NONANTIALIASED, CLEARTYPE and DEFAULT. Normally you would use "qDEFAULT". Some quality values are not supported in legacy OSs. + fXX - OpenType font feature. Specify a single feature as + tag=value, where tag is a 4-character OpenType feature + tag and value is the parameter (0 to disable, 1 or + higher to enable/select variant). Multiple features + can be specified by repeating the ":f" option. + This only takes effect when 'renderoptions' is set to use + DirectWrite (type:directx). Default features (calt, liga, + etc.) are preserved unless explicitly overridden. + Example: ":fss19=1:fcalt=0" enables Stylistic Set 19 + and disables Contextual Alternates. - A '_' can be used in the place of a space, so you don't need to use backslashes to escape the spaces. Examples: > :set guifont=courier_new:h12:w5:b:cRUSSIAN :set guifont=Andale_Mono:h7.5:w4.5 + :set guifont=Cascadia_Code:h14:fss19=1:fcalt=1:fliga=1 See also |font-sizes|. diff --git a/runtime/doc/netbeans.txt b/runtime/doc/netbeans.txt index d56d31fe51..d20ae51907 100644 --- a/runtime/doc/netbeans.txt +++ b/runtime/doc/netbeans.txt @@ -1,4 +1,4 @@ -*netbeans.txt* For Vim version 9.2. Last change: 2026 Feb 14 +*netbeans.txt* For Vim version 9.2. Last change: 2026 Mar 07 VIM REFERENCE MANUAL by Gordon Prieur et al. @@ -849,7 +849,7 @@ REJECT Not used. These errors occur when a message violates the protocol: *E627* *E628* *E629* *E632* *E633* *E634* *E635* *E636* *E637* *E638* *E639* *E640* *E641* *E642* *E643* *E644* *E645* *E646* -*E647* *E648* *E650* *E651* *E652* +*E647* *E648* *E649* *E650* *E651* *E652* ============================================================================== diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 9a3da1ad9f..b6ec7e3845 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1,4 +1,4 @@ -*options.txt* For Vim version 9.2. Last change: 2026 Apr 06 +*options.txt* For Vim version 9.2. Last change: 2026 Apr 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -7022,6 +7022,7 @@ A jump table for the options with a short description can be found at |Q_op|. global Defines a border and optional decorations for the popup menu in completion. The value is a comma-separated list of keywords. + See |'pumopt'| for a consolidated alternative. Border styles (at most one): "single" use thin box-drawing characters @@ -7057,6 +7058,7 @@ A jump table for the options with a short description can be found at |Q_op|. Determines the maximum number of items to show in the popup menu for Insert mode completion. When zero as much space as available is used. |ins-completion-menu|. + See |'pumopt'| for a consolidated alternative. *'pummaxwidth'* *'pmw'* 'pummaxwidth' 'pmw' number (default 0) @@ -7068,12 +7070,67 @@ A jump table for the options with a short description can be found at |Q_op|. This option takes precedence over 'pumwidth'. |ins-completion-menu|. + See |'pumopt'| for a consolidated alternative. + + *'pumopt'* +'pumopt' string (default "") + global + Configures the popup menu used for Insert mode completion. + The value is a comma-separated list of key:value pairs and flags. + + Keys with values: + border:{style} set a border style (at most one): + "single" thin box-drawing characters + "double" double-line box-drawing characters + "round" rounded corners + "ascii" ASCII characters (-, |, +) + "custom:X;X;X;X;X;X;X;X" + eight characters separated by + semicolons, in the order: top, right, + bottom, left, topleft, topright, + botright, botleft + height:{n} maximum number of items to show (default 0, + meaning as much space as available) + width:{n} minimum width (default 15) + maxwidth:{n} maximum width (default 0, meaning no limit). + This takes precedence over width. + Truncated text is indicated by "trunc" value + of 'fillchars' option. + opacity:{n} opacity percentage 0-100 (default 100). + When less than 100, background content shows + through the popup menu. + + Flags (no value): + margin adds one-cell spacing inside the left and + right border. Requires a border style. + shadow draws a shadow at the right and bottom edges. + + Border styles using box-drawing characters ("single", "double", + "round") are only available when 'encoding' is "utf-8" and + 'ambiwidth' is "single". + + Highlight groups: + |hl-PmenuBorder| used for the border characters + |hl-PmenuShadow| used for the shadow + + Note: When 'pumopt' is set, all values are reset to their defaults + first, then the specified keys are applied. Unspecified keys get + their default values. + + Examples: > + :set pumopt=border:single + :set pumopt=border:double,margin,shadow + :set pumopt=height:10,width:20,opacity:80 + :set pumopt=border:custom:─;│;─;│;┌;┐;┘;└,shadow +< + See also: |ins-completion-menu|. *'pumwidth'* *'pw'* 'pumwidth' 'pw' number (default 15) global Determines the minimum width to use for the popup menu for Insert mode completion. |ins-completion-menu|. + See |'pumopt'| for a consolidated alternative. *'pythondll'* 'pythondll' string (default depends on the build) diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index afbb4c23ff..9b4959240f 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -1,4 +1,4 @@ -*quickref.txt* For Vim version 9.2. Last change: 2026 Mar 04 +*quickref.txt* For Vim version 9.2. Last change: 2026 Apr 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -872,6 +872,7 @@ Short explanation of each option: *option-list* 'printoptions' 'popt' controls the format of :hardcopy output 'prompt' 'prompt' enable prompt in Ex mode 'pumheight' 'ph' maximum height of the popup menu +'pumopt' 'pumopt' additional options for the popup menu 'pumwidth' 'pw' minimum width of the popup menu 'pythondll' name of the Python 2 dynamic library 'pythonhome' name of the Python 2 home directory diff --git a/runtime/doc/tags b/runtime/doc/tags index fc1e47e4a4..a24132803b 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -909,6 +909,7 @@ $quote eval.txt /*$quote* 'pumborder' options.txt /*'pumborder'* 'pumheight' options.txt /*'pumheight'* 'pummaxwidth' options.txt /*'pummaxwidth'* +'pumopt' options.txt /*'pumopt'* 'pumwidth' options.txt /*'pumwidth'* 'pvh' options.txt /*'pvh'* 'pvp' options.txt /*'pvp'* @@ -5351,6 +5352,7 @@ E645 netbeans.txt /*E645* E646 netbeans.txt /*E646* E647 netbeans.txt /*E647* E648 netbeans.txt /*E648* +E649 netbeans.txt /*E649* E65 pattern.txt /*E65* E650 netbeans.txt /*E650* E651 netbeans.txt /*E651* diff --git a/runtime/doc/textprop.txt b/runtime/doc/textprop.txt index f57a238e29..9fd5ff6686 100644 --- a/runtime/doc/textprop.txt +++ b/runtime/doc/textprop.txt @@ -1,4 +1,4 @@ -*textprop.txt* For Vim version 9.2. Last change: 2026 Apr 06 +*textprop.txt* For Vim version 9.2. Last change: 2026 Apr 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -511,7 +511,9 @@ will move accordingly. When text is deleted and a text property no longer includes any text, it is deleted. However, a text property that was defined as zero-width will remain, -unless the whole line is deleted. +unless the whole line is deleted. When lines are joined by a multi-line +substitute command, virtual text properties on the deleted lines are moved to +the resulting joined line. *E275* When a buffer is unloaded, all the text properties are gone. There is no way to store the properties in a file. You can only re-create them. When a diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt index 8045698a38..acce37226a 100644 --- a/runtime/doc/version9.txt +++ b/runtime/doc/version9.txt @@ -1,4 +1,4 @@ -*version9.txt* For Vim version 9.2. Last change: 2026 Mar 25 +*version9.txt* For Vim version 9.2. Last change: 2026 Apr 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -52614,17 +52614,23 @@ Other ~ - |system()| and |systemlist()| functions accept a list as first argument, bypassing the shell completely. +Platform specific ~ +----------------- +- support OpenType font features in 'guifont' for DirectWrite (Win32) + xxd ~ --- Add "-t" option to append a terminating NUL byte to C include output (-i). *changed-9.3* -Changed~ +Changed ~ ------- - Support for NeXTStep was dropped with patch v9.2.0122 - |json_decode()| is stricter: keywords must be lowercase, lone surrogates are now invalid - |js_decode()| rejects lone surrogates +- virtual text properties on lines deleted by a multi-line substitute + are moved to the resulting joined line instead of being dropped. *added-9.3* Added ~ @@ -52641,6 +52647,7 @@ Autocommands: ~ Options: ~ +'pumopt' Additional options for the popup menu 'statuslineopt' Extra window-local options for the 'statusline', to configure the height. 't_BS' Begin synchronized update. diff --git a/runtime/optwin.vim b/runtime/optwin.vim index d0664a68ac..33cec946c2 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -1,7 +1,7 @@ " These commands create the option window. " " Maintainer: The Vim Project -" Last Change: 2026 Mar 11 +" Last Change: 2026 Apr 07 " Former Maintainer: Bram Moolenaar " If there already is an option window, jump to that one. @@ -932,6 +932,8 @@ if has("insert_expand") call OptionG("pmw", &pmw) call AddOption("pumborder", gettext("popup border style")) call OptionG("pb", &pb) + call AddOption("pumopt", gettext("additional options for the popup menu")) + call OptionG("pumopt", &pumopt) call AddOption("completefunc", gettext("user defined function for Insert mode completion")) call append("$", "\t" .. s:local_to_buffer) call OptionL("cfu") diff --git a/runtime/syntax/bitbake.vim b/runtime/syntax/bitbake.vim index 5e9bc58290..9fea3e291a 100644 --- a/runtime/syntax/bitbake.vim +++ b/runtime/syntax/bitbake.vim @@ -6,6 +6,7 @@ " Copyright (C) 2008 Ricardo Salveti " Last Change: 2022 Jul 25 " 2025 Oct 13 by Vim project: update multiline function syntax #18565 +" 2026 Apr 07 by Vim project: update syntax script #19931 " " This file is licensed under the MIT license, see COPYING.MIT in " this source distribution for the terms. @@ -62,14 +63,14 @@ syn match bbVarFlagDef "^\([a-zA-Z0-9\-_\.]\+\)\(\[[a-zA-Z0-9\-_\.+]\+\ syn region bbVarFlagFlag matchgroup=bbArrayBrackets start="\[" end="\]\s*\(:=\|=\|.=\|=.|+=\|=+\|?=\)\@=" contained contains=bbIdentifier nextgroup=bbVarEq " Includes and requires -syn keyword bbInclude inherit include require contained +syn keyword bbInclude inherit inherit_defer include include_all require contained syn match bbIncludeRest ".*$" contained contains=bbString,bbVarDeref -syn match bbIncludeLine "^\(inherit\|include\|require\)\s\+" contains=bbInclude nextgroup=bbIncludeRest +syn match bbIncludeLine "^\(inherit\|inherit_defer\|include\|include_all\|require\)\s\+" contains=bbInclude nextgroup=bbIncludeRest " Add taks and similar -syn keyword bbStatement addtask deltask addhandler after before EXPORT_FUNCTIONS contained +syn keyword bbStatement addtask deltask addhandler after before EXPORT_FUNCTIONS addpylib contained syn match bbStatementRest ".*$" skipwhite contained contains=bbStatement -syn match bbStatementLine "^\(addtask\|deltask\|addhandler\|after\|before\|EXPORT_FUNCTIONS\)\s\+" contains=bbStatement nextgroup=bbStatementRest +syn match bbStatementLine "^\(addtask\|deltask\|addhandler\|after\|before\|EXPORT_FUNCTIONS\|addpylib\)\s\+" contains=bbStatement nextgroup=bbStatementRest " OE Important Functions syn keyword bbOEFunctions do_fetch do_unpack do_patch do_configure do_compile do_stage do_install do_package contained diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index 193125b4ea..06875ecfb7 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -2,7 +2,7 @@ " Language: Vim script " Maintainer: Hirohito Higashi " Doug Kearns -" Last Change: 2026 Mar 13 +" Last Change: 2026 Apr 07 " Former Maintainer: Charles E. Campbell " DO NOT CHANGE DIRECTLY. @@ -69,10 +69,10 @@ syn keyword vimOption contained co columns com comments cms commentstring cp com syn keyword vimOption contained efm errorformat ek esckeys ei eventignore eiw eventignorewin et expandtab ex exrc fenc fileencoding fencs fileencodings ff fileformat ffs fileformats fic fileignorecase ft filetype fcs fillchars ffu findfunc fixeol fixendofline fcl foldclose fdc foldcolumn fen foldenable fde foldexpr fdi foldignore fdl foldlevel fdls foldlevelstart fmr foldmarker fdm foldmethod fml foldminlines fdn foldnestmax fdo foldopen fdt foldtext fex formatexpr flp formatlistpat fo formatoptions fp formatprg fs fsync gd gdefault gfm grepformat gp grepprg gcr guicursor gfn guifont gfs guifontset gfw guifontwide ghr guiheadroom gli guiligatures go guioptions guipty gtl guitablabel gtt guitabtooltip hf helpfile hh helpheight hlg helplang hid hidden hl highlight skipwhite nextgroup=vimSetEqual,vimSetMod syn keyword vimOption contained hi history hk hkmap hkp hkmapp hls hlsearch icon iconstring ic ignorecase imaf imactivatefunc imak imactivatekey imc imcmdline imd imdisable imi iminsert ims imsearch imsf imstatusfunc imst imstyle inc include inex includeexpr is incsearch inde indentexpr indk indentkeys inf infercase im insertmode isf isfname isi isident isk iskeyword isp isprint js joinspaces jop jumpoptions key kmp keymap km keymodel kpc keyprotocol kp keywordprg lmap langmap lm langmenu lnr langnoremap lrm langremap ls laststatus lz lazyredraw lhi lhistory lbr linebreak lines lsp linespace lisp lop lispoptions lw lispwords list lcs listchars lpl loadplugins luadll magic mef makeef menc makeencoding mp makeprg mps matchpairs mat matchtime mco maxcombine mfd maxfuncdepth skipwhite nextgroup=vimSetEqual,vimSetMod syn keyword vimOption contained mmd maxmapdepth mm maxmem mmp maxmempattern mmt maxmemtot msc maxsearchcount mis menuitems mopt messagesopt msm mkspellmem ml modeline mle modelineexpr mls modelines ma modifiable mod modified more mouse mousef mousefocus mh mousehide mousem mousemodel mousemev mousemoveevent mouses mouseshape mouset mousetime mzq mzquantum mzschemedll mzschemegcdll nf nrformats nu number nuw numberwidth ofu omnifunc odev opendevice opfunc operatorfunc ost osctimeoutlen pp packpath para paragraphs paste pt pastetoggle pex patchexpr pm patchmode pa path perldll pi preserveindent pvh previewheight pvp previewpopup pvw previewwindow pdev printdevice penc printencoding pexpr printexpr pfn printfont pheader printheader pmbcs printmbcharset pmbfn printmbfont skipwhite nextgroup=vimSetEqual,vimSetMod -syn keyword vimOption contained popt printoptions prompt pb pumborder ph pumheight pmw pummaxwidth pw pumwidth pythondll pythonhome pythonthreedll pythonthreehome pyx pyxversion qftf quickfixtextfunc qe quoteescape ro readonly rdt redrawtime re regexpengine rnu relativenumber remap rop renderoptions report rs restorescreen ri revins rl rightleft rlc rightleftcmd rubydll ru ruler ruf rulerformat rtp runtimepath scr scroll scb scrollbind scf scrollfocus sj scrolljump so scrolloff sbo scrollopt sect sections secure sel selection slm selectmode ssop sessionoptions sh shell shcf shellcmdflag sp shellpipe shq shellquote srr shellredir ssl shellslash stmp shelltemp st shelltype sxe shellxescape sxq shellxquote sr shiftround sw shiftwidth shm shortmess sn shortname sbr showbreak skipwhite nextgroup=vimSetEqual,vimSetMod -syn keyword vimOption contained sc showcmd sloc showcmdloc sft showfulltag sm showmatch smd showmode stal showtabline stpl showtabpanel ss sidescroll siso sidescrolloff scl signcolumn scs smartcase si smartindent sta smarttab sms smoothscroll sts softtabstop spell spc spellcapcheck spf spellfile spl spelllang spo spelloptions sps spellsuggest sb splitbelow spk splitkeep spr splitright sol startofline stl statusline stlo statuslineopt su suffixes sua suffixesadd swf swapfile sws swapsync swb switchbuf smc synmaxcol syn syntax tcl tabclose tal tabline tpm tabpagemax tpl tabpanel tplo tabpanelopt ts tabstop tbs tagbsearch tc tagcase tfu tagfunc tl taglength tr tagrelative tag tags tgst tagstack tcldll term tbidi termbidi tenc termencoding tgc termguicolors trz termresize skipwhite nextgroup=vimSetEqual,vimSetMod -syn keyword vimOption contained tsy termsync twk termwinkey twsl termwinscroll tws termwinsize twt termwintype terse ta textauto tx textmode tw textwidth tsr thesaurus tsrfu thesaurusfunc top tildeop to timeout tm timeoutlen title titlelen titleold titlestring tb toolbar tbis toolbariconsize ttimeout ttm ttimeoutlen tbi ttybuiltin tf ttyfast ttym ttymouse tsl ttyscroll tty ttytype udir undodir udf undofile ul undolevels ur undoreload uc updatecount ut updatetime vsts varsofttabstop vts vartabstop vbs verbose vfile verbosefile vdir viewdir vop viewoptions vi viminfo vif viminfofile ve virtualedit vb visualbell warn wiv weirdinvert ww whichwrap wc wildchar wcm wildcharm wig wildignore wic wildignorecase wmnu wildmenu wim wildmode wop wildoptions wak winaltkeys wcr wincolor skipwhite nextgroup=vimSetEqual,vimSetMod -syn keyword vimOption contained wi window wfb winfixbuf wfh winfixheight wfw winfixwidth wh winheight whl winhighlight wmh winminheight wmw winminwidth winptydll wiw winwidth wse wlseat wst wlsteal wtm wltimeoutlen wrap wm wrapmargin ws wrapscan write wa writeany wb writebackup wd writedelay xtermcodes skipwhite nextgroup=vimSetEqual,vimSetMod +syn keyword vimOption contained popt printoptions prompt pb pumborder ph pumheight pmw pummaxwidth pumopt pw pumwidth pythondll pythonhome pythonthreedll pythonthreehome pyx pyxversion qftf quickfixtextfunc qe quoteescape ro readonly rdt redrawtime re regexpengine rnu relativenumber remap rop renderoptions report rs restorescreen ri revins rl rightleft rlc rightleftcmd rubydll ru ruler ruf rulerformat rtp runtimepath scr scroll scb scrollbind scf scrollfocus sj scrolljump so scrolloff sbo scrollopt sect sections secure sel selection slm selectmode ssop sessionoptions sh shell shcf shellcmdflag sp shellpipe shq shellquote srr shellredir ssl shellslash stmp shelltemp st shelltype sxe shellxescape sxq shellxquote sr shiftround sw shiftwidth shm shortmess sn shortname skipwhite nextgroup=vimSetEqual,vimSetMod +syn keyword vimOption contained sbr showbreak sc showcmd sloc showcmdloc sft showfulltag sm showmatch smd showmode stal showtabline stpl showtabpanel ss sidescroll siso sidescrolloff scl signcolumn scs smartcase si smartindent sta smarttab sms smoothscroll sts softtabstop spell spc spellcapcheck spf spellfile spl spelllang spo spelloptions sps spellsuggest sb splitbelow spk splitkeep spr splitright sol startofline stl statusline stlo statuslineopt su suffixes sua suffixesadd swf swapfile sws swapsync swb switchbuf smc synmaxcol syn syntax tcl tabclose tal tabline tpm tabpagemax tpl tabpanel tplo tabpanelopt ts tabstop tbs tagbsearch tc tagcase tfu tagfunc tl taglength tr tagrelative tag tags tgst tagstack tcldll term tbidi termbidi tenc termencoding tgc termguicolors skipwhite nextgroup=vimSetEqual,vimSetMod +syn keyword vimOption contained trz termresize tsy termsync twk termwinkey twsl termwinscroll tws termwinsize twt termwintype terse ta textauto tx textmode tw textwidth tsr thesaurus tsrfu thesaurusfunc top tildeop to timeout tm timeoutlen title titlelen titleold titlestring tb toolbar tbis toolbariconsize ttimeout ttm ttimeoutlen tbi ttybuiltin tf ttyfast ttym ttymouse tsl ttyscroll tty ttytype udir undodir udf undofile ul undolevels ur undoreload uc updatecount ut updatetime vsts varsofttabstop vts vartabstop vbs verbose vfile verbosefile vdir viewdir vop viewoptions vi viminfo vif viminfofile ve virtualedit vb visualbell warn wiv weirdinvert ww whichwrap wc wildchar wcm wildcharm wig wildignore wic wildignorecase wmnu wildmenu wim wildmode wop wildoptions wak winaltkeys skipwhite nextgroup=vimSetEqual,vimSetMod +syn keyword vimOption contained wcr wincolor wi window wfb winfixbuf wfh winfixheight wfw winfixwidth wh winheight whl winhighlight wmh winminheight wmw winminwidth winptydll wiw winwidth wse wlseat wst wlsteal wtm wltimeoutlen wrap wm wrapmargin ws wrapscan write wa writeany wb writebackup wd writedelay xtermcodes skipwhite nextgroup=vimSetEqual,vimSetMod " vimOptions: These are the turn-off setting variants {{{2 " GEN_SYN_VIM: vimOption turn-off, START_STR='syn keyword vimOption contained', END_STR='' @@ -108,10 +108,10 @@ syn keyword vimOptionVarName contained co columns com comments cms commentstring syn keyword vimOptionVarName contained efm errorformat ek esckeys ei eventignore eiw eventignorewin et expandtab ex exrc fenc fileencoding fencs fileencodings ff fileformat ffs fileformats fic fileignorecase ft filetype fcs fillchars ffu findfunc fixeol fixendofline fcl foldclose fdc foldcolumn fen foldenable fde foldexpr fdi foldignore fdl foldlevel fdls foldlevelstart fmr foldmarker fdm foldmethod fml foldminlines fdn foldnestmax fdo foldopen fdt foldtext fex formatexpr flp formatlistpat fo formatoptions fp formatprg fs fsync gd gdefault gfm grepformat gp grepprg gcr guicursor gfn guifont gfs guifontset gfw guifontwide ghr guiheadroom gli guiligatures go guioptions guipty gtl guitablabel gtt guitabtooltip hf helpfile hh helpheight hlg helplang hid hidden hl highlight syn keyword vimOptionVarName contained hi history hk hkmap hkp hkmapp hls hlsearch icon iconstring ic ignorecase imaf imactivatefunc imak imactivatekey imc imcmdline imd imdisable imi iminsert ims imsearch imsf imstatusfunc imst imstyle inc include inex includeexpr is incsearch inde indentexpr indk indentkeys inf infercase im insertmode isf isfname isi isident isk iskeyword isp isprint js joinspaces jop jumpoptions key kmp keymap km keymodel kpc keyprotocol kp keywordprg lmap langmap lm langmenu lnr langnoremap lrm langremap ls laststatus lz lazyredraw lhi lhistory lbr linebreak lines lsp linespace lisp lop lispoptions lw lispwords list lcs listchars lpl loadplugins luadll magic mef makeef menc makeencoding mp makeprg mps matchpairs mat matchtime mco maxcombine syn keyword vimOptionVarName contained mfd maxfuncdepth mmd maxmapdepth mm maxmem mmp maxmempattern mmt maxmemtot msc maxsearchcount mis menuitems mopt messagesopt msm mkspellmem ml modeline mle modelineexpr mls modelines ma modifiable mod modified more mouse mousef mousefocus mh mousehide mousem mousemodel mousemev mousemoveevent mouses mouseshape mouset mousetime mzq mzquantum mzschemedll mzschemegcdll nf nrformats nu number nuw numberwidth ofu omnifunc odev opendevice opfunc operatorfunc ost osctimeoutlen pp packpath para paragraphs paste pt pastetoggle pex patchexpr pm patchmode pa path perldll pi preserveindent pvh previewheight pvp previewpopup pvw previewwindow pdev printdevice penc printencoding pexpr printexpr pfn printfont pheader printheader pmbcs printmbcharset -syn keyword vimOptionVarName contained pmbfn printmbfont popt printoptions prompt pb pumborder ph pumheight pmw pummaxwidth pw pumwidth pythondll pythonhome pythonthreedll pythonthreehome pyx pyxversion qftf quickfixtextfunc qe quoteescape ro readonly rdt redrawtime re regexpengine rnu relativenumber remap rop renderoptions report rs restorescreen ri revins rl rightleft rlc rightleftcmd rubydll ru ruler ruf rulerformat rtp runtimepath scr scroll scb scrollbind scf scrollfocus sj scrolljump so scrolloff sbo scrollopt sect sections secure sel selection slm selectmode ssop sessionoptions sh shell shcf shellcmdflag sp shellpipe shq shellquote srr shellredir ssl shellslash stmp shelltemp st shelltype sxe shellxescape sxq shellxquote sr shiftround sw shiftwidth shm shortmess -syn keyword vimOptionVarName contained sn shortname sbr showbreak sc showcmd sloc showcmdloc sft showfulltag sm showmatch smd showmode stal showtabline stpl showtabpanel ss sidescroll siso sidescrolloff scl signcolumn scs smartcase si smartindent sta smarttab sms smoothscroll sts softtabstop spell spc spellcapcheck spf spellfile spl spelllang spo spelloptions sps spellsuggest sb splitbelow spk splitkeep spr splitright sol startofline stl statusline stlo statuslineopt su suffixes sua suffixesadd swf swapfile sws swapsync swb switchbuf smc synmaxcol syn syntax tcl tabclose tal tabline tpm tabpagemax tpl tabpanel tplo tabpanelopt ts tabstop tbs tagbsearch tc tagcase tfu tagfunc tl taglength tr tagrelative tag tags tgst tagstack tcldll term tbidi termbidi tenc termencoding -syn keyword vimOptionVarName contained tgc termguicolors trz termresize tsy termsync twk termwinkey twsl termwinscroll tws termwinsize twt termwintype terse ta textauto tx textmode tw textwidth tsr thesaurus tsrfu thesaurusfunc top tildeop to timeout tm timeoutlen title titlelen titleold titlestring tb toolbar tbis toolbariconsize ttimeout ttm ttimeoutlen tbi ttybuiltin tf ttyfast ttym ttymouse tsl ttyscroll tty ttytype udir undodir udf undofile ul undolevels ur undoreload uc updatecount ut updatetime vsts varsofttabstop vts vartabstop vbs verbose vfile verbosefile vdir viewdir vop viewoptions vi viminfo vif viminfofile ve virtualedit vb visualbell warn wiv weirdinvert ww whichwrap wc wildchar wcm wildcharm wig wildignore wic wildignorecase wmnu wildmenu wim wildmode -syn keyword vimOptionVarName contained wop wildoptions wak winaltkeys wcr wincolor wi window wfb winfixbuf wfh winfixheight wfw winfixwidth wh winheight whl winhighlight wmh winminheight wmw winminwidth winptydll wiw winwidth wse wlseat wst wlsteal wtm wltimeoutlen wrap wm wrapmargin ws wrapscan write wa writeany wb writebackup wd writedelay xtermcodes +syn keyword vimOptionVarName contained pmbfn printmbfont popt printoptions prompt pb pumborder ph pumheight pmw pummaxwidth pumopt pw pumwidth pythondll pythonhome pythonthreedll pythonthreehome pyx pyxversion qftf quickfixtextfunc qe quoteescape ro readonly rdt redrawtime re regexpengine rnu relativenumber remap rop renderoptions report rs restorescreen ri revins rl rightleft rlc rightleftcmd rubydll ru ruler ruf rulerformat rtp runtimepath scr scroll scb scrollbind scf scrollfocus sj scrolljump so scrolloff sbo scrollopt sect sections secure sel selection slm selectmode ssop sessionoptions sh shell shcf shellcmdflag sp shellpipe shq shellquote srr shellredir ssl shellslash stmp shelltemp st shelltype sxe shellxescape sxq shellxquote sr shiftround sw shiftwidth +syn keyword vimOptionVarName contained shm shortmess sn shortname sbr showbreak sc showcmd sloc showcmdloc sft showfulltag sm showmatch smd showmode stal showtabline stpl showtabpanel ss sidescroll siso sidescrolloff scl signcolumn scs smartcase si smartindent sta smarttab sms smoothscroll sts softtabstop spell spc spellcapcheck spf spellfile spl spelllang spo spelloptions sps spellsuggest sb splitbelow spk splitkeep spr splitright sol startofline stl statusline stlo statuslineopt su suffixes sua suffixesadd swf swapfile sws swapsync swb switchbuf smc synmaxcol syn syntax tcl tabclose tal tabline tpm tabpagemax tpl tabpanel tplo tabpanelopt ts tabstop tbs tagbsearch tc tagcase tfu tagfunc tl taglength tr tagrelative tag tags tgst tagstack tcldll term tbidi termbidi +syn keyword vimOptionVarName contained tenc termencoding tgc termguicolors trz termresize tsy termsync twk termwinkey twsl termwinscroll tws termwinsize twt termwintype terse ta textauto tx textmode tw textwidth tsr thesaurus tsrfu thesaurusfunc top tildeop to timeout tm timeoutlen title titlelen titleold titlestring tb toolbar tbis toolbariconsize ttimeout ttm ttimeoutlen tbi ttybuiltin tf ttyfast ttym ttymouse tsl ttyscroll tty ttytype udir undodir udf undofile ul undolevels ur undoreload uc updatecount ut updatetime vsts varsofttabstop vts vartabstop vbs verbose vfile verbosefile vdir viewdir vop viewoptions vi viminfo vif viminfofile ve virtualedit vb visualbell warn wiv weirdinvert ww whichwrap wc wildchar wcm wildcharm wig wildignore wic wildignorecase wmnu wildmenu +syn keyword vimOptionVarName contained wim wildmode wop wildoptions wak winaltkeys wcr wincolor wi window wfb winfixbuf wfh winfixheight wfw winfixwidth wh winheight whl winhighlight wmh winminheight wmw winminwidth winptydll wiw winwidth wse wlseat wst wlsteal wtm wltimeoutlen wrap wm wrapmargin ws wrapscan write wa writeany wb writebackup wd writedelay xtermcodes " GEN_SYN_VIM: vimOption term output code variable, START_STR='syn keyword vimOptionVarName contained', END_STR='' syn keyword vimOptionVarName contained t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo t_BS t_ES syn keyword vimOptionVarName contained t_F1 t_F2 t_F3 t_F4 t_F5 t_F6 t_F7 t_F8 t_F9 t_k1 t_K1 t_k2 t_k3 t_K3 t_k4 t_K4 t_k5 t_K5 t_k6 t_K6 t_k7 t_K7 t_k8 t_K8 t_k9 t_K9 t_KA t_kb t_kB t_KB t_KC t_kd t_kD t_KD t_KE t_KF t_KG t_kh t_KH t_kI t_KI t_KJ t_KK t_kl t_KL t_kN t_kP t_kr t_ku diff --git a/src/buffer.c b/src/buffer.c index af1e2d5b7d..9c2c63eec6 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1119,9 +1119,6 @@ free_buffer_stuff( #endif #ifdef FEAT_NETBEANS_INTG netbeans_file_killed(buf); -#endif -#ifdef FEAT_PROP_POPUP - ga_clear_strings(&buf->b_textprop_text); #endif map_clear_mode(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings map_clear_mode(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs diff --git a/src/change.c b/src/change.c index c0c2e0ba1c..52e251ee84 100644 --- a/src/change.c +++ b/src/change.c @@ -321,6 +321,9 @@ f_listener_add(typval_T *argvars, typval_T *rettv) buf_T *buf = curbuf; int unbuffered = 0; + if (check_secure()) + return; + if (recursive) { emsg(_(e_cannot_add_listener_in_listener_callback)); @@ -386,6 +389,9 @@ f_listener_flush(typval_T *argvars, typval_T *rettv UNUSED) { buf_T *buf = curbuf; + if (check_secure()) + return; + if (recursive) return; @@ -439,6 +445,9 @@ f_listener_remove(typval_T *argvars, typval_T *rettv) int id; buf_T *buf; + if (check_secure()) + return; + if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) return; @@ -2561,7 +2570,7 @@ truncate_line(int fixpos) * Saves the lines for undo first if "undo" is TRUE. */ void -del_lines(long nlines, int undo) +del_lines(long nlines, int undo) { long n; linenr_T first = curwin->w_cursor.lnum; diff --git a/src/charset.c b/src/charset.c index 1fbbf98f76..8ad768d354 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1140,6 +1140,22 @@ init_chartabsize_arg( cts->cts_text_props[text_prop_idxs[i]]; vim_free(text_prop_idxs); } + + // Convert tp_text_offset to tp_text pointer. + char_u *count_ptr = prop_start - PROP_COUNT_SIZE; + + for (i = 0; i < count; ++i) + { + textprop_T *tp = &cts->cts_text_props[i]; + + if (tp->tp_id < 0 && tp->u.tp_text_offset > 0) + { + tp->u.tp_text = count_ptr + tp->u.tp_text_offset; + tp->tp_flags |= TP_FLAG_VTEXT_PTR; + } + else + tp->u.tp_text = NULL; + } } } } @@ -1294,7 +1310,7 @@ win_lbr_chartabsize( int charlen = *s == NUL ? 1 : mb_ptr2len(s); int i; int col = (int)(s - line); - garray_T *gap = &wp->w_buffer->b_textprop_text; + // The "$" for 'list' mode will go between the EOL and // the text prop, account for that. @@ -1318,9 +1334,9 @@ win_lbr_chartabsize( && ((tp->tp_flags & TP_FLAG_ALIGN_ABOVE) ? col == 0 : s[0] == NUL && cts->cts_with_trailing))) - && -tp->tp_id - 1 < gap->ga_len) + && tp->u.tp_text != NULL) { - char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; + char_u *p = tp->u.tp_text; if (p != NULL) { diff --git a/src/drawline.c b/src/drawline.c index 87fef7061d..c415d0a131 100644 --- a/src/drawline.c +++ b/src/drawline.c @@ -685,8 +685,7 @@ text_prop_position( int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE); int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW); int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP); - int padding = tp->tp_col == MAXCOL && tp->tp_len > 1 - ? tp->tp_len - 1 : 0; + int padding = tp->tp_col == MAXCOL ? tp->tp_padleft : 0; int col_with_padding = scr_col + (below ? 0 : padding); int room = wp->w_width - col_with_padding; int before = room; // spaces before the text @@ -1705,9 +1704,29 @@ win_line( else text_props = ALLOC_MULT(textprop_T, text_prop_count); if (text_props != NULL) + { mch_memmove(text_props, prop_start, text_prop_count * sizeof(textprop_T)); + // Convert tp_text_offset to tp_text pointer for virtual + // text properties. prop_start points into the memline + // after the prop_count field. + char_u *count_ptr = prop_start - PROP_COUNT_SIZE; + + for (int i = 0; i < text_prop_count; ++i) + { + if (text_props[i].tp_id < 0 + && text_props[i].u.tp_text_offset > 0) + { + text_props[i].u.tp_text = + count_ptr + text_props[i].u.tp_text_offset; + text_props[i].tp_flags |= TP_FLAG_VTEXT_PTR; + } + else + text_props[i].u.tp_text = NULL; + } + } + // Allocate an array for the indexes. if (text_prop_count <= WIN_LINE_TEXT_PROP_STACK_LEN) text_prop_idxs = text_prop_idxs_buf; @@ -2301,13 +2320,10 @@ win_line( } } if (text_prop_id < 0 && used_tpi >= 0 - && -text_prop_id - <= wp->w_buffer->b_textprop_text.ga_len) + && text_props[used_tpi].u.tp_text != NULL) { textprop_T *tp = &text_props[used_tpi]; - char_u *p = ((char_u **)wp->w_buffer - ->b_textprop_text.ga_data)[ - -text_prop_id - 1]; + char_u *p = tp->u.tp_text; int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE); int bail_out = FALSE; @@ -2325,8 +2341,7 @@ win_line( int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP); int padding = tp->tp_col == MAXCOL - && tp->tp_len > 1 - ? tp->tp_len - 1 : 0; + ? tp->tp_padleft : 0; // Insert virtual text before the current // character, or add after the end of the line. diff --git a/src/errors.h b/src/errors.h index 2c04c3c68c..fde1324a17 100644 --- a/src/errors.h +++ b/src/errors.h @@ -1669,7 +1669,8 @@ EXTERN char e_invalid_buffer_identifier_in_setdot[] INIT(= N_("E647: Invalid buffer identifier in setDot")); EXTERN char e_invalid_buffer_identifier_in_close[] INIT(= N_("E648: Invalid buffer identifier in close")); -// E649 unused +EXTERN char e_invalid_identifier_in_defineannotype[] + INIT(= N_("E649: Invalid identifier name in defineAnnoType")); EXTERN char e_invalid_buffer_identifier_in_defineannotype[] INIT(= N_("E650: Invalid buffer identifier in defineAnnoType")); EXTERN char e_invalid_buffer_identifier_in_addanno[] @@ -3435,9 +3436,8 @@ EXTERN char e_internal_error_shortmess_too_long[] #ifdef FEAT_EVAL EXTERN char e_class_variable_str_not_found_in_class_str[] INIT(= N_("E1337: Class variable \"%s\" not found in class \"%s\"")); -// E1338 unused #endif -// E1339 unused +// E1338 and E1339 unused #ifdef FEAT_EVAL EXTERN char e_argument_already_declared_in_class_str[] INIT(= N_("E1340: Argument already declared in the class: %s")); diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 4382ea5b70..efb0c66dc0 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -4895,15 +4895,27 @@ ex_substitute(exarg_T *eap) text_prop_count); if (text_props != NULL) { - int pi; - mch_memmove(text_props, prop_start, text_prop_count * sizeof(textprop_T)); - // After joining the text prop columns will - // increase. - for (pi = 0; pi < text_prop_count; ++pi) - text_props[pi].tp_col += - regmatch.startpos[0].col + sublen - 1; + // Filter out virtual text and continuation + // properties from deleted lines, convert + // offsets to pointers, and adjust columns. + int wi = 0; + for (int pi = 0; pi < text_prop_count; ++pi) + { + // Skip virtual text and continuation + // properties from the deleted line. + if (text_props[pi].tp_id < 0 + || (text_props[pi].tp_flags + & TP_FLAG_CONT_PREV)) + continue; + text_props[wi] = text_props[pi]; + text_props[wi].tp_col += + regmatch.startpos[0].col + sublen - 1; + text_props[wi].u.tp_text = NULL; + ++wi; + } + text_prop_count = wi; } } } @@ -5142,7 +5154,14 @@ skip: break; for (i = 0; i < nmatch_tl; ++i) ml_delete(lnum); - mark_adjust(lnum, lnum + nmatch_tl - 1, + if (copycol > 0) + mark_adjust(lnum, lnum + nmatch_tl - 1, + (long)MAXLNUM, -nmatch_tl); + else + // The entire last matched line was consumed, + // so the first line was effectively replaced + // by lines below. + mark_adjust(lnum - 1, lnum - 1, (long)MAXLNUM, -nmatch_tl); if (subflags.do_ask) deleted_lines(lnum, nmatch_tl); diff --git a/src/globals.h b/src/globals.h index 8f7417fea7..727aec840a 100644 --- a/src/globals.h +++ b/src/globals.h @@ -125,6 +125,23 @@ EXTERN int screen_zindex INIT(= 0); EXTERN win_T *screen_opacity_popup INIT(= NULL); #endif +// Pum opacity level (0 = fully transparent, 100 = fully opaque). +// Set via 'pumopt' opacity: key. +EXTERN long p_po INIT(= 100); + +// Blend value for popup menu opacity (0 = off, 1-99 = blend level). +// Set during pum drawing when pum opacity is active. +EXTERN int screen_pum_blend INIT(= 0); + +// Saved background screen content for pum opacity blending. +EXTERN sattr_T *pum_bg_attrs INIT(= NULL); +EXTERN schar_T *pum_bg_lines INIT(= NULL); +EXTERN u8char_T *pum_bg_linesUC INIT(= NULL); +EXTERN u8char_T *pum_bg_linesC[MAX_MCO]; +EXTERN int pum_bg_top INIT(= 0); +EXTERN int pum_bg_bot INIT(= 0); +EXTERN int pum_bg_cols INIT(= 0); + EXTERN int screen_Rows INIT(= 0); // actual size of ScreenLines[] EXTERN int screen_Columns INIT(= 0); // actual size of ScreenLines[] diff --git a/src/gui_dwrite.cpp b/src/gui_dwrite.cpp index c71358717a..673b6d539c 100644 --- a/src/gui_dwrite.cpp +++ b/src/gui_dwrite.cpp @@ -313,6 +313,9 @@ struct DWriteContext { D2D1_TEXT_ANTIALIAS_MODE mTextAntialiasMode; + DWriteFontFeature mFontFeatures[DWRITE_MAX_FONT_FEATURES]; + int mFontFeatureCount; + // METHODS DWriteContext(); @@ -357,6 +360,8 @@ struct DWriteContext { DWriteRenderingParams *GetRenderingParams( DWriteRenderingParams *params); + + void SetFontFeatures(const DWriteFontFeature *features, int count); }; class AdjustedGlyphRun : public DWRITE_GLYPH_RUN @@ -648,8 +653,10 @@ DWriteContext::DWriteContext() : mFontStyle(DWRITE_FONT_STYLE_NORMAL), mFontSize(0.0f), mFontAscent(0.0f), - mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT) + mTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_DEFAULT), + mFontFeatureCount(0) { + ZeroMemory(mFontFeatures, sizeof(mFontFeatures)); HRESULT hr; hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, @@ -1086,6 +1093,56 @@ DWriteContext::DrawText(const WCHAR *text, int len, textLayout->SetFontWeight(mFontWeight, textRange); textLayout->SetFontStyle(mFontStyle, textRange); + if (mFontFeatureCount > 0) + { + // Default OpenType features that DirectWrite normally enables. + // SetTypography() overrides all defaults, so we must + // re-add them here explicitly. + static const DWRITE_FONT_FEATURE defaultFeatures[] = { + { DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_ALTERNATES, 1 }, + { DWRITE_FONT_FEATURE_TAG_STANDARD_LIGATURES, 1 }, + { DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_LIGATURES, 1 }, + { DWRITE_FONT_FEATURE_TAG_REQUIRED_LIGATURES, 1 }, + { DWRITE_FONT_FEATURE_TAG_KERNING, 1 }, + }; + static const int numDefaults = sizeof(defaultFeatures) + / sizeof(defaultFeatures[0]); + + IDWriteTypography *typography = NULL; + hr = mDWriteFactory->CreateTypography(&typography); + if (SUCCEEDED(hr)) + { + // Add default features, skipping any that the user + // has explicitly specified (either + or -). + for (int d = 0; d < numDefaults; ++d) + { + int overridden = 0; + for (int u = 0; u < mFontFeatureCount; ++u) + { + if ((DWRITE_FONT_FEATURE_TAG)mFontFeatures[u].tag + == defaultFeatures[d].nameTag) + { + overridden = 1; + break; + } + } + if (!overridden) + typography->AddFontFeature(defaultFeatures[d]); + } + // Add user-specified features. + for (int i = 0; i < mFontFeatureCount; ++i) + { + DWRITE_FONT_FEATURE ff = { + (DWRITE_FONT_FEATURE_TAG)mFontFeatures[i].tag, + mFontFeatures[i].parameter + }; + typography->AddFontFeature(ff); + } + textLayout->SetTypography(typography, textRange); + SafeRelease(&typography); + } + } + // Calculate baseline using font ascent from font metrics. // Do NOT use GetLineMetrics() because it returns different values // depending on text content (e.g., when CJK characters trigger @@ -1413,3 +1470,24 @@ DWriteContext_GetRenderingParams( else return NULL; } + + void +DWriteContext::SetFontFeatures( + const DWriteFontFeature *features, int count) +{ + if (count > DWRITE_MAX_FONT_FEATURES) + count = DWRITE_MAX_FONT_FEATURES; + mFontFeatureCount = count; + if (count > 0 && features != NULL) + memcpy(mFontFeatures, features, sizeof(DWriteFontFeature) * count); +} + + void +DWriteContext_SetFontFeatures( + DWriteContext *ctx, + const DWriteFontFeature *features, + int count) +{ + if (ctx != NULL) + ctx->SetFontFeatures(features, count); +} diff --git a/src/gui_dwrite.h b/src/gui_dwrite.h index 5de06f92b1..4c4777764e 100644 --- a/src/gui_dwrite.h +++ b/src/gui_dwrite.h @@ -51,6 +51,13 @@ typedef struct DWriteRenderingParams { int textAntialiasMode; } DWriteRenderingParams; +#define DWRITE_MAX_FONT_FEATURES 32 + +typedef struct DWriteFontFeature { + unsigned int tag; // OpenType feature tag (4 bytes) + unsigned int parameter; // Feature parameter (0 = disable, 1 = enable) +} DWriteFontFeature; + void DWrite_Init(void); void DWrite_Final(void); @@ -86,6 +93,11 @@ DWriteRenderingParams *DWriteContext_GetRenderingParams( DWriteContext *ctx, DWriteRenderingParams *params); +void DWriteContext_SetFontFeatures( + DWriteContext *ctx, + const DWriteFontFeature *features, + int count); + #ifdef __cplusplus } #endif diff --git a/src/gui_w32.c b/src/gui_w32.c index 605897fb2b..093c84176e 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -145,7 +145,6 @@ gui_mch_set_rendering_options(char_u *s) int dx_geom = 0; int dx_renmode = 0; int dx_taamode = 0; - // parse string as rendering options. for (p = s; p != NULL && *p != NUL; ) { @@ -3956,6 +3955,60 @@ gui_mch_init_font(char_u *font_name, int fontset UNUSED) if (font == NOFONT) return FAIL; +#if defined(FEAT_DIRECTX) + // Parse font features from guifont (e.g., ":fss19=1:fcalt=0:fliga=1"). + { + DWriteFontFeature features[DWRITE_MAX_FONT_FEATURES]; + int feat_count = 0; + char_u *fp; + + if (font_name != NULL) + { + // Find each ":f" option in font_name. + for (fp = font_name; *fp != NUL; fp++) + { + if (*fp == ':' && *(fp + 1) == 'f') + { + char_u tag[5]; + int ti = 0; + unsigned int param = 1; + + fp += 2; // skip ":f" + while (*fp != NUL && *fp != '=' && *fp != ':' + && ti < 4) + tag[ti++] = *fp++; + tag[ti] = NUL; + + if (ti != 4) + continue; // invalid tag length + + if (*fp == '=') + { + fp++; + param = (unsigned int)atoi((char *)fp); + while (*fp >= '0' && *fp <= '9') + fp++; + } + + if (feat_count < DWRITE_MAX_FONT_FEATURES) + { + features[feat_count].tag = + ((unsigned int)tag[0]) + | ((unsigned int)tag[1] << 8) + | ((unsigned int)tag[2] << 16) + | ((unsigned int)tag[3] << 24); + features[feat_count].parameter = param; + feat_count++; + } + + fp--; // adjust for loop increment + } + } + } + DWriteContext_SetFontFeatures(s_dwc, features, feat_count); + } +#endif + if (font_name == NULL) font_name = (char_u *)""; #ifdef FEAT_MBYTE_IME diff --git a/src/highlight.c b/src/highlight.c index 70b1ee7868..782820ed11 100644 --- a/src/highlight.c +++ b/src/highlight.c @@ -3321,6 +3321,138 @@ hl_blend_attr(int char_attr, int popup_attr, int blend, int blend_fg UNUSED) return get_attr_entry(&term_attr_table, &new_en); } +/* + * Blend for pum opacity space cells: keep underlying fg, blend bg. + * This is different from hl_blend_attr(blend_fg=TRUE) where fg blends + * in the wrong direction for pum use. + */ + int +hl_pum_blend_attr(int char_attr, int popup_attr, int blend UNUSED) +{ + attrentry_T *char_aep = NULL; + attrentry_T *popup_aep; + attrentry_T new_en; + +#ifdef FEAT_GUI + if (gui.in_use) + { + if (char_attr > HL_ALL) + char_aep = syn_gui_attr2entry(char_attr); + if (char_aep != NULL) + new_en = *char_aep; + else + { + CLEAR_FIELD(new_en); + new_en.ae_u.gui.fg_color = INVALCOLOR; + new_en.ae_u.gui.bg_color = INVALCOLOR; + new_en.ae_u.gui.sp_color = INVALCOLOR; + if (char_attr <= HL_ALL) + new_en.ae_attr = char_attr; + } + if (popup_attr > HL_ALL) + { + popup_aep = syn_gui_attr2entry(popup_attr); + if (popup_aep != NULL) + { + // Blend fg: pum_bg toward underlying_fg. + // blend=0 (opaque): fg = pum_bg (text hidden) + // blend=100 (transparent): fg = underlying_fg (text visible) + if (popup_aep->ae_u.gui.bg_color != INVALCOLOR) + { + int base_fg = 0xFFFFFF; + if (char_aep != NULL + && char_aep->ae_u.gui.fg_color != INVALCOLOR) + base_fg = char_aep->ae_u.gui.fg_color; + new_en.ae_u.gui.fg_color = blend_colors( + popup_aep->ae_u.gui.bg_color, base_fg, blend); + } + // Blend bg: popup bg toward underlying bg. + if (popup_aep->ae_u.gui.bg_color != INVALCOLOR) + { + guicolor_T underlying_bg = INVALCOLOR; + if (char_aep != NULL) + underlying_bg = char_aep->ae_u.gui.bg_color; + new_en.ae_u.gui.bg_color = blend_colors( + popup_aep->ae_u.gui.bg_color, + underlying_bg, blend); + } + } + } + return get_attr_entry(&gui_attr_table, &new_en); + } +#endif + + if (IS_CTERM) + { + if (char_attr > HL_ALL) + char_aep = syn_cterm_attr2entry(char_attr); + if (char_aep != NULL) + new_en = *char_aep; + else + { + CLEAR_FIELD(new_en); +#ifdef FEAT_TERMGUICOLORS + new_en.ae_u.cterm.bg_rgb = INVALCOLOR; + new_en.ae_u.cterm.fg_rgb = INVALCOLOR; + new_en.ae_u.cterm.ul_rgb = INVALCOLOR; +#endif + if (char_attr <= HL_ALL) + new_en.ae_attr = char_attr; + } + if (popup_attr > HL_ALL) + { + popup_aep = syn_cterm_attr2entry(popup_attr); + if (popup_aep != NULL) + { + // Blend cterm fg: use popup bg (hides text when opaque) + if (popup_aep->ae_u.cterm.fg_color > 0) + new_en.ae_u.cterm.fg_color = + popup_aep->ae_u.cterm.fg_color; + // Use popup cterm bg. + if (popup_aep->ae_u.cterm.bg_color > 0) + new_en.ae_u.cterm.bg_color = + popup_aep->ae_u.cterm.bg_color; +#ifdef FEAT_TERMGUICOLORS + // Blend fg_rgb: pum_bg toward underlying_fg. + if (popup_aep->ae_u.cterm.bg_rgb != INVALCOLOR) + { + int base_fg = 0xFFFFFF; + if (char_aep != NULL + && char_aep->ae_u.cterm.fg_rgb != INVALCOLOR) + base_fg = char_aep->ae_u.cterm.fg_rgb; + new_en.ae_u.cterm.fg_rgb = blend_colors( + popup_aep->ae_u.cterm.bg_rgb, base_fg, blend); + } + // Blend bg_rgb. + if (popup_aep->ae_u.cterm.bg_rgb != INVALCOLOR) + { + guicolor_T underlying_bg = INVALCOLOR; + if (char_aep != NULL) + underlying_bg = char_aep->ae_u.cterm.bg_rgb; + new_en.ae_u.cterm.bg_rgb = blend_colors( + popup_aep->ae_u.cterm.bg_rgb, + underlying_bg, blend); + } +#endif + } + } + return get_attr_entry(&cterm_attr_table, &new_en); + } + + // term mode + if (char_attr > HL_ALL) + char_aep = syn_term_attr2entry(char_attr); + if (char_aep != NULL) + new_en = *char_aep; + else + { + CLEAR_FIELD(new_en); + if (char_attr <= HL_ALL) + new_en.ae_attr = char_attr; + } + return get_attr_entry(&term_attr_table, &new_en); +} + #ifdef FEAT_GUI attrentry_T * syn_gui_attr2entry(int attr) diff --git a/src/memline.c b/src/memline.c index 886f08f973..c15946a6eb 100644 --- a/src/memline.c +++ b/src/memline.c @@ -2930,13 +2930,19 @@ add_text_props_for_append( { if (round == 2) { + uint16_t pc; + if (new_prop_count == 0) return; // nothing to do - new_len = *len + new_prop_count * sizeof(textprop_T); + new_len = *len + (int)PROP_COUNT_SIZE + + new_prop_count * (int)sizeof(textprop_T); new_line = alloc(new_len); if (new_line == NULL) return; mch_memmove(new_line, *line, *len); + // Write prop_count header. + pc = (uint16_t)new_prop_count; + mch_memmove(new_line + *len, &pc, PROP_COUNT_SIZE); new_prop_count = 0; } @@ -2954,8 +2960,10 @@ add_text_props_for_append( prop.tp_flags |= TP_FLAG_CONT_PREV; prop.tp_col = 1; prop.tp_len = *len; // not exactly the right length - mch_memmove(new_line + *len + new_prop_count - * sizeof(textprop_T), &prop, sizeof(textprop_T)); + prop.u.tp_text_offset = 0; + mch_memmove(new_line + *len + (int)PROP_COUNT_SIZE + + new_prop_count * sizeof(textprop_T), + &prop, sizeof(textprop_T)); } ++new_prop_count; } @@ -3772,34 +3780,48 @@ adjust_text_props_for_delete( textlen = STRLEN(text) + 1; if ((long)textlen >= line_size) { + // No properties on this line. if (above) internal_error("no text property above deleted line"); else internal_error("no text property below deleted line"); return; } - this_props_len = line_size - (int)textlen; + if ((long)textlen + (long)PROP_COUNT_SIZE > line_size) + { + internal_error("text property data too short"); + return; + } + + uint16_t pc; + + mch_memmove(&pc, text + textlen, PROP_COUNT_SIZE); + this_props_len = pc * (int)sizeof(textprop_T); } found = FALSE; - for (done_this = 0; done_this < this_props_len; - done_this += sizeof(textprop_T)) { - int flag = above ? TP_FLAG_CONT_NEXT - : TP_FLAG_CONT_PREV; - textprop_T prop_this; + char_u *props_start = text + textlen + PROP_COUNT_SIZE; - mch_memmove(&prop_this, text + textlen + done_this, - sizeof(textprop_T)); - if ((prop_this.tp_flags & flag) - && prop_del.tp_id == prop_this.tp_id - && prop_del.tp_type == prop_this.tp_type) + for (done_this = 0; done_this < this_props_len; + done_this += sizeof(textprop_T)) { - found = TRUE; - prop_this.tp_flags &= ~flag; - mch_memmove(text + textlen + done_this, &prop_this, + int flag = above ? TP_FLAG_CONT_NEXT + : TP_FLAG_CONT_PREV; + textprop_T prop_this; + + mch_memmove(&prop_this, props_start + done_this, sizeof(textprop_T)); - break; + if ((prop_this.tp_flags & flag) + && prop_del.tp_id == prop_this.tp_id + && prop_del.tp_type == prop_this.tp_type) + { + found = TRUE; + prop_this.tp_flags &= ~flag; + mch_memmove(props_start + done_this, &prop_this, + sizeof(textprop_T)); + break; + } } } if (!found) @@ -4003,13 +4025,23 @@ theend: #ifdef FEAT_PROP_POPUP if (textprop_save != NULL) { + // textprop_save is [prop_count][textprop_T...][vtext...]. + // Skip prop_count header and pass only the textprop_T part. + uint16_t pc; + char_u *props_data; + int props_bytes; + + mch_memmove(&pc, textprop_save, PROP_COUNT_SIZE); + props_data = textprop_save + PROP_COUNT_SIZE; + props_bytes = pc * (int)sizeof(textprop_T); + // Adjust text properties in the line above and below. if (lnum > 1) - adjust_text_props_for_delete(buf, lnum - 1, textprop_save, - (int)textprop_len, TRUE); + adjust_text_props_for_delete(buf, lnum - 1, + props_data, props_bytes, TRUE); if (lnum <= buf->b_ml.ml_line_count) - adjust_text_props_for_delete(buf, lnum, textprop_save, - (int)textprop_len, FALSE); + adjust_text_props_for_delete(buf, lnum, + props_data, props_bytes, FALSE); } vim_free(textprop_save); #endif diff --git a/src/netbeans.c b/src/netbeans.c index 484228b526..12098982ef 100644 --- a/src/netbeans.c +++ b/src/netbeans.c @@ -40,6 +40,11 @@ #define GUARDEDOFFSET 1000000 // base for "guarded" sign id's #define MAX_COLOR_LENGTH 32 // max length of color name in defineAnnoType +// Characters valid in a sign/highlight group name +#define VALID_CHARS (char_u *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" +#define VALID_SIGNNAME_CHARS VALID_CHARS "_" +#define VALID_COLOR_CHARS VALID_CHARS "#" + // The first implementation (working only with Netbeans) returned "1.1". The // protocol implemented here also supports A-A-P. static char *ExtEdProtocolVersion = "2.5"; @@ -77,6 +82,22 @@ static int dosetvisible = FALSE; static int needupdate = 0; static int inAtomic = 0; +/* + * Return TRUE if "str" contains only characters from "allowed". + * Used to validate NetBeans-supplied strings before interpolating them + * into Ex commands via coloncmd(). + */ + static int +nb_is_safe_string(char_u *str, char_u *allowed) +{ + if (str == NULL) + return FALSE; + for (char_u *p = str; *p != NUL; p++) + if (vim_strchr(allowed, *p) == NULL) + return FALSE; + return TRUE; +} + /* * Callback invoked when the channel is closed. */ @@ -1949,6 +1970,15 @@ nb_do_cmd( VIM_CLEAR(typeName); parse_error = TRUE; } + else if (!nb_is_safe_string(typeName, VALID_SIGNNAME_CHARS) || + (*fg != NUL && !nb_is_safe_string(fg, VALID_COLOR_CHARS)) || + (*bg != NUL && !nb_is_safe_string(bg, VALID_COLOR_CHARS))) + { + nbdebug((" invalid chars in typeName/fg/bg in defineAnnoType\n")); + emsg(_(e_invalid_identifier_in_defineannotype)); + VIM_CLEAR(typeName); + parse_error = TRUE; + } else if (typeName != NULL && tooltip != NULL && glyphFile != NULL) addsigntype(buf, typeNum, typeName, tooltip, glyphFile, fg, bg); @@ -2321,10 +2351,24 @@ special_keys(char_u *args) if (strlen(tok) + i < KEYBUFLEN) { - vim_strncpy((char_u *)&keybuf[i], (char_u *)tok, KEYBUFLEN - i - 1); - vim_snprintf(cmdbuf, sizeof(cmdbuf), - "<%s> :nbkey %s", keybuf, keybuf); - do_map(MAPTYPE_MAP, (char_u *)cmdbuf, MODE_NORMAL, FALSE); + // Only allow alphanumeric and function-key name characters. + // Reject anything else to prevent map command injection. + int safe = TRUE; + for (char_u *tp = (char_u *)tok; *tp != NUL; tp++) + { + if (!ASCII_ISALNUM(*tp) && *tp != '-') + { + safe = FALSE; + break; + } + } + if (safe) + { + vim_strncpy((char_u *)&keybuf[i], (char_u *)tok, KEYBUFLEN - i - 1); + vim_snprintf(cmdbuf, sizeof(cmdbuf), + "<%s> :nbkey %s", keybuf, keybuf); + do_map(MAPTYPE_MAP, (char_u *)cmdbuf, MODE_NORMAL, FALSE); + } } tok = strtok(NULL, " "); } diff --git a/src/ops.c b/src/ops.c index 6ea50c912e..715897331e 100644 --- a/src/ops.c +++ b/src/ops.c @@ -2172,10 +2172,6 @@ do_join( int remove_comments = (use_formatoptions == TRUE) && has_format_option(FO_REMOVE_COMS); int prev_was_comment; -#ifdef FEAT_PROP_POPUP - int propcount = 0; // number of props over all joined lines - int props_remaining; -#endif if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) @@ -2205,10 +2201,6 @@ do_join( for (t = 0; t < count; ++t) { curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); -#ifdef FEAT_PROP_POPUP - propcount += count_props((linenr_T) (curwin->w_cursor.lnum + t), - t > 0, t + 1 == count); -#endif if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '[ mark. @@ -2295,9 +2287,6 @@ do_join( // allocate the space for the new line newp_len = sumsize + 1; -#ifdef FEAT_PROP_POPUP - newp_len += propcount * sizeof(textprop_T); -#endif newp = alloc(newp_len); if (newp == NULL) { @@ -2316,8 +2305,15 @@ do_join( * should not really be a problem. */ #ifdef FEAT_PROP_POPUP - props_remaining = propcount; + unpacked_memline_T um = um_open_at_no_props( + curwin->w_buffer, curwin->w_cursor.lnum, 0); + // um_open_at_no_props may have invalidated "curr". + int curr_off = (int)(curr - curr_start); + + curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + count - 1)); + curr += curr_off; #endif + for (t = count - 1; ; --t) { int spaces_removed; @@ -2338,9 +2334,8 @@ do_join( mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, -t, (long)(cend - newp - spaces_removed), spaces_removed); #ifdef FEAT_PROP_POPUP - prepend_joined_props(newp + sumsize + 1, propcount, &props_remaining, - curwin->w_cursor.lnum + t, t == count - 1, - (long)(cend - newp), spaces_removed); + prepend_joined_props(&um, curwin->w_cursor.lnum + t, + t == count - 1, (long)(cend - newp), spaces_removed); #endif if (t == 0) break; @@ -2352,6 +2347,16 @@ do_join( currsize = (int)STRLEN(curr); } +#ifdef FEAT_PROP_POPUP + if (um.buf != NULL) + { + um_set_text(&um, newp); + um_reverse_props(&um); + um_close(&um); + newp = NULL; // um_set_text took ownership + } + else +#endif ml_replace_len(curwin->w_cursor.lnum, newp, (colnr_T)newp_len, TRUE, FALSE); if (setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) diff --git a/src/option.h b/src/option.h index 0cebcfb950..e2f415726d 100644 --- a/src/option.h +++ b/src/option.h @@ -556,6 +556,7 @@ EXTERN long p_ph; // 'pumheight' EXTERN long p_pw; // 'pumwidth' EXTERN long p_pmw; // 'pummaxwidth' EXTERN char_u *p_pb; // 'pumborder' +EXTERN char_u *p_pumopt; // 'pumopt' EXTERN char_u *p_com; // 'comments' EXTERN char_u *p_cpo; // 'cpoptions' #ifdef FEAT_CSCOPE diff --git a/src/optiondefs.h b/src/optiondefs.h index fa9854b385..1bf67a8ce6 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -2201,6 +2201,10 @@ static struct vimoption options[] = {"pummaxwidth", "pmw", P_NUM|P_VI_DEF, (char_u *)&p_pmw, PV_NONE, NULL, NULL, {(char_u *)0L, (char_u *)0L} SCTX_INIT}, + {"pumopt", NULL, P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_COLON, + (char_u *)&p_pumopt, PV_NONE, + did_set_pumopt, expand_set_pumopt, + {(char_u *)"", (char_u *)NULL} SCTX_INIT}, {"pumwidth", "pw", P_NUM|P_VI_DEF, (char_u *)&p_pw, PV_NONE, NULL, NULL, {(char_u *)15L, (char_u *)15L} SCTX_INIT}, diff --git a/src/optionstr.c b/src/optionstr.c index e0c9790539..f687a60967 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -3706,6 +3706,197 @@ expand_set_rightleftcmd(optexpand_T *args, int *numMatches, char_u ***matches) pum_set_margin(FALSE); \ } while (0) +/* + * Parse a border value from a pumopt "border:" token. + * Returns OK on success, FAIL on error. + */ + static int +parse_pumopt_border(char_u *val, int len) +{ + // Use box-drawing characters only when 'encoding' is "utf-8" and + // 'ambiwidth' is "single". + int can_use_box_chars = (enc_utf8 && *p_ambw == 's'); + char_u *token; + + token = vim_strnsave(val, len); + if (token == NULL) + return FAIL; + + if (can_use_box_chars && STRCMP(token, "single") == 0) + pum_set_border_chars(0x2500, 0x2502, 0x2500, 0x2502, // ─ │ ─ │ + 0x250c, 0x2510, 0x2518, 0x2514); // ┌ ┐ ┘ └ + else if (can_use_box_chars && STRCMP(token, "double") == 0) + pum_set_border_chars(0x2550, 0x2551, 0x2550, 0x2551, // ═ ║ ═ ║ + 0x2554, 0x2557, 0x255D, 0x255A); // ╔ ╗ ╝ ╚ + else if (can_use_box_chars && STRCMP(token, "round") == 0) + pum_set_border_chars(0x2500, 0x2502, 0x2500, 0x2502, // ─ │ ─ │ + 0x256d, 0x256e, 0x256f, 0x2570); // ╭ ╮ ╯ ╰ + else if (STRCMP(token, "ascii") == 0) + pum_set_border_chars('-', '|', '-', '|', '+', '+', '+', '+'); + else if (STRNCMP(token, "custom:", 7) == 0) + { + char_u *q = token + 7; + int out[8]; + + for (int i = 0; i < 8; i++) + { + if (*q == NUL || *q == ',') + { + vim_free(token); + return FAIL; + } + out[i] = mb_ptr2char(q); + mb_ptr2char_adv(&q); + if (i < 7) + { + if (*q != ';') + { + vim_free(token); + return FAIL; + } + q++; + } + } + if (*q != NUL && *q != ',') + { + vim_free(token); + return FAIL; + } + pum_set_border_chars(out[0], out[1], out[2], out[3], out[4], out[5], + out[6], out[7]); + } + else + { + vim_free(token); + return FAIL; + } + + vim_free(token); + pum_set_border(TRUE); + return OK; +} + +/* + * The 'pumopt' option is changed. + * Format: comma-separated key:value pairs. + * border:{single|double|round|ascii|custom:X;X;X;X;X;X;X;X} + * height:{n} + * width:{n} + * maxwidth:{n} + * opacity:{n} + * shadow + * margin (requires border) + */ + char * +did_set_pumopt(optset_T *args) +{ + char_u **varp = (char_u **)args->os_varp; + char_u *p; + int have_border = FALSE; + int have_margin = FALSE; + + // Reset to defaults. + PUM_BORDER_CLEAR(); + p_ph = 0; + p_pw = 15; + p_pmw = 0; + p_po = 100; + + if (*varp == NULL || **varp == NUL) + return NULL; + + for (p = *varp; p != NULL && *p != NUL; ) + { + char_u *comma = vim_strchr(p, ','); + int len; + + if (comma != NULL) + len = (int)(comma - p); + else + len = (int)STRLEN(p); + + if (STRNCMP(p, "border:", 7) == 0) + { + if (have_border) + goto error; + have_border = TRUE; + if (parse_pumopt_border(p + 7, len - 7) == FAIL) + goto error; + } + else if (STRNCMP(p, "height:", 7) == 0) + { + long n = atol((char *)p + 7); + if (n < 0) + goto error; + p_ph = n; + } + else if (STRNCMP(p, "width:", 6) == 0) + { + long n = atol((char *)p + 6); + if (n < 0) + goto error; + p_pw = n; + } + else if (STRNCMP(p, "maxwidth:", 9) == 0) + { + long n = atol((char *)p + 9); + if (n < 0) + goto error; + p_pmw = n; + } + else if (STRNCMP(p, "opacity:", 8) == 0) + { + long n = atol((char *)p + 8); + if (n < 0 || n > 100) + goto error; + p_po = n; + } + else if (len == 6 && STRNCMP(p, "shadow", 6) == 0) + pum_set_shadow(TRUE); + else if (len == 6 && STRNCMP(p, "margin", 6) == 0) + { + have_margin = TRUE; + pum_set_margin(TRUE); + } + else + goto error; + + if (comma != NULL) + p = comma + 1; + else + break; + } + + if (have_margin && !have_border) + goto error; + + // Invalidate cached background for opacity changes. + pum_opacity_changed(); + + return NULL; + +error: + PUM_BORDER_CLEAR(); + p_ph = 0; + p_pw = 15; + p_pmw = 0; + p_po = 100; + return e_invalid_argument; +} + + int +expand_set_pumopt(optexpand_T *args, int *numMatches, char_u ***matches) +{ + static char *(p_pumopt_values[]) = {"border:", "height:", "width:", + "maxwidth:", "opacity:", "shadow", "margin", NULL}; + return expand_set_opt_string( + args, + p_pumopt_values, + ARRAY_LENGTH(p_pumopt_values) - 1, + numMatches, + matches); +} + /* * The 'pumborder' option is changed. * Rules: @@ -3717,10 +3908,7 @@ expand_set_rightleftcmd(optexpand_T *args, int *numMatches, char_u ***matches) did_set_pumborder(optset_T *args) { char_u **varp = (char_u **)args->os_varp; - // Use box-drawing characters only when 'encoding' is "utf-8" and - // 'ambiwidth' is "single". - int can_use_box_chars = (enc_utf8 && *p_ambw == 's'); - char_u *p, *token; + char_u *p; int len; int have_border = FALSE; int have_margin = FALSE; @@ -3732,89 +3920,36 @@ did_set_pumborder(optset_T *args) for (p = *varp; p != NULL && *p != NUL; ) { - // end of token is either ',' or NUL char_u *comma = vim_strchr(p, ','); if (comma != NULL) len = (int)(comma - p); else len = (int)STRLEN(p); - token = vim_strnsave(p, len); - if (token == NULL) - goto error; - - if ((can_use_box_chars && (STRCMP(token, "single") == 0 - || STRCMP(token, "double") == 0 - || STRCMP(token, "round") == 0)) - || STRCMP(token, "ascii") == 0 - || (STRNCMP(token, "custom:", 7) == 0)) - { - if (have_border) - { - // multiple border styles not allowed - vim_free(token); - goto error; - } - have_border = TRUE; - - if (STRCMP(token, "single") == 0) - pum_set_border_chars(0x2500, 0x2502, 0x2500, 0x2502, // ─ │ ─ │ - 0x250c, 0x2510, 0x2518, 0x2514); // ┌ ┐ ┘ └ - else if (STRCMP(token, "double") == 0) - pum_set_border_chars(0x2550, 0x2551, 0x2550, 0x2551, // ═ ║ ═ ║ - 0x2554, 0x2557, 0x255D, 0x255A); // ╔ ╗ ╝ ╚ - else if (STRCMP(token, "round") == 0) - pum_set_border_chars(0x2500, 0x2502, 0x2500, 0x2502, // ─ │ ─ │ - 0x256d, 0x256e, 0x256f, 0x2570); // ╭ ╮ ╯ ╰ - else if (STRCMP(token, "ascii") == 0) - pum_set_border_chars('-', '|', '-', '|', '+', '+', '+', '+'); - else if (STRNCMP(token, "custom:", 7) == 0) - { - char_u *q = token + 7; - int out[8]; - - for (int i = 0; i < 8; i++) - { - if (*q == NUL || *q == ',') - goto error; - out[i] = mb_ptr2char(q); - mb_ptr2char_adv(&q); - if (i < 7) - { - if (*q != ';') - goto error; // must be semicolon - q++; - } - } - if (*q != NUL && *q != ',') // must end exactly after the 8th char - goto error; - pum_set_border_chars(out[0], out[1], out[2], out[3], out[4], out[5], - out[6], out[7]); - } - } - else if (STRCMP(token, "shadow") == 0) + if (STRNCMP(p, "shadow", len) == 0 && len == 6) pum_set_shadow(TRUE); - else if (STRCMP(token, "margin") == 0) + else if (STRNCMP(p, "margin", len) == 0 && len == 6) { have_margin = TRUE; pum_set_margin(TRUE); } else { - vim_free(token); - goto error; + if (have_border) + goto error; + have_border = TRUE; + if (parse_pumopt_border(p, len) == FAIL) + goto error; } - vim_free(token); - if (comma != NULL) - p = comma + 1; // move to next token (skip comma) + p = comma + 1; else break; } if (have_margin && !have_border) - goto error; // margin must be combined with border + goto error; return NULL; @@ -3827,12 +3962,12 @@ error: int expand_set_pumborder(optexpand_T *args, int *numMatches, char_u ***matches) { - static char *(p_rlc_values[]) = {"single", "double", "round", "ascii", + static char *(p_pb_values[]) = {"single", "double", "round", "ascii", "custom", "shadow", "margin", NULL}; return expand_set_opt_string( args, - p_rlc_values, - ARRAY_LENGTH(p_rlc_values) - 1, + p_pb_values, + ARRAY_LENGTH(p_pb_values) - 1, numMatches, matches); } diff --git a/src/os_mswin.c b/src/os_mswin.c index be71fac73f..6eaf84f6ce 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -3210,6 +3210,12 @@ get_logfont( } } break; + case L'f': + // Font features (e.g., "fss19=1"). + // Parsed separately by gui_mch_init_font(); skip here. + while (*p && *p != L':') + p++; + break; case L'q': for (i = 0; i < (int)ARRAY_LENGTH(quality_pairs); ++i) { diff --git a/src/po/vim.pot b/src/po/vim.pot index e57893d24d..b2e3b0f647 100644 --- a/src/po/vim.pot +++ b/src/po/vim.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Vim\n" "Report-Msgid-Bugs-To: vim-dev@vim.org\n" -"POT-Creation-Date: 2026-04-06 13:30+0000\n" +"POT-Creation-Date: 2026-04-07 19:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -5867,6 +5867,9 @@ msgstr "" msgid "E648: Invalid buffer identifier in close" msgstr "" +msgid "E649: Invalid identifier name in defineAnnoType" +msgstr "" + msgid "E650: Invalid buffer identifier in defineAnnoType" msgstr "" @@ -10012,6 +10015,9 @@ msgstr "" msgid "popup border style" msgstr "" +msgid "additional options for the popup menu" +msgstr "" + msgid "user defined function for Insert mode completion" msgstr "" diff --git a/src/popupmenu.c b/src/popupmenu.c index b8c72d44f8..2ee720087d 100644 --- a/src/popupmenu.c +++ b/src/popupmenu.c @@ -406,11 +406,17 @@ pum_call_update_screen(void) int pum_under_menu(int row, int col, int only_redrawing) { + int extra_left = pum_border + (pum_margin && pum_border ? 1 : 0); + int extra_right = pum_border + (pum_margin && pum_border ? 1 : 0) + + (pum_shadow ? 2 : 0); + int extra_above = pum_border; + int extra_below = pum_border + (pum_shadow ? 1 : 0); + return (!only_redrawing || pum_will_redraw) - && row >= pum_row - && row < pum_row + pum_height - && col >= pum_col - 1 - && col < pum_col + pum_width + pum_scrollbar; + && row >= pum_row - extra_above + && row < pum_row + pum_height + extra_below + && col >= pum_col - 1 - extra_left + && col < pum_col + pum_width + pum_scrollbar + extra_right; } /* @@ -878,6 +884,42 @@ pum_align_order(int *order) order[2] = is_default ? CPT_MENU : cia_flags % 10; } +static void pum_free_bg(void); + +/* + * Called when the pum opacity value has changed. + * Invalidates cached background and triggers redraw if pum is visible. + */ + void +pum_opacity_changed(void) +{ + // Invalidate cached background so it gets re-saved. + pum_free_bg(); + + if (pum_visible()) + { + // Force full screen clear so ScreenAttrs doesn't retain + // stale blended values from the previous pumopacity. + redraw_all_later(UPD_CLEAR); + call_update_screen = TRUE; + pum_redraw(); + } +} + + static void +pum_free_bg(void) +{ + int k; + VIM_CLEAR(pum_bg_attrs); + VIM_CLEAR(pum_bg_lines); + VIM_CLEAR(pum_bg_linesUC); + for (k = 0; k < MAX_MCO; ++k) + VIM_CLEAR(pum_bg_linesC[k]); + pum_bg_top = 0; + pum_bg_bot = 0; + pum_bg_cols = 0; +} + /* * Redraw the popup menu, using "pum_first" and "pum_selected". */ @@ -906,6 +948,7 @@ pum_redraw(void) int orig_attr = -1; int scroll_range = pum_size - pum_height; bool override_success; + int opacity_active = (p_po > 0 && p_po < 100); // Use current window for highlight overrides when using 'winhighlight' override_success = push_highlight_overrides(curwin->w_hl, curwin->w_hl_len); @@ -925,11 +968,97 @@ pum_redraw(void) if (call_update_screen) { call_update_screen = FALSE; - // Do not redraw in pum_may_redraw() and don't draw in the area where - // the popup menu will be. - pum_will_redraw = TRUE; - update_screen(0); - pum_will_redraw = FALSE; + // Invalidate cached background if screen size changed (e.g. + // after window resize). + if (opacity_active && pum_bg_lines != NULL + && (pum_bg_cols != screen_Columns + || pum_bg_bot > screen_Rows)) + pum_free_bg(); + + if (opacity_active && pum_bg_lines != NULL) + { + // Already have saved background; skip update_screen to avoid + // flickering. Just do a normal pum_will_redraw update. + pum_will_redraw = TRUE; + update_screen(0); + pum_will_redraw = FALSE; + } + else if (opacity_active) + { + // For opacity: draw background including the area under the + // pum, then save it. + pum_pretend_not_visible = TRUE; + update_screen(0); + pum_pretend_not_visible = FALSE; + + // Save background to static buffers. + if (ScreenLines != NULL && ScreenAttrs != NULL) + { + int save_top, save_bot, save_ncells, k; + + pum_free_bg(); + save_top = pum_row - pum_border; + save_bot = pum_row + pum_height + pum_border + + (pum_shadow ? 1 : 0) + 1; + if (save_top < 0) + save_top = 0; + if (save_bot > screen_Rows) + save_bot = screen_Rows; + pum_bg_top = save_top; + pum_bg_bot = save_bot; + pum_bg_cols = screen_Columns; + if (save_top < save_bot) + { + save_ncells = (save_bot - save_top) * screen_Columns; + pum_bg_attrs = LALLOC_MULT(sattr_T, save_ncells); + pum_bg_lines = LALLOC_MULT(schar_T, save_ncells); + if (enc_utf8) + { + pum_bg_linesUC = LALLOC_MULT(u8char_T, save_ncells); + for (k = 0; k < MAX_MCO; ++k) + pum_bg_linesC[k] = LALLOC_MULT(u8char_T, + save_ncells); + } + if (pum_bg_attrs != NULL && pum_bg_lines != NULL) + { + for (int r = save_top; r < save_bot; ++r) + { + int soff = (r - save_top) * screen_Columns; + int loff = LineOffset[r]; + + mch_memmove(pum_bg_attrs + soff, + ScreenAttrs + loff, + screen_Columns * sizeof(sattr_T)); + mch_memmove(pum_bg_lines + soff, + ScreenLines + loff, + screen_Columns * sizeof(schar_T)); + if (enc_utf8 && pum_bg_linesUC != NULL + && ScreenLinesUC != NULL) + { + mch_memmove(pum_bg_linesUC + soff, + ScreenLinesUC + loff, + screen_Columns * sizeof(u8char_T)); + for (k = 0; k < MAX_MCO; ++k) + if (pum_bg_linesC[k] != NULL + && ScreenLinesC[k] != NULL) + mch_memmove(pum_bg_linesC[k] + soff, + ScreenLinesC[k] + loff, + screen_Columns + * sizeof(u8char_T)); + } + } + } + } + } + } + else + { + // Do not redraw in pum_may_redraw() and don't draw in the area + // where the popup menu will be. + pum_will_redraw = TRUE; + update_screen(0); + pum_will_redraw = FALSE; + } } // never display more than we have @@ -950,12 +1079,18 @@ pum_redraw(void) screen_zindex = POPUPMENU_ZINDEX; #endif - // Draw border and shadow first if enabled + // Draw border and shadow first if enabled, before setting blend + // so that border/shadow characters are drawn without opacity. if (pum_border) pum_draw_border(); if (pum_shadow) pum_draw_shadow(); + // Set blend for screen_puts_len / screen_fill to use. + // Only the pum content area should be blended, not border/shadow. + if (opacity_active) + screen_pum_blend = 100 - (int)p_po; + for (i = 0; i < pum_height; ++i) { idx = i + pum_first; @@ -967,7 +1102,8 @@ pum_redraw(void) #ifdef FEAT_RIGHTLEFT if (pum_rl) { - if (pum_col < curwin->w_wincol + curwin->w_width - 1 - pum_border) + if (pum_col < curwin->w_wincol + curwin->w_width - 1 + - pum_border) screen_putchar(' ', row, pum_col + 1, attr); } else @@ -1032,8 +1168,8 @@ pum_redraw(void) #ifdef FEAT_RIGHTLEFT if (pum_rl) - screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', - ' ', orig_attr); + screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, + ' ', ' ', orig_attr); else #endif screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', @@ -1043,6 +1179,8 @@ pum_redraw(void) ++row; } + screen_pum_blend = 0; + #ifdef FEAT_PROP_POPUP screen_zindex = 0; #endif @@ -1427,6 +1565,7 @@ pum_set_selected(int n, int repeat UNUSED) void pum_undisplay(void) { + pum_free_bg(); pum_array = NULL; redraw_all_later(UPD_NOT_VALID); redraw_tabline = TRUE; diff --git a/src/popupwin.c b/src/popupwin.c index 3ab96cb3e5..d5fdbb8d26 100644 --- a/src/popupwin.c +++ b/src/popupwin.c @@ -46,6 +46,8 @@ static void may_start_message_win_timer(win_T *wp); static int popup_on_cmdline = FALSE; static void popup_adjust_position(win_T *wp); +static void redraw_under_popup_area(int winrow, int wincol, int height, + int width, int leftoff); /* * Get option value for "key", which is "line" or "col". @@ -1316,9 +1318,9 @@ popup_adjust_position(win_T *wp) int screen_ecol; // Popup window is positioned relative to a text property. - if (find_visible_prop(prop_win, + if (!find_visible_prop(prop_win, wp->w_popup_prop_type, wp->w_popup_prop_id, - &prop, &prop_lnum) == FAIL) + &prop, &prop_lnum)) { // Text property is no longer visible, hide the popup. // Unhiding the popup is done in check_popup_unhidden(). @@ -3107,6 +3109,14 @@ f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) { int id; win_T *wp; +#ifdef FEAT_PROP_POPUP + int old_popup_active; +#endif + int old_winrow; + int old_wincol; + int old_popup_height; + int old_popup_width; + int old_popup_leftoff; if (in_vim9script() && (check_for_number_arg(argvars, 0) == FAIL @@ -3118,6 +3128,16 @@ f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) if (wp == NULL) return; +#ifdef FEAT_PROP_POPUP + old_popup_active = (wp->w_popup_flags & POPF_OPACITY) + && wp->w_popup_blend > 0; +#endif + old_winrow = wp->w_winrow; + old_wincol = wp->w_wincol; + old_popup_height = popup_height(wp); + old_popup_width = popup_width(wp); + old_popup_leftoff = wp->w_popup_leftoff; + if (check_for_string_or_list_arg(argvars, 1) == FAIL) return; @@ -3132,6 +3152,17 @@ f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) if (must_redraw < UPD_VALID) must_redraw = UPD_VALID; popup_adjust_position(wp); + +#ifdef FEAT_PROP_POPUP + if (old_popup_active + && (old_winrow != wp->w_winrow + || old_wincol != wp->w_wincol + || old_popup_height != popup_height(wp) + || old_popup_width != popup_width(wp) + || old_popup_leftoff != wp->w_popup_leftoff)) + redraw_under_popup_area(old_winrow, old_wincol, + old_popup_height, old_popup_width, old_popup_leftoff); +#endif } /* @@ -3316,6 +3347,49 @@ close_all_popups(int force) return; } +/* + * Force windows under a popup area to redraw. + */ + static void +redraw_under_popup_area(int winrow, int wincol, int height, int width, int leftoff) +{ + int r; + + for (r = winrow; r < winrow + height && r < screen_Rows; ++r) + { + int c; + win_T *prev_twp = NULL; + + if (r >= cmdline_row) + { + clear_cmdline = TRUE; + continue; + } + + for (c = wincol; c < wincol + width - leftoff && c < screen_Columns; ++c) + { + int line_cp = r; + int col_cp = c; + win_T *twp; + + twp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP); + if (twp != NULL && twp != prev_twp) + { + prev_twp = twp; + if (line_cp < twp->w_height) + { + linenr_T lnum; + + (void)mouse_comp_pos(twp, &line_cp, &col_cp, &lnum, NULL); + redrawWinline(twp, lnum); + } + else if (line_cp == twp->w_height) + twp->w_redr_status = TRUE; + } + } + } +} + /* * popup_move({id}, {options}) */ @@ -3329,6 +3403,9 @@ f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) int old_wincol; int old_height; int old_width; + int old_popup_height; + int old_popup_width; + int old_popup_leftoff; if (in_vim9script() && (check_for_number_arg(argvars, 0) == FAIL @@ -3349,6 +3426,9 @@ f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) old_wincol = wp->w_wincol; old_height = wp->w_height; old_width = wp->w_width; + old_popup_height = popup_height(wp); + old_popup_width = popup_width(wp); + old_popup_leftoff = wp->w_popup_leftoff; apply_move_options(wp, dict); @@ -3367,39 +3447,8 @@ f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) redraw_win_later(wp, UPD_NOT_VALID); if ((wp->w_popup_flags & POPF_OPACITY) && wp->w_popup_blend > 0) - { - int total_h = old_height + popup_top_extra(wp) - + wp->w_popup_border[2] + wp->w_popup_padding[2]; - int row; - - for (row = old_winrow; - row < old_winrow + total_h && row < screen_Rows; ++row) - { - if (row >= cmdline_row) - clear_cmdline = TRUE; - else - { - int line_cp = row; - int col_cp = old_wincol; - win_T *twp; - - twp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP); - if (twp != NULL) - { - if (line_cp >= twp->w_height) - twp->w_redr_status = TRUE; - else - { - linenr_T lnum; - - (void)mouse_comp_pos(twp, &line_cp, &col_cp, - &lnum, NULL); - redrawWinline(twp, lnum); - } - } - } - } - } + redraw_under_popup_area(old_winrow, old_wincol, + old_popup_height, old_popup_width, old_popup_leftoff); } } @@ -3415,7 +3464,13 @@ f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) linenr_T old_firstline; #ifdef FEAT_PROP_POPUP int old_blend; + int old_popup_active; #endif + int old_winrow; + int old_wincol; + int old_popup_height; + int old_popup_width; + int old_popup_leftoff; int old_zindex; int old_popup_flags; char_u *old_scrollbar_highlight; @@ -3441,7 +3496,14 @@ f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) old_firstline = wp->w_firstline; #ifdef FEAT_PROP_POPUP old_blend = wp->w_popup_blend; + old_popup_active = (wp->w_popup_flags & POPF_OPACITY) + && wp->w_popup_blend > 0; #endif + old_winrow = wp->w_winrow; + old_wincol = wp->w_wincol; + old_popup_height = popup_height(wp); + old_popup_width = popup_width(wp); + old_popup_leftoff = wp->w_popup_leftoff; old_zindex = wp->w_zindex; old_popup_flags = wp->w_popup_flags; old_scrollbar_highlight = wp->w_scrollbar_highlight; @@ -3514,6 +3576,17 @@ f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) // popup_adjust_position() only sets popup_mask_refresh when the // position or size actually changed. popup_adjust_position(wp); + +#ifdef FEAT_PROP_POPUP + if (old_popup_active + && (old_winrow != wp->w_winrow + || old_wincol != wp->w_wincol + || old_popup_height != popup_height(wp) + || old_popup_width != popup_width(wp) + || old_popup_leftoff != wp->w_popup_leftoff)) + redraw_under_popup_area(old_winrow, old_wincol, + old_popup_height, old_popup_width, old_popup_leftoff); +#endif } /* @@ -4234,7 +4307,7 @@ check_popup_unhidden(win_T *wp) if ((wp->w_popup_flags & POPF_HIDDEN_FORCE) == 0 && find_visible_prop(wp->w_popup_prop_win, wp->w_popup_prop_type, wp->w_popup_prop_id, - &prop, &lnum) == OK) + &prop, &lnum)) { wp->w_popup_flags &= ~POPF_HIDDEN; wp->w_popup_prop_topline = 0; // force repositioning @@ -4755,10 +4828,15 @@ draw_opacity_padding_cell( && utf_char2cells(ScreenLinesUC[base_off]) == 2) { // The left half still has the wide char on screen. - // Clear it to a space. + // Clear it to an unblended space: only the right half is + // covered by the popup background. ScreenLines[base_off] = ' '; ScreenLinesUC[base_off] = 0; ScreenAttrs[base_off] = saved_screenattrs[base_save_off]; + popup_set_base_screen_cell(row, base_col, + ScreenLines[base_off], + ScreenAttrs[base_off], + ScreenLinesUC[base_off]); screen_char(base_off, row, base_col); // Draw padding in the right half. @@ -4778,43 +4856,6 @@ draw_opacity_padding_cell( return; } - // screen_line() already cleared the base cell (popup - // content was a space). Restore the full wide char from - // saved background so it shows through with opacity. - if (base_save_off >= 0 - && saved_screenlinesuc != NULL - && saved_screenlinesuc[base_save_off] != 0 - && utf_char2cells( - saved_screenlinesuc[base_save_off]) == 2) - { - ScreenLines[base_off] = - saved_screenlines[base_save_off]; - ScreenLinesUC[base_off] = - saved_screenlinesuc[base_save_off]; - ScreenLines[off] = saved_screenlines[save_off]; - ScreenLinesUC[off] = saved_screenlinesuc[save_off]; - ScreenAttrs[base_off] = - saved_screenattrs[base_save_off]; - ScreenAttrs[off] = saved_screenattrs[save_off]; - - int popup_attr_val = - get_win_attr(screen_opacity_popup); - int blend = screen_opacity_popup->w_popup_blend; - ScreenAttrs[base_off] = hl_blend_attr( - ScreenAttrs[base_off], - popup_attr_val, blend, TRUE); - ScreenAttrs[off] = ScreenAttrs[base_off]; - popup_set_base_screen_cell(row, base_col, - ScreenLines[base_off], - ScreenAttrs[base_off], - ScreenLinesUC[base_off]); - popup_set_base_screen_cell(row, col, - ScreenLines[off], ScreenAttrs[off], - ScreenLinesUC[off]); - screen_char(base_off, row, base_col); - return; - } - // Draw padding in the right half. ScreenLines[off] = ' '; ScreenAttrs[off] = saved_screenattrs[save_off]; diff --git a/src/proto/highlight.pro b/src/proto/highlight.pro index 5d92317396..856ce86b37 100644 --- a/src/proto/highlight.pro +++ b/src/proto/highlight.pro @@ -21,6 +21,7 @@ int get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg); void clear_hl_tables(void); int hl_combine_attr(int char_attr, int prim_attr); int hl_blend_attr(int char_attr, int popup_attr, int blend, int blend_fg); +int hl_pum_blend_attr(int char_attr, int popup_attr, int blend); attrentry_T *syn_gui_attr2entry(int attr); int syn_attr2attr(int attr); attrentry_T *syn_term_attr2entry(int attr); diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro index be7660d1d3..08896413da 100644 --- a/src/proto/optionstr.pro +++ b/src/proto/optionstr.pro @@ -136,6 +136,8 @@ int expand_set_printoptions(optexpand_T *args, int *numMatches, char_u ***matche char *did_set_renderoptions(optset_T *args); char *did_set_rightleftcmd(optset_T *args); int expand_set_rightleftcmd(optexpand_T *args, int *numMatches, char_u ***matches); +char *did_set_pumopt(optset_T *args); +int expand_set_pumopt(optexpand_T *args, int *numMatches, char_u ***matches); char *did_set_pumborder(optset_T *args); int expand_set_pumborder(optexpand_T *args, int *numMatches, char_u ***matches); char *did_set_rulerformat(optset_T *args); diff --git a/src/proto/popupmenu.pro b/src/proto/popupmenu.pro index 66316dfab2..4afd678125 100644 --- a/src/proto/popupmenu.pro +++ b/src/proto/popupmenu.pro @@ -5,6 +5,7 @@ void pum_set_margin(int enable); void pum_display(pumitem_T *array, int size, int selected); void pum_call_update_screen(void); int pum_under_menu(int row, int col, int only_redrawing); +void pum_opacity_changed(void); void pum_redraw(void); void pum_position_info_popup(win_T *wp); void pum_undisplay(void); diff --git a/src/proto/textprop.pro b/src/proto/textprop.pro index 4b9a7a4491..d3ecf6d14c 100644 --- a/src/proto/textprop.pro +++ b/src/proto/textprop.pro @@ -1,4 +1,13 @@ /* textprop.c */ +unpacked_memline_T um_open(buf_T *buf); +bool um_goto_line(unpacked_memline_T *um, linenr_T lnum, int extra_props); +unpacked_memline_T um_open_at(buf_T *buf, linenr_T lnum, int extra_props); +bool um_set_text(unpacked_memline_T *um, char_u *text); +void um_reverse_props(unpacked_memline_T *um); +unpacked_memline_T um_open_at_no_props(buf_T *buf, linenr_T lnum, int prop_count); +void um_delete_prop(unpacked_memline_T *um, int index); +void um_close(unpacked_memline_T *um); +void um_abort(unpacked_memline_T *um); int find_prop_type_id(char_u *name, buf_T *buf); void f_prop_add(typval_T *argvars, typval_T *rettv); void f_prop_add_list(typval_T *argvars, typval_T *rettv); @@ -7,10 +16,11 @@ int get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change); int prop_count_above_below(buf_T *buf, linenr_T lnum); int count_props(linenr_T lnum, int only_starting, int last_line); void sort_text_props(buf_T *buf, textprop_T *props, int *idxs, int count); -int find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, linenr_T *found_lnum); +bool find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, linenr_T *found_lnum); +char_u *props_add_count_header(char_u *line, int line_len, int textlen, int *new_len); void add_text_props(linenr_T lnum, textprop_T *text_props, int text_prop_count); proptype_T *text_prop_type_by_id(buf_T *buf, int id); -int text_prop_type_valid(buf_T *buf, textprop_T *prop); +bool text_prop_type_valid(buf_T *buf, textprop_T *prop); void f_prop_clear(typval_T *argvars, typval_T *rettv); void f_prop_find(typval_T *argvars, typval_T *rettv); void f_prop_list(typval_T *argvars, typval_T *rettv); @@ -24,5 +34,5 @@ void clear_global_prop_types(void); void clear_buf_prop_types(buf_T *buf); int adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added, int flags); void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted, int at_eol); -void prepend_joined_props(char_u *new_props, int propcount, int *props_remaining, linenr_T lnum, int last_line, long col, int removed); +void prepend_joined_props(unpacked_memline_T *um, linenr_T lnum, int last_line, long col, int removed); /* vim: set ft=c : */ diff --git a/src/screen.c b/src/screen.c index 7065ee960f..2e7ad97eaf 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2680,6 +2680,34 @@ screen_fill( } skip_opacity_fill: #endif + // For pum opacity: blend pum background with underlying. + // Only for space cells; text cells are handled normally. + if (screen_pum_blend > 0 && c == ' ' + && pum_bg_attrs != NULL + && row >= pum_bg_top && row < pum_bg_bot + && col < pum_bg_cols) + { + int soff = (row - pum_bg_top) * pum_bg_cols + col; + int underlying_attr = pum_bg_attrs[soff]; + + // Restore underlying character so text shows through. + ScreenLines[off] = pum_bg_lines[soff]; + if (enc_utf8 && pum_bg_linesUC != NULL + && ScreenLinesUC != NULL) + { + int k; + ScreenLinesUC[off] = pum_bg_linesUC[soff]; + for (k = 0; k < MAX_MCO; ++k) + if (pum_bg_linesC[k] != NULL + && ScreenLinesC[k] != NULL) + ScreenLinesC[k][off] = pum_bg_linesC[k][soff]; + } + // Keep underlying fg, blend bg only. + ScreenAttrs[off] = hl_pum_blend_attr(underlying_attr, + attr, screen_pum_blend); + screen_char(off, row, col); + goto next_col; + } #if defined(FEAT_GUI) || defined(UNIX) // The bold trick may make a single row of pixels appear in // the next character. When a bold character is removed, the @@ -2736,9 +2764,7 @@ skip_opacity_fill: if (!did_delete || c != ' ') screen_char(off, row, col); } -#ifdef FEAT_PROP_POPUP next_col: -#endif ScreenCols[off] = -1; ++off; if (col == start_col) diff --git a/src/structs.h b/src/structs.h index 5c1d59f00e..a7a84ebf5c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -893,13 +893,22 @@ typedef struct memline typedef struct textprop_S { colnr_T tp_col; // start column (one based, in bytes) - colnr_T tp_len; // length in bytes, when tp_id is negative used - // for left padding plus one + colnr_T tp_len; // length in bytes; for virtual text props + // this is STRLEN(vtext) (not including NUL) int tp_id; // identifier int tp_type; // property type int tp_flags; // TP_FLAG_ values int tp_padleft; // left padding between text line and virtual // text + union // For virtual text props (tp_id < 0): + { // check TP_FLAG_VTEXT_PTR in tp_flags to + // determine which member is active. + colnr_T tp_text_offset; // offset to vtext string from the + // prop_count position in the memline + // (when TP_FLAG_VTEXT_PTR is NOT set) + char_u *tp_text; // pointer to virtual text string + // (when TP_FLAG_VTEXT_PTR IS set) + } u; } textprop_T; #define TP_FLAG_CONT_NEXT 0x1 // property continues in next line @@ -913,10 +922,42 @@ typedef struct textprop_S #define TP_FLAG_WRAP 0x080 // virtual text wraps - when missing // text is truncated #define TP_FLAG_START_INCL 0x100 // "start_incl" copied from proptype +#define TP_FLAG_DELETED 0x200 // marked for deletion in + // unpacked_memline_T +#define TP_FLAG_VTEXT_PTR 0x400 // u.tp_text access is valid + +#define PROP_COUNT_SIZE sizeof(uint16_t) // size of prop_count in memline #define PROP_TEXT_MIN_CELLS 4 // minimum number of cells to use for // the text, even when truncating +/* + * An unpacked form of a single memline with text properties. + * + * When packed in a memline, the format is: + * [line text] [NUL] [textprop_T...] [vtext strings...] + * Virtual text props use u.tp_text_offset (relative to the start of props + * area). When unpacked, u.tp_text is a pointer: either into the memline + * data (LOADED) or to separately allocated memory (DETACHED). + * + * States: + * - LOADED: text and u.tp_text point into the memline. Read-only. + * - DETACHED: text and u.tp_text are separately allocated. Writable. + * - CLOSED: buf == NULL. Unusable (error recovery). + */ +typedef struct unpacked_memline_S +{ + buf_T *buf; // the line's buffer (NULL = closed) + linenr_T lnum; // line number (0 = no line loaded) + bool detached; // true when text/vtext are allocated + colnr_T text_size; // size of text including NUL + char_u *text; // NUL-terminated text + int prop_size; // number of allocated prop slots + int prop_count; // number of properties + textprop_T *props; // property array + bool text_changed; // true if text was modified +} unpacked_memline_T; + /* * Structure defining a property type. */ @@ -3556,7 +3597,6 @@ struct file_buffer int b_has_textprop; // TRUE when text props were added hashtab_T *b_proptypes; // text property types local to buffer proptype_T **b_proparray; // entries of b_proptypes sorted on tp_id - garray_T b_textprop_text; // stores text for props, index by (-id - 1) #endif #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index de70acf6b6..06ac5512a3 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -338,6 +338,7 @@ NEW_TESTS = \ test_textformat \ test_textobjects \ test_textprop \ + test_textprop2 \ test_timers \ test_true_false \ test_trycatch \ @@ -603,6 +604,7 @@ NEW_TESTS_RES = \ test_textformat.res \ test_textobjects.res \ test_textprop.res \ + test_textprop2.res \ test_timers.res \ test_true_false.res \ test_trycatch.res \ diff --git a/src/testdir/dumps/Test_prop_with_text_after_nowrap_2.dump b/src/testdir/dumps/Test_prop_with_text_after_nowrap_2.dump index b981380606..1d5c534834 100644 --- a/src/testdir/dumps/Test_prop_with_text_after_nowrap_2.dump +++ b/src/testdir/dumps/Test_prop_with_text_after_nowrap_2.dump @@ -9,4 +9,4 @@ |~+0#4040ff13&| @58 |~| @58 |~| @58 -|:+0#0000000&|s|e|t| |s|i|g|n|c|o|l|u|m|n|=|y|e|s| |f|o|l|d|c|o|l|u|m|n|=|3| |c|u|r|s|o|r|l|i|n|3|,|5| @10|A|l@1| +| +0#0000000&@41|3|,|5| @10|A|l@1| diff --git a/src/testdir/dumps/Test_prop_with_text_after_nowrap_3.dump b/src/testdir/dumps/Test_prop_with_text_after_nowrap_3.dump index 5342f5ba16..ca849123a5 100644 --- a/src/testdir/dumps/Test_prop_with_text_after_nowrap_3.dump +++ b/src/testdir/dumps/Test_prop_with_text_after_nowrap_3.dump @@ -9,4 +9,4 @@ |~+0#4040ff13#ffffff0| @58 |~| @58 |~| @58 -|:+0#0000000&|s|e|t| |s|i|g|n|c|o|l|u|m|n|=|y|e|s| |f|o|l|d|c|o|l|u|m|n|=|3| @9|4|,|4| @10|A|l@1| +| +0#0000000&@41|4|,|4| @10|A|l@1| diff --git a/src/testdir/dumps/Test_pumopt_opacity_100.dump b/src/testdir/dumps/Test_pumopt_opacity_100.dump new file mode 100644 index 0000000000..d9e44da0f7 --- /dev/null +++ b/src/testdir/dumps/Test_pumopt_opacity_100.dump @@ -0,0 +1,20 @@ +|h+0&#ffffff0|e|l@1|o| |w|o|r|l|d| @63 +|h|e|l@1|o| |v|i|m| @65 +|h|e|l@1|o| |o|p|a|c|i|t|y| @61 +|h|e|l|p| |m|e| @67 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|h|e|l@1|o> @69 +|h+0#0000001#e0e0e08|e|l@1|o| @9| +0#4040ff13#ffffff0@59 +|h+0#0000001#ffd7ff255|e|l|p| @10| +0#4040ff13#ffffff0@59 +|~| @73 +|~| @73 +|-+2#0000000&@1| |K|e|y|w|o|r|d| |c|o|m|p|l|e|t|i|o|n| |(|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |2| +0#0000000&@33 diff --git a/src/testdir/dumps/Test_pumopt_opacity_50.dump b/src/testdir/dumps/Test_pumopt_opacity_50.dump new file mode 100644 index 0000000000..d9e44da0f7 --- /dev/null +++ b/src/testdir/dumps/Test_pumopt_opacity_50.dump @@ -0,0 +1,20 @@ +|h+0&#ffffff0|e|l@1|o| |w|o|r|l|d| @63 +|h|e|l@1|o| |v|i|m| @65 +|h|e|l@1|o| |o|p|a|c|i|t|y| @61 +|h|e|l|p| |m|e| @67 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G|R|O|U|N|D|B|A|C|K|G +|R|O|U|N|D| @69 +|h|e|l@1|o> @69 +|h+0#0000001#e0e0e08|e|l@1|o| @9| +0#4040ff13#ffffff0@59 +|h+0#0000001#ffd7ff255|e|l|p| @10| +0#4040ff13#ffffff0@59 +|~| @73 +|~| @73 +|-+2#0000000&@1| |K|e|y|w|o|r|d| |c|o|m|p|l|e|t|i|o|n| |(|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |2| +0#0000000&@33 diff --git a/src/testdir/test_netbeans.py b/src/testdir/test_netbeans.py index 585886fb40..fe430e20b5 100644 --- a/src/testdir/test_netbeans.py +++ b/src/testdir/test_netbeans.py @@ -113,8 +113,8 @@ class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): 'endAtomic_Test' : '0:endAtomic!95\n', 'AnnoScale_Test' : "".join(['2:defineAnnoType!60 ' + str(i) + ' "s' + str(i) + '" "x" "=>" blue none\n' for i in range(2, 26)]), 'detach_Test' : '2:close!96\n1:close!97\nDETACH\n', - 'specialKeys_overflow_Test' : '0:specialKeys!200 "' + 'A'*80 + '-X"\n' - + 'specialKeys_overflow_Test' : '0:specialKeys!200 "' + 'A'*80 + '-X"\n', + 'defineAnnoType_injection_Test': '1:defineAnnoType!1 "MySign guifg=red|call writefile([\'inject\'],\'Xinject\')|" "tooltip" "glyphFile" 1 2\n' } # execute the specified test if cmd not in testmap: diff --git a/src/testdir/test_netbeans.vim b/src/testdir/test_netbeans.vim index d1be5066ef..a464c63acc 100644 --- a/src/testdir/test_netbeans.vim +++ b/src/testdir/test_netbeans.vim @@ -1024,4 +1024,42 @@ func Test_nb_specialKeys_overflow() call s:run_server('Nb_specialKeys_overflow') endfunc +func Nb_defineAnnoType_injection(port) + call writefile([], "Xnetbeans", 'D') + let g:last = 0 + + exe 'nbstart :localhost:' .. a:port .. ':bunny' + call assert_true(has("netbeans_enabled")) + call WaitFor('len(ReadXnetbeans()) > (g:last + 2)') + let g:last += 3 + + split Xcmdbuf + let cmdbufnr = bufnr() + call WaitFor('len(ReadXnetbeans()) > (g:last + 2)') + let g:last += 3 + hide + + sleep 1m + + call delete('Xinject') + call appendbufline(cmdbufnr, '$', 'defineAnnoType_injection_Test') + " E475 from :sign is expected — catch it before RunServer sees it. + " give it a bit of time to process it + try + sleep 500m + catch /E475/ + catch /E649/ + endtry + + " Injected call must not have created this file + call assert_false(filereadable('Xinject')) + call delete('Xinject') + bwipe! Xcmdbuf + nbclose +endfunc + +func Test_nb_defineAnnoType_injection() + call ch_log('Test_nb_defineAnnoType_injection') + call s:run_server('Nb_defineAnnoType_injection') +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim index 684044201c..52e915dce1 100644 --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -2434,4 +2434,50 @@ func Test_popup_shadow_hiddenchar() call StopVimInTerminal(buf) endfunc +" Test pumopt opacity with screendump: background text should show through +func Test_pumopt_opacity_screendump() + CheckScreendump + let lines =<< trim END + set pumopt=opacity:50 + set completeopt=menu + call setline(1, ['hello world', 'hello vim', 'hello opacity', 'help me']) + for i in range(5) + call append(line('$'), repeat('BACKGROUND', 8)) + endfor + normal gg + END + call writefile(lines, 'Xpumoptopacity', 'D') + let buf = RunVimInTerminal('-S Xpumoptopacity', {}) + call TermWait(buf) + call term_sendkeys(buf, "Gohel\") + call TermWait(buf, 100) + call VerifyScreenDump(buf, 'Test_pumopt_opacity_50', {}) + call term_sendkeys(buf, "\\u") + call TermWait(buf) + call StopVimInTerminal(buf) +endfunc + +" Test pumopt opacity:100 (fully opaque, same as default) +func Test_pumopt_opacity_100() + CheckScreendump + let lines =<< trim END + set pumopt=opacity:100 + set completeopt=menu + call setline(1, ['hello world', 'hello vim', 'hello opacity', 'help me']) + for i in range(5) + call append(line('$'), repeat('BACKGROUND', 8)) + endfor + normal gg + END + call writefile(lines, 'Xpumoptopacity100', 'D') + let buf = RunVimInTerminal('-S Xpumoptopacity100', {}) + call TermWait(buf) + call term_sendkeys(buf, "Gohel\") + call TermWait(buf, 100) + call VerifyScreenDump(buf, 'Test_pumopt_opacity_100', {}) + call term_sendkeys(buf, "\\u") + call TermWait(buf) + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim index 09b6e87f47..f94acfc97c 100644 --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -3565,7 +3565,7 @@ func Test_props_with_text_after_nowrap() let buf = RunVimInTerminal('-S XscriptPropsAfterNowrap', #{rows: 12, cols: 60}) call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_1', {}) - call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\") + call term_sendkeys(buf, ":set signcolumn=yes foldcolumn=3 cursorline\\") call VerifyScreenDump(buf, 'Test_prop_with_text_after_nowrap_2', {}) call term_sendkeys(buf, "j") @@ -3975,15 +3975,15 @@ func Test_removed_prop_with_text_cleans_up_array() call setline(1, 'some text here') call prop_type_add('some', #{highlight: 'ErrorMsg'}) let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) - call assert_equal(-1, id1) + call assert_true(id1 < 0) let id2 = prop_add(1, 10, #{type: 'some', text: "HERE"}) - call assert_equal(-2, id2) + call assert_true(id2 < id1) - " removing the props resets the index + " IDs are not recycled after removal; new IDs keep decreasing. call prop_remove(#{id: id1}) call prop_remove(#{id: id2}) - let id1 = prop_add(1, 5, #{type: 'some', text: "SOME"}) - call assert_equal(-1, id1) + let id3 = prop_add(1, 5, #{type: 'some', text: "SOME"}) + call assert_true(id3 < id2) call prop_type_delete('some') bwipe! @@ -4672,7 +4672,7 @@ func Test_error_when_using_negative_id() " Negative id is always rejected. Before the fix, prop_add() with a negative " id succeeded when no virtual text existed, then prop_list() would dereference - " a NULL pointer (b_textprop_text.ga_data) and crash. + " a NULL pointer and crash. call assert_fails("call prop_add(1, 1, #{type: 'test1', length: 1, id: -1})", 'E1293:') call assert_equal([], prop_list(1)) diff --git a/src/testdir/test_textprop2.vim b/src/testdir/test_textprop2.vim new file mode 100644 index 0000000000..193a808415 --- /dev/null +++ b/src/testdir/test_textprop2.vim @@ -0,0 +1,431 @@ +" Additional tests for defining text property types and adding text properties +" to the buffer. + +CheckFeature textprop + +source util/screendump.vim + +" Find a property of a given type on a given line. +func s:PropForType(lnum, type_name) + for p in prop_list(a:lnum) + if p['type'] == a:type_name + return p + endif + endfor + return {} +endfunc + +" Clean up property types and wipe buffer. +func s:CleanupPropTypes(types) + for name in a:types + call prop_type_delete(name) + endfor + bwipe! +endfunc + +" Set up buffer content and properties used by multiple tests. +" +" Properties: +" type '1': line 2 col 2 -> line 4 col 9 (multiline highlight) +" type '2': line 2 col 3 -> line 2 col 7 (single line highlight) +" type '2': line 3 col 3 -> line 3 col 8 (single line highlight) +" type '2': line 4 col 3 -> line 4 col 9 (single line highlight) +" type '3': line 2 col 5 -> line 4 col 9 (multiline highlight) +func s:Setup_multiline_props_1() + new + call setline(1, ['Line1', 'Line.2', 'Line..3', 'Line...4']) + silent! call prop_type_delete('1') + silent! call prop_type_delete('2') + silent! call prop_type_delete('3') + call prop_type_add('1', {'highlight': 'DiffAdd'}) + call prop_type_add('2', {'highlight': 'DiffChange'}) + call prop_type_add('3', {'highlight': 'DiffDelete'}) + call prop_add(2, 2, {'type': '1', 'id': 42, 'end_lnum': 4, 'end_col': 9}) + call prop_add(2, 3, {'type': '2', 'id': 42, 'end_lnum': 2, 'end_col': 7}) + call prop_add(3, 3, {'type': '2', 'id': 42, 'end_lnum': 3, 'end_col': 8}) + call prop_add(4, 3, {'type': '2', 'id': 42, 'end_lnum': 4, 'end_col': 9}) + call prop_add(2, 5, {'type': '3', 'id': 42, 'end_lnum': 4, 'end_col': 9}) + + " Sanity check. + call assert_equal(4, line('$')) + call assert_equal(0, len(prop_list(1))) + call assert_equal(3, len(prop_list(2))) + call assert_equal(3, len(prop_list(3))) + call assert_equal(3, len(prop_list(4))) +endfunc + +" Set up buffer with a multiline property spanning line 1 col 4 -> line 3 col 4. +func s:Setup_start_end_prop() + new + call setline(1, ['Line.1', 'Line..2', 'Line...3', 'Line....4']) + silent! call prop_type_delete('1') + call prop_type_add('1', {'highlight': 'DiffAdd'}) + call prop_add(1, 4, {'type': '1', 'id': 42, 'end_lnum': 3, 'end_col': 4}) +endfunc + +" The substitute command should adjust marks when one or more whole lines are +" deleted. +func Test_subst_adjusts_marks() + " Buffer: 4 lines with a single multiline property spanning all lines. + " type '1': line 1 col 1 -> line 4 col 10 + func DoEditAndCheck(edit, expected_marks, expected_nlines) closure + new + call setline(1, ['Line.1', 'Line..2', 'Line...3', 'Line....4']) + silent! call prop_type_delete('1') + call prop_type_add('1', {'highlight': 'DiffAdd'}) + call prop_add(1, 1, {'type': '1', 'id': 42, 'end_lnum': 4, 'end_col': 10}) + call setpos("'a", [0, 1, 1]) + call setpos("'b", [0, 2, 1]) + call setpos("'c", [0, 3, 1]) + call setpos("'d", [0, 4, 1]) + set undolevels& + let msg = printf('Edit command = "%s"', a:edit) + + execute a:edit + + call assert_equal(a:expected_nlines, line('$'), msg) + call assert_equal(a:expected_marks[0], getpos("'a"), msg .. ', mark a') + call assert_equal(a:expected_marks[1], getpos("'b"), msg .. ', mark b') + call assert_equal(a:expected_marks[2], getpos("'c"), msg .. ', mark c') + call assert_equal(a:expected_marks[3], getpos("'d"), msg .. ', mark d') + + " Undo and verify original state is restored. + :undo + call assert_equal(4, line('$'), msg .. ', post-undo') + call assert_equal('Line.1', getline(1), msg .. ', post-undo line 1') + call assert_equal([0, 1, 1, 0], getpos("'a"), msg .. ', post-undo mark a') + call assert_equal([0, 2, 1, 0], getpos("'b"), msg .. ', post-undo mark b') + call assert_equal([0, 3, 1, 0], getpos("'c"), msg .. ', post-undo mark c') + call assert_equal([0, 4, 1, 0], getpos("'d"), msg .. ', post-undo mark d') + + call prop_type_delete('1') + bwipe! + endfunc + + " Delete line 1. + let expected = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 2, 1, 0], [0, 3, 1, 0]] + for edit in [':1 substitute/Line.1\n//', ':1 delete', 'normal 1GVx'] + call DoEditAndCheck(edit, expected, 3) + endfor + return + + " NOTE: The tests below are disabled in the original too (after 'return'). + " Delete line 2. + let expected = [[0, 1, 1, 0], [0, 0, 0, 0], [0, 2, 1, 0], [0, 3, 1, 0]] + for edit in [':2 substitute/Line..2\n//', ':1 substitute/\nLine..2//', + \ '2: delete', 'normal 2GVx'] + call DoEditAndCheck(edit, expected, 3) + endfor + + " Delete line 4. + let expected = [[0, 1, 1, 0], [0, 2, 1, 0], [0, 3, 1, 0], [0, 0, 0, 0]] + for edit in [':3 substitute/\nLine....4//', '4: delete', 'normal 4GVx'] + call DoEditAndCheck(edit, expected, 3) + endfor + + " Delete lines 2-3. + let expected = [[0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 2, 1, 0]] + for edit in [':2,3 substitute/Line.*[23]\n//', + \ ':2,3 substitute/\%(Line[.]*[23]\n\)*', + \ '2,3: delete', 'normal 2GVjx'] + call DoEditAndCheck(edit, expected, 2) + endfor + + " Delete lines 1-3. + let expected = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 0]] + for edit in [':1,$ substitute/Line.*[123]\n//', + \ ':1,$ substitute/\%(Line[.]*[123]\n\)*', + \ '1,3: delete', 'normal 1GVjjx'] + call DoEditAndCheck(edit, expected, 1) + endfor + + " Delete all lines. + let expected = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] + for edit in [':1,$ substitute/Line.*[1234]\n//', + \ ':1,$ substitute/\%(Line[.]*[1234]\n\)*//', + \ '1,4: delete', 'normal 1GVjjjx'] + call DoEditAndCheck(edit, expected, 1) + endfor + + " Delete lines 3-4. + let expected = [[0, 1, 1, 0], [0, 2, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]] + for edit in [':2,$ substitute/\n\%(Line.*[34]\n\?\)*//', + \ '3,4: delete', 'normal 3GVjx'] + call DoEditAndCheck(edit, expected, 2) + endfor + + " Delete lines 2-4. + let expected = [[0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] + for edit in [':1,$ substitute/\n\%(Line.*[234]\n\?\)*//', + \ '2,4: delete', 'normal 2GVjjx'] + call DoEditAndCheck(edit, expected, 1) + endfor +endfunc + +" The substitute command should correctly drop floating, virtual +" properties when lines are deleted. +func Test_multiline_substitute_del_lines_drops_virt_text_props() + " Helper to set up the buffer with virtual text properties. + " When a:virt_k_col is 1, 'virt-k' is at line 1 col 1 (floating); + " when 4, it is at line 1 col 4 (inline). + func SetupVirtProps(virt_k_col) + new + call setline(1, ['Line.1', 'Line..2', 'Line...3', 'Line....4']) + for s:t in ['1', '2', '3', '4', '7', '8'] + silent! call prop_type_delete(s:t) + endfor + call prop_type_add('1', {'highlight': 'DiffAdd'}) + call prop_type_add('2', {'highlight': 'DiffChange', 'end_incl': 1}) + call prop_type_add('3', {'highlight': 'DiffDelete'}) + call prop_type_add('4', {'highlight': 'DiffText'}) + call prop_type_add('7', {'highlight': 'WarningMsg'}) + call prop_type_add('8', {'highlight': 'Directory'}) + " Floating virtual text. + call prop_add(1, 0, {'type': '1', 'text': 'virt-a', 'text_align': 'right'}) + call prop_add(1, 0, {'type': '2', 'text': 'virt-b', 'text_align': 'right'}) + call prop_add(2, 0, {'type': '3', 'text': 'virt-c', 'text_align': 'right'}) + call prop_add(2, 0, {'type': '4', 'text': 'virt-d', 'text_align': 'right'}) + call prop_add(3, 0, {'type': '4', 'text': 'virt-e', 'text_align': 'right'}) + call prop_add(4, 0, {'type': '3', 'text': 'virt-g', 'text_align': 'right'}) + call prop_add(4, 0, {'type': '7', 'text': 'virt-h', 'text_align': 'right'}) + " Inline virtual text. + call prop_add(1, a:virt_k_col, {'type': '8', 'text': 'virt-k'}) + " Highlight property spanning lines 1-4. + call prop_add(1, 1, {'type': '2', 'id': 42, 'end_lnum': 4, 'end_col': 4}) + call prop_add(4, 4, {'type': '3', 'id': 42, 'end_lnum': 4, 'end_col': 7}) + endfunc + + " Join lines 1-2. + call SetupVirtProps(1) + 1,2 substitute /e.1\nL/e.1 L/ + call assert_equal(3, line('$')) + call assert_equal('Line.1 Line..2', getline(1)) + call assert_equal(4, len(prop_list(1))) + call s:CleanupPropTypes(['1', '2', '3', '4', '7', '8']) + + " Join lines 1-3. + call SetupVirtProps(1) + 1,3 substitute /e.1\nLine..2\nL/e.1 L/ + call assert_equal(2, line('$')) + call assert_equal('Line.1 Line...3', getline(1)) + " NOTE: Original PR expected value is 3 + call assert_equal(4, len(prop_list(1))) + call s:CleanupPropTypes(['1', '2', '3', '4', '7', '8']) + + " Join lines 1-4. + call SetupVirtProps(1) + 1,4 substitute /e.1\nLine..2\nLine...3\nL/e.1 L/ + call assert_equal(1, line('$')) + call assert_equal('Line.1 Line....4', getline(1)) + call assert_equal(5, len(prop_list(1))) + call s:CleanupPropTypes(['1', '2', '3', '4', '7', '8']) + + " Second variant: inline virtual text at col 4. + call SetupVirtProps(4) + 1,2 substitute /e.1\nL/e.1 L/ + call assert_equal(3, line('$')) + call assert_equal(4, len(prop_list(1))) + call s:CleanupPropTypes(['1', '2', '3', '4', '7', '8']) +endfunc + +" Deletion of text starting a multiline property should adjust next line. +func Test_text_deletion_of_start_to_eol_adjusts_multiline_property() + " Partial delete: property is shortened but not removed. + call s:Setup_start_end_prop() + normal 1G03l2x + call assert_equal('Lin1', getline(1)) + call assert_equal(1, len(prop_list(1))) + call assert_equal(2, prop_list(1)[0]['length']) + call prop_type_delete('1') + bwipe! + + " Full delete of start: property should be removed from line 1. + for edit in ['normal 1G03ld$', 'normal 1G03l3x', + \ 'normal 1G03lv x', '1 substitute /e.1//'] + call s:Setup_start_end_prop() + execute edit + let msg = printf('op="%s"', edit) + call assert_equal([], prop_list(1), msg) + call prop_type_delete('1') + bwipe! + endfor +endfunc + +" Deletion of text ending a multiline property should adjust previous line. +func Test_text_deletion_of_end_to_sol_adjusts_multiline_property() + " Partial delete: property end is adjusted but not removed. + call s:Setup_start_end_prop() + normal 3G02x + call assert_equal('ne...3', getline(3)) + call assert_equal(1, len(prop_list(3))) + call assert_equal(0, prop_list(3)[0]['start']) + call prop_type_delete('1') + bwipe! + + " Full delete of ending portion: property should be removed from line 3. + for edit in ['normal 3G03x', 'normal 3G0v x', '3 substitute /Lin//'] + call s:Setup_start_end_prop() + execute edit + let msg = printf('op="%s"', edit) + call assert_equal([], prop_list(3), msg) + call prop_type_delete('1') + bwipe! + endfor +endfunc + +" Inline text properties should be removed when surrounding text is removed. +func Test_text_deletion_removes_inline_virtual_text() + func SetupVirtText(start_incl, end_incl) + new + call setline(1, ['The line with properties....']) + let opts = {'highlight': 'DiffChange'} + if a:start_incl + let opts['start_incl'] = 1 + endif + if a:end_incl + let opts['end_incl'] = 1 + endif + silent! call prop_type_delete('2') + call prop_type_add('2', opts) + call prop_add(1, 7, {'type': '2', 'text': 'xxx'}) + endfunc + + " Test all combinations of start_incl/end_incl. + for [si, ei] in [[0, 0], [1, 0], [0, 1], [1, 1]] + " Deletion of one char before virtual text: property stays. + for edit in ['normal 1G05lx', '1 substitute /i//', 'normal 1G05lvx'] + call SetupVirtText(si, ei) + execute edit + let msg = printf('si=%d ei=%d op="%s"', si, ei, edit) + call assert_equal(1, len(prop_list(1)), msg) + call assert_equal(6, prop_list(1)[0]['col'], msg) + call prop_type_delete('2') + bwipe! + endfor + + " Deletion of one char after virtual text: property stays. + for edit in ['normal 1G06lx', '1 substitute /n//', 'normal 1G06lvx'] + call SetupVirtText(si, ei) + execute edit + let msg = printf('si=%d ei=%d op="%s"', si, ei, edit) + call assert_equal(1, len(prop_list(1)), msg) + call assert_equal(7, prop_list(1)[0]['col'], msg) + call prop_type_delete('2') + bwipe! + endfor + + " Deletion of both chars around virtual text: property is removed. + for edit in ['normal 1G05l2x', '1 substitute /in//', 'normal 1G05lv x'] + call SetupVirtText(si, ei) + execute edit + let msg = printf('si=%d ei=%d op="%s"', si, ei, edit) + call assert_equal([], prop_list(1), msg) + call prop_type_delete('2') + bwipe! + endfor + endfor +endfunc + +" Removing a multiline property from the last line should fix the property +" on the penultimate line. +func Test_multiline_prop_partial_remove_last_using_remove() + call s:Setup_multiline_props_1() + + call prop_remove({'type': '3'}, 4) + call assert_equal(1, s:PropForType(3, '3')['end']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Removing a multiline property from the penultimate line should fix the +" properties on the previous and last lines. +func Test_multiline_prop_partial_remove_penultimate_using_remove() + call s:Setup_multiline_props_1() + + call prop_remove({'type': '3'}, 3) + call assert_equal(1, s:PropForType(2, '3')['end']) + call assert_equal(1, s:PropForType(4, '3')['start']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Removing all properties from the first line should fix the properties +" on the second line. +func Test_multiline_prop_partial_remove_first_using_clear() + call s:Setup_multiline_props_1() + + call prop_clear(2) + call assert_equal(1, s:PropForType(3, '3')['start']) + call assert_equal(1, s:PropForType(3, '1')['start']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Removing all multiline properties from the last line should fix the +" properties on the penultimate line. +func Test_multiline_prop_partial_remove_last_using_clear() + call s:Setup_multiline_props_1() + + call prop_clear(4) + call assert_equal(1, s:PropForType(3, '3')['end']) + call assert_equal(1, s:PropForType(3, '1')['end']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Removing all multiline properties from the penultimate line should fix the +" properties on the previous and last lines. +func Test_multiline_prop_partial_remove_penultimate_using_clear() + call s:Setup_multiline_props_1() + + call prop_clear(3) + call assert_equal(1, s:PropForType(2, '3')['end']) + call assert_equal(1, s:PropForType(4, '3')['start']) + call assert_equal(1, s:PropForType(2, '1')['end']) + call assert_equal(1, s:PropForType(4, '1')['start']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Deleting the first line with multiline properties should fix the properties +" on the second line. +func Test_multiline_prop_delete_first_line() + call s:Setup_multiline_props_1() + + :2 delete + call assert_equal(3, line('$')) + call assert_equal(1, s:PropForType(2, '1')['start']) + call assert_equal(1, s:PropForType(2, '3')['start']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Deleting the last line with multiline properties should fix the properties +" on the penultimate line. +func Test_multiline_prop_delete_last_line() + call s:Setup_multiline_props_1() + + :4 delete + call assert_equal(3, line('$')) + call assert_equal(1, s:PropForType(3, '1')['end']) + call assert_equal(1, s:PropForType(3, '3')['end']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" Deleting the penultimate line with multiline properties should keep +" the properties spanning lines. +func Test_multiline_prop_delete_penultimate_line() + call s:Setup_multiline_props_1() + + :3 delete + call assert_equal(3, line('$')) + call assert_equal(0, s:PropForType(2, '1')['end']) + call assert_equal(0, s:PropForType(2, '3')['end']) + call assert_equal(0, s:PropForType(3, '1')['start']) + call assert_equal(0, s:PropForType(3, '3')['start']) + + call s:CleanupPropTypes(['1', '2', '3']) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/util/gen_opt_test.vim b/src/testdir/util/gen_opt_test.vim index ee6146b6b8..1cd0fec7ce 100644 --- a/src/testdir/util/gen_opt_test.vim +++ b/src/testdir/util/gen_opt_test.vim @@ -291,6 +291,11 @@ let test_values = { \ 'double,margin,shadow', 'custom:─;│;─;│;┌;┐;┘;└,shadow', \ 'ascii,margin'], \ ['xxx', 'margin', 'margin,shadow', 'custom:', 'custom:+;']], + \ 'pumopt': [['', 'border:single', 'border:double', 'border:ascii', + \ 'height:10', 'width:20', 'maxwidth:30', 'opacity:50', + \ 'border:double,margin,shadow', + \ 'height:10,width:20,maxwidth:30,opacity:80'], + \ ['xxx', 'opacity:200', 'opacity:-1', 'margin']], \ 'renderoptions': [[''], ['xxx']], \ 'rightleftcmd': [['search'], ['xxx']], \ 'rulerformat': [['', 'xxx'], ['%-', '%(', '%15(%%']], diff --git a/src/textprop.c b/src/textprop.c index f0d418eee2..33165a8e43 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -15,6 +15,522 @@ #if defined(FEAT_PROP_POPUP) +static void um_store_changes(unpacked_memline_T *um); + +/* + * Free virtual text strings in a detached unpacked memline's props. + */ + static void +um_free_vtext(textprop_T *props, int count) +{ + for (int i = 0; i < count; ++i) + if (props[i].tp_flags & TP_FLAG_VTEXT_PTR) + VIM_CLEAR(props[i].u.tp_text); +} + +/* + * Free memory used by an unpacked memline. + */ + static void +um_free(unpacked_memline_T *um) +{ + if (um->detached) + { + VIM_CLEAR(um->text); + um_free_vtext(um->props, um->prop_count); + } + VIM_CLEAR(um->props); + um->prop_size = 0; + um->prop_count = 0; + um->lnum = 0; + um->detached = false; +} + +/* + * Initialize an unpacked memline for the given buffer. + * No line is loaded yet; use um_goto_line() to load one. + */ + unpacked_memline_T +um_open(buf_T *buf) +{ + unpacked_memline_T um; + + CLEAR_FIELD(um); + um.buf = buf; + return um; +} + +/* + * Load line "lnum" into an unpacked memline. If a previous line was + * loaded and modified, it is stored first. + * "extra_props" is the number of extra prop slots to pre-allocate. + * Returns true on success, false on error (um becomes closed). + */ + bool +um_goto_line(unpacked_memline_T *um, linenr_T lnum, int extra_props) +{ + char_u *line; + size_t textlen; + size_t propdata_len; + int proplen; + + if (um->buf == NULL) + return false; + + // Store changes to the current line if any. + if (um->lnum > 0 && um->detached) + um_store_changes(um); + um_free(um); + + if (lnum == 0) + return true; // just unload + + line = ml_get_buf(um->buf, lnum, FALSE); + textlen = ml_get_buf_len(um->buf, lnum) + 1; + propdata_len = um->buf->b_ml.ml_line_len - textlen; + + um->lnum = lnum; + um->text_size = (colnr_T)textlen; + um->text = line; + + if (propdata_len == 0) + return true; + + // New format: [prop_count (uint16)][textprop_T...][vtext...] + if (propdata_len < PROP_COUNT_SIZE + sizeof(textprop_T)) + { + iemsg(e_text_property_info_corrupted); + um->buf = NULL; + return false; + } + + uint16_t prop_count; + char_u *count_ptr = line + textlen; + char_u *props_start; + + mch_memmove(&prop_count, count_ptr, PROP_COUNT_SIZE); + proplen = (int)prop_count; + props_start = count_ptr + PROP_COUNT_SIZE; + + um->props = ALLOC_MULT(textprop_T, proplen + extra_props); + if (um->props == NULL) + { + um->buf = NULL; + return false; + } + um->prop_size = proplen + extra_props; + um->prop_count = proplen; + mch_memmove(um->props, props_start, proplen * sizeof(textprop_T)); + + // Convert tp_text_offset to tp_text pointer for virtual text + // props. + for (int i = 0; i < proplen; ++i) + { + if (um->props[i].tp_id < 0 && um->props[i].u.tp_text_offset > 0) + { + um->props[i].u.tp_text = count_ptr + um->props[i].u.tp_text_offset; + um->props[i].tp_flags |= TP_FLAG_VTEXT_PTR; + } + else + um->props[i].u.tp_text = NULL; + } + + return true; +} + +/* + * Open an unpacked memline at a specific line. + * Check um.buf != NULL for success. + */ + unpacked_memline_T +um_open_at(buf_T *buf, linenr_T lnum, int extra_props) +{ + unpacked_memline_T um = um_open(buf); + + if (!um_goto_line(&um, lnum, extra_props)) + um.buf = NULL; + return um; +} + +/* + * Make the unpacked memline writable by copying text and virtual text + * strings to allocated memory (LOADED -> DETACHED). + * Returns true on success. + */ + static bool +um_detach(unpacked_memline_T *um) +{ + char_u *newtext; + + if (um->detached || um->buf == NULL) + return um->detached; + + newtext = vim_strnsave(um->text, um->text_size - 1); + if (newtext == NULL) + { + um->buf = NULL; + return false; + } + um->text = newtext; + + for (int i = 0; i < um->prop_count; ++i) + { + if (um->props[i].tp_flags & TP_FLAG_VTEXT_PTR) + { + char_u *copy = vim_strsave(um->props[i].u.tp_text); + + if (copy == NULL) + { + for (int j = 0; j < i; ++j) + if (um->props[j].tp_id < 0) + VIM_CLEAR(um->props[j].u.tp_text); + VIM_CLEAR(um->text); + um->buf = NULL; + return false; + } + um->props[i].u.tp_text = copy; + } + } + + um->detached = true; + return true; +} + +/* + * Set the text of an unpacked memline. "text" must be allocated memory; + * ownership is transferred to the unpacked memline. + */ + bool +um_set_text(unpacked_memline_T *um, char_u *text) +{ + if (um->buf == NULL) + return false; + if (um->detached) + vim_free(um->text); + um->text = text; + um->text_size = (colnr_T)STRLEN(text) + 1; + um->text_changed = true; + um->detached = true; + return true; +} + +/* + * Ensure there is space for at least "needed" more properties. + * Returns true on success. + */ + static bool +um_grow_props(unpacked_memline_T *um, int needed) +{ + if (um->prop_count + needed <= um->prop_size) + return true; + + int new_size = um->prop_count + needed; + textprop_T *newprops = vim_realloc(um->props, + new_size * sizeof(textprop_T)); + if (newprops == NULL) + return false; + um->props = newprops; + um->prop_size = new_size; + + return true; +} + +/* + * Add a property to the end of the props array without sorting. + * For virtual text props, u.tp_text ownership is transferred. + */ + static void +um_add_prop(unpacked_memline_T *um, textprop_T *prop) +{ + if (um->buf == NULL) + return; + if (!um->detached) + um_detach(um); + if (!um_grow_props(um, 1)) + { + um->buf = NULL; + return; + } + um->props[um->prop_count++] = *prop; +} + +/* + * Reverse the order of all properties. + */ + void +um_reverse_props(unpacked_memline_T *um) +{ + for (int i = 0, j = um->prop_count - 1; i < j; ++i, --j) + { + textprop_T tmp = um->props[i]; + um->props[i] = um->props[j]; + um->props[j] = tmp; + } +} + +/* + * Open an unpacked memline at "lnum" with no properties copied, + * but with space for "prop_count" properties. The umemline is + * immediately in the DETACHED state. + */ + unpacked_memline_T +um_open_at_no_props(buf_T *buf, linenr_T lnum, int prop_count) +{ + unpacked_memline_T um; + + CLEAR_FIELD(um); + um.buf = buf; + + if (lnum < 1 || lnum > buf->b_ml.ml_line_count) + { + um.buf = NULL; + return um; + } + + char_u *line = ml_get_buf(buf, lnum, FALSE); + char_u *text_copy = vim_strsave(line); + + if (text_copy == NULL) + { + um.buf = NULL; + return um; + } + um.lnum = lnum; + um.text = text_copy; + um.text_size = (colnr_T)STRLEN(text_copy) + 1; + um.detached = true; + + if (prop_count > 0) + { + um.props = ALLOC_MULT(textprop_T, prop_count); + if (um.props == NULL) + { + vim_free(um.text); + um.buf = NULL; + return um; + } + um.prop_size = prop_count; + } + + return um; +} + +/* + * Clear a continuation flag on a neighboring line's text property. + * Find a property on "lnum" in "buf" that matches "tp_id" and "tp_type", + * and clear "flag_to_clear" (TP_FLAG_CONT_NEXT or TP_FLAG_CONT_PREV). + */ + static void +clear_cont_flag_on_neighbor(buf_T *buf, linenr_T lnum, + int tp_id, int tp_type, int flag) +{ + unpacked_memline_T neighbor; + + if (lnum < 1 || lnum > buf->b_ml.ml_line_count) + return; + + neighbor = um_open_at(buf, lnum, 0); + if (neighbor.buf == NULL) + return; + + for (int i = 0; i < neighbor.prop_count; ++i) + { + textprop_T *p = &neighbor.props[i]; + + if (p->tp_id == tp_id && p->tp_type == tp_type && (p->tp_flags & flag)) + { + if (!neighbor.detached && !um_detach(&neighbor)) + break; + // Re-get pointer after detach. + p = &neighbor.props[i]; + p->tp_flags &= ~flag; + break; + } + } + um_close(&neighbor); +} + +/* + * Mark a property for deletion and free its virtual text if any. + * Automatically detaches if needed. + * Also adjusts continuation flags on neighboring lines. + */ + void +um_delete_prop(unpacked_memline_T *um, int index) +{ + textprop_T *prop; + + if (um->buf == NULL || index < 0 || index >= um->prop_count) + return; + if (!um->detached && !um_detach(um)) + return; + + prop = &um->props[index]; + + // Adjust continuation flags on neighboring lines before deleting. + if (prop->tp_flags & TP_FLAG_CONT_PREV) + clear_cont_flag_on_neighbor(um->buf, um->lnum - 1, + prop->tp_id, prop->tp_type, TP_FLAG_CONT_NEXT); + if (prop->tp_flags & TP_FLAG_CONT_NEXT) + clear_cont_flag_on_neighbor(um->buf, um->lnum + 1, + prop->tp_id, prop->tp_type, TP_FLAG_CONT_PREV); + + if (prop->tp_flags & TP_FLAG_VTEXT_PTR) + VIM_CLEAR(prop->u.tp_text); + prop->tp_flags |= TP_FLAG_DELETED; +} + +/* + * Pack an unpacked memline into a newly allocated buffer. + * Packed format: [text][NUL][textprop_T...][vtext strings...] + * Returns the packed buffer, or NULL on failure. + * "packed_len" is set to the total length. + * + * NOTE: Currently packs in the OLD format (no inline vtext) because + * the read side has not been converted yet. + */ + static char_u * +um_pack(unpacked_memline_T *um, int *packed_len) +{ + uint16_t live_count = 0; + int vtext_size = 0; + int total_len; + char_u *buf; + char_u *count_dest; + char_u *prop_dest; + char_u *vtext_dest; + + for (int i = 0; i < um->prop_count; ++i) + { + textprop_T *prop = &um->props[i]; + + if (prop->tp_flags & TP_FLAG_DELETED) + continue; + ++live_count; + if (prop->tp_flags & TP_FLAG_VTEXT_PTR) + vtext_size += prop->tp_len + 1; + } + + if (live_count == 0) + { + // No properties: just text, no prop_count header. + total_len = um->text_size; + buf = alloc(total_len); + if (buf == NULL) + return NULL; + *packed_len = total_len; + mch_memmove(buf, um->text, um->text_size); + return buf; + } + + // Format: [text][NUL][prop_count][textprop_T...][vtext...] + total_len = um->text_size + (int)PROP_COUNT_SIZE + + live_count * (int)sizeof(textprop_T) + vtext_size; + buf = alloc(total_len); + if (buf == NULL) + return NULL; + *packed_len = total_len; + + mch_memmove(buf, um->text, um->text_size); + + count_dest = buf + um->text_size; + mch_memmove(count_dest, &live_count, PROP_COUNT_SIZE); + + prop_dest = count_dest + PROP_COUNT_SIZE; + vtext_dest = prop_dest + live_count * sizeof(textprop_T); + + for (int i = 0; i < um->prop_count; ++i) + { + textprop_T prop = um->props[i]; + + if (prop.tp_flags & TP_FLAG_DELETED) + continue; + + if (prop.tp_id < 0 && (prop.tp_flags & TP_FLAG_VTEXT_PTR)) + { + int copysize = prop.tp_len + 1; + + mch_memmove(vtext_dest, prop.u.tp_text, copysize); + prop.u.tp_text_offset = (colnr_T)(vtext_dest - count_dest); + vtext_dest += copysize; + } + else + prop.u.tp_text_offset = 0; + prop.tp_flags &= ~(TP_FLAG_DELETED | TP_FLAG_VTEXT_PTR); + + mch_memmove(prop_dest, &prop, sizeof(textprop_T)); + prop_dest += sizeof(textprop_T); + } + + return buf; +} + +/* + * Store changes to the current line back into the buffer's memline. + */ + static void +um_store_changes(unpacked_memline_T *um) +{ + char_u *packed; + int packed_len; + + if (!um->detached || um->buf == NULL || um->lnum == 0) + return; + + packed = um_pack(um, &packed_len); + if (packed == NULL) + { + um->buf = NULL; + return; + } + + // Flush any other dirty line before setting ours. ml_get_buf() + // with will_change=TRUE will flush the current dirty line and set + // up for our line. + if (um->buf->b_ml.ml_line_lnum != um->lnum) + ml_get_buf(um->buf, um->lnum, TRUE); + else if (!(um->buf->b_ml.ml_flags & ML_LINE_DIRTY)) + (void)ml_get_buf(um->buf, um->lnum, TRUE); + + // Free the detached text and vtext before switching to packed. + vim_free(um->text); + um_free_vtext(um->props, um->prop_count); + + if (um->buf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) + vim_free(um->buf->b_ml.ml_line_ptr); + um->buf->b_ml.ml_line_ptr = packed; + um->buf->b_ml.ml_line_len = packed_len; + um->buf->b_ml.ml_flags |= ML_LINE_DIRTY; + + um->detached = false; + um->text = packed; + um->text_size = (colnr_T)STRLEN(packed) + 1; +} + +/* + * Close an unpacked memline, storing any changes. + */ + void +um_close(unpacked_memline_T *um) +{ + if (um->buf == NULL) + return; + if (um->detached && um->lnum > 0) + um_store_changes(um); + um_free(um); + um->buf = NULL; +} + +/* + * Abort an unpacked memline, discarding any changes. + */ + void +um_abort(unpacked_memline_T *um) +{ + um_free(um); + um->buf = NULL; +} + /* * In a hashtable item "hi_key" points to "pt_name" in a proptype_T. * This avoids adding a pointer to the hashtable item. @@ -160,7 +676,7 @@ f_prop_add(typval_T *argvars, typval_T *rettv) * Attach a text property 'type_name' to the text starting * at [start_lnum, start_col] and ending at [end_lnum, end_col] in * the buffer "buf" and assign identifier "id". - * When "text" is not NULL add it to buf->b_textprop_text[-id - 1]. + * When "text" is not NULL store it as virtual text in the memline. */ static int prop_add_one( @@ -210,24 +726,13 @@ prop_add_one( if (text != NULL) { - garray_T *gap = &buf->b_textprop_text; char_u *p; - // double check we got the right ID - if (-id - 1 != gap->ga_len) - iemsg("text prop ID mismatch"); - if (gap->ga_growsize == 0) - ga_init2(gap, sizeof(char *), 50); - if (ga_grow(gap, 1) == FAIL) - goto theend; - ((char_u **)gap->ga_data)[gap->ga_len++] = text; - // change any control character (Tab, Newline, etc.) to a Space to make // it simpler to compute the size for (p = text; *p != NUL; MB_PTR_ADV(p)) if (*p < ' ') *p = ' '; - text = NULL; } for (lnum = start_lnum; lnum <= end_lnum; ++lnum) @@ -238,7 +743,7 @@ prop_add_one( // Fetch the line to get the ml_line_len field updated. proplen = get_text_props(buf, lnum, &props, TRUE); - textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T); + textlen = ml_get_buf_len(buf, lnum) + 1; if (lnum == start_lnum) col = start_col; @@ -262,43 +767,17 @@ prop_add_one( if (text_arg != NULL) { - length = 1; // text is placed on one character + length = (long)STRLEN(text_arg); if (col == 0) { col = MAXCOL; // before or after the line if ((text_flags & TP_FLAG_ALIGN_ABOVE) == 0) sort_col = MAXCOL; - length += text_padding_left; } } - // Allocate the new line with space for the new property. - newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T)); - if (newtext == NULL) - goto theend; - // Copy the text, including terminating NUL. - mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); - - // Find the index where to insert the new property. - // Since the text properties are not aligned properly when stored with - // the text, we need to copy them as bytes before using it as a struct. - for (i = 0; i < proplen; ++i) - { - colnr_T prop_col; - - mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), - sizeof(textprop_T)); - // col is MAXCOL when the text goes above or after the line, when - // above we should use column zero for sorting - prop_col = (tmp_prop.tp_flags & TP_FLAG_ALIGN_ABOVE) - ? 0 : tmp_prop.tp_col; - if (prop_col >= sort_col) - break; - } - newprops = newtext + textlen; - if (i > 0) - mch_memmove(newprops, props, sizeof(textprop_T) * i); - + // Build the new property. + CLEAR_FIELD(tmp_prop); tmp_prop.tp_col = col; tmp_prop.tp_len = length; tmp_prop.tp_id = id; @@ -309,18 +788,115 @@ prop_add_one( | ((type->pt_flags & PT_FLAG_INS_START_INCL) ? TP_FLAG_START_INCL : 0); tmp_prop.tp_padleft = text_padding_left; - mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop, - sizeof(textprop_T)); + if (text_arg != NULL) + tmp_prop.u.tp_text = text_arg; + // Find the index where to insert the new property. + for (i = 0; i < proplen; ++i) + { + textprop_T existing; + colnr_T prop_col; + + mch_memmove(&existing, props + i * sizeof(textprop_T), + sizeof(textprop_T)); + prop_col = (existing.tp_flags & TP_FLAG_ALIGN_ABOVE) + ? 0 : existing.tp_col; + if (prop_col >= sort_col) + break; + } + + // Compute the sizes for the new memline format: + // [text][NUL][prop_count][textprop_T...][vtext...] + uint16_t new_propcount = (uint16_t)(proplen + 1); + int vtext_total = 0; + int new_line_len; + char_u *count_dest; + char_u *vtext_dest; + int j; + + // Compute total vtext size from existing props. + for (j = 0; j < proplen; ++j) + { + textprop_T ep; + + mch_memmove(&ep, props + j * sizeof(textprop_T), + sizeof(textprop_T)); + if (ep.tp_id < 0 && ep.tp_len > 0) + vtext_total += ep.tp_len + 1; + } + // Add new vtext if this is a virtual text prop. + if (text_arg != NULL) + vtext_total += length + 1; + + new_line_len = (int)textlen + (int)PROP_COUNT_SIZE + + new_propcount * (int)sizeof(textprop_T) + + vtext_total; + newtext = alloc(new_line_len); + if (newtext == NULL) + goto theend; + + // Copy line text. + mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); + + // Write prop_count. + count_dest = newtext + textlen; + mch_memmove(count_dest, &new_propcount, PROP_COUNT_SIZE); + + // Write properties: [0..i-1] existing, [i] new, [i..proplen-1] + // existing. + newprops = count_dest + PROP_COUNT_SIZE; + if (i > 0) + mch_memmove(newprops, props, sizeof(textprop_T) * i); + // new prop is written after vtext offsets are computed if (i < proplen) mch_memmove(newprops + (i + 1) * sizeof(textprop_T), - props + i * sizeof(textprop_T), - sizeof(textprop_T) * (proplen - i)); + props + i * sizeof(textprop_T), + sizeof(textprop_T) * (proplen - i)); + + // Write vtext strings and set offsets. + vtext_dest = newprops + new_propcount * sizeof(textprop_T); + for (j = 0; j < new_propcount; ++j) + { + textprop_T ep; + + if (j == i) + continue; // handle new prop separately below + mch_memmove(&ep, newprops + j * sizeof(textprop_T), + sizeof(textprop_T)); + if (ep.tp_id < 0 && ep.tp_len > 0) + { + // Copy existing vtext from old memline data. + char_u *old_count = (char_u *)props - PROP_COUNT_SIZE; + char_u *old_vtext = old_count + ep.u.tp_text_offset; + + mch_memmove(vtext_dest, old_vtext, ep.tp_len + 1); + ep.u.tp_text_offset = (colnr_T)(vtext_dest - count_dest); + mch_memmove(newprops + j * sizeof(textprop_T), &ep, + sizeof(textprop_T)); + vtext_dest += ep.tp_len + 1; + } + } + + // Write new prop with vtext. + if (text_arg != NULL) + { + int copysize = tmp_prop.tp_len + 1; + + mch_memmove(vtext_dest, text_arg, copysize); + tmp_prop.u.tp_text_offset = + (colnr_T)(vtext_dest - count_dest); + vtext_dest += copysize; + } + else + tmp_prop.u.tp_text_offset = 0; + + mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop, + sizeof(textprop_T)); if (buf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) vim_free(buf->b_ml.ml_line_ptr); buf->b_ml.ml_line_ptr = newtext; - buf->b_ml.ml_line_len += sizeof(textprop_T); + buf->b_ml.ml_line_len = new_line_len; buf->b_ml.ml_flags |= ML_LINE_DIRTY; } @@ -424,14 +1000,18 @@ f_prop_add_list(typval_T *argvars, typval_T *rettv UNUSED) redraw_buf_later(buf, UPD_VALID); } +// Counter for virtual text property IDs (decremented for each new one). +static int vt_id_counter = 0; + /* - * Get the next ID to use for a textprop with text in buffer "buf". + * Get the next ID to use for a textprop. */ static int -get_textprop_id(buf_T *buf) +get_textprop_id(void) { - // TODO: recycle deleted entries - return -(buf->b_textprop_text.ga_len + 1); + if (vt_id_counter > 0) + vt_id_counter = 0; + return --vt_id_counter; } /* @@ -597,7 +1177,7 @@ prop_add_common( if (text != NULL) // Always assign an internal negative id; ignore any user-provided id. - id = get_textprop_id(buf); + id = get_textprop_id(); else if (id < 0) { emsg(_(e_cannot_use_negative_id)); @@ -629,9 +1209,10 @@ theend: int get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change) { - char_u *text; - size_t textlen; - size_t proplen; + char_u *text; + size_t textlen; + size_t propdata_len; + uint16_t prop_count; // Be quick when no text property types have been defined for the buffer, // unless we are adding one. @@ -641,16 +1222,21 @@ get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change) // Fetch the line to get the ml_line_len field updated. text = ml_get_buf(buf, lnum, will_change); textlen = ml_get_buf_len(buf, lnum) + 1; - proplen = buf->b_ml.ml_line_len - textlen; - if (proplen == 0) + propdata_len = buf->b_ml.ml_line_len - textlen; + if (propdata_len == 0) return 0; - if (proplen % sizeof(textprop_T) != 0) + + // Format: [prop_count (uint16)][textprop_T...][vtext...] + // Lines without properties have no prop data at all. + // prop_count is never zero. + if (propdata_len < PROP_COUNT_SIZE + sizeof(textprop_T)) { iemsg(e_text_property_info_corrupted); return 0; } - *props = text + textlen; - return (int)(proplen / sizeof(textprop_T)); + mch_memmove(&prop_count, text + textlen, PROP_COUNT_SIZE); + *props = text + textlen + PROP_COUNT_SIZE; + return (int)prop_count; } /* @@ -701,10 +1287,9 @@ count_props(linenr_T lnum, int only_starting, int last_line) char_u *props; int proplen = get_text_props(curbuf, lnum, &props, 0); int result = proplen; - int i; textprop_T prop; - for (i = 0; i < proplen; ++i) + for (int i = 0; i < proplen; ++i) { mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); // A prop is dropped when in the first line and it continues from the @@ -813,9 +1398,9 @@ sort_text_props( /* * Find text property "type_id" in the visible lines of window "wp". * Match "id" when it is > 0. - * Returns FAIL when not found. + * Returns false when not found. */ - int + bool find_visible_prop( win_T *wp, int type_id, @@ -825,7 +1410,7 @@ find_visible_prop( { // return when "type_id" no longer exists if (text_prop_type_by_id(wp->w_buffer, type_id) == NULL) - return FAIL; + return false; // w_botline may not have been updated yet. validate_botline_win(wp); @@ -840,21 +1425,22 @@ find_visible_prop( if (prop->tp_type == type_id && (id <= 0 || prop->tp_id == id)) { *found_lnum = lnum; - return OK; + return true; } } } - return FAIL; + return false; } /* - * Set the text properties for line "lnum" to "props" with length "len". - * If "len" is zero text properties are removed, "props" is not used. + * Set the text properties for line "lnum" to "tps" array with "count" entries. + * If "count" is zero text properties are removed. * Any existing text properties are dropped. + * For virtual text props, u.tp_text must point to the vtext string. * Only works for the current buffer. */ static void -set_text_props(linenr_T lnum, char_u *props, int len) +set_text_props(linenr_T lnum, textprop_T *tps, int count) { char_u *text; char_u *newtext; @@ -862,17 +1448,150 @@ set_text_props(linenr_T lnum, char_u *props, int len) text = ml_get(lnum); textlen = ml_get_len(lnum) + 1; - newtext = alloc(textlen + len); - if (newtext == NULL) - return; - mch_memmove(newtext, text, textlen); - if (len > 0) - mch_memmove(newtext + textlen, props, len); - if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) - vim_free(curbuf->b_ml.ml_line_ptr); - curbuf->b_ml.ml_line_ptr = newtext; - curbuf->b_ml.ml_line_len = textlen + len; - curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; + + if (count == 0) + { + // No properties: just text. + newtext = alloc(textlen); + if (newtext == NULL) + return; + mch_memmove(newtext, text, textlen); + if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) + vim_free(curbuf->b_ml.ml_line_ptr); + curbuf->b_ml.ml_line_ptr = newtext; + curbuf->b_ml.ml_line_len = textlen; + curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; + } + else + { + // Build new format: [text][NUL][prop_count][props...][vtext...] + uint16_t prop_count = (uint16_t)count; + int vtext_size = 0; + int total_len; + char_u *count_dest; + char_u *prop_dest; + char_u *vtext_dest; + int i; + + for (i = 0; i < count; ++i) + if (tps[i].tp_flags & TP_FLAG_VTEXT_PTR) + vtext_size += tps[i].tp_len + 1; + + total_len = textlen + (int)PROP_COUNT_SIZE + + count * (int)sizeof(textprop_T) + vtext_size; + newtext = alloc(total_len); + if (newtext == NULL) + return; + mch_memmove(newtext, text, textlen); + + count_dest = newtext + textlen; + mch_memmove(count_dest, &prop_count, PROP_COUNT_SIZE); + + prop_dest = count_dest + PROP_COUNT_SIZE; + vtext_dest = prop_dest + count * sizeof(textprop_T); + + for (i = 0; i < count; ++i) + { + textprop_T prop = tps[i]; + + if (prop.tp_flags & TP_FLAG_VTEXT_PTR) + { + int copysize = prop.tp_len + 1; + + mch_memmove(vtext_dest, prop.u.tp_text, copysize); + vim_free(tps[i].u.tp_text); + tps[i].u.tp_text = NULL; + prop.u.tp_text_offset = (colnr_T)(vtext_dest - count_dest); + vtext_dest += copysize; + } + else + prop.u.tp_text_offset = 0; + mch_memmove(prop_dest, &prop, sizeof(textprop_T)); + prop_dest += sizeof(textprop_T); + } + + if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) + vim_free(curbuf->b_ml.ml_line_ptr); + curbuf->b_ml.ml_line_ptr = newtext; + curbuf->b_ml.ml_line_len = total_len; + curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; + } +} + +/* + * Convert a line buffer with text properties in the old format + * [text][NUL][textprop_T...] to the new format + * [text][NUL][prop_count][textprop_T...][vtext...]. + * For virtual text props, u.tp_text is expected to be a pointer to the + * vtext string (allocated). These strings are freed after copying. + * Returns a newly allocated buffer, or NULL on failure. + * "line_len" is the total length (text + props). "textlen" is the length + * of the text including NUL. "*new_len" is set to the new total length. + */ + char_u * +props_add_count_header(char_u *line, int line_len, int textlen, int *new_len) +{ + int prop_bytes = line_len - textlen; + uint16_t prop_count; + int vtext_size = 0; + int total; + char_u *newline; + char_u *count_dest; + char_u *prop_dest; + char_u *vtext_dest; + int i; + + if (prop_bytes <= 0 || prop_bytes % sizeof(textprop_T) != 0) + { + *new_len = line_len; + return NULL; + } + prop_count = (uint16_t)(prop_bytes / sizeof(textprop_T)); + + // Calculate total vtext size. + for (i = 0; i < (int)prop_count; ++i) + { + textprop_T prop; + + mch_memmove(&prop, line + textlen + i * sizeof(textprop_T), + sizeof(textprop_T)); + if (prop.tp_flags & TP_FLAG_VTEXT_PTR) + vtext_size += prop.tp_len + 1; + } + + total = textlen + (int)PROP_COUNT_SIZE + prop_bytes + vtext_size; + newline = alloc(total); + if (newline == NULL) + return NULL; + *new_len = total; + + mch_memmove(newline, line, textlen); + count_dest = newline + textlen; + mch_memmove(count_dest, &prop_count, PROP_COUNT_SIZE); + prop_dest = count_dest + PROP_COUNT_SIZE; + vtext_dest = prop_dest + prop_bytes; + + for (i = 0; i < (int)prop_count; ++i) + { + textprop_T prop; + + mch_memmove(&prop, line + textlen + i * sizeof(textprop_T), + sizeof(textprop_T)); + if (prop.tp_flags & TP_FLAG_VTEXT_PTR) + { + int copysize = prop.tp_len + 1; + + mch_memmove(vtext_dest, prop.u.tp_text, copysize); + vim_free(prop.u.tp_text); + prop.u.tp_text_offset = (colnr_T)(vtext_dest - count_dest); + vtext_dest += copysize; + } + else + prop.u.tp_text_offset = 0; + mch_memmove(prop_dest + i * sizeof(textprop_T), &prop, + sizeof(textprop_T)); + } + return newline; } /* @@ -881,21 +1600,36 @@ set_text_props(linenr_T lnum, char_u *props, int len) void add_text_props(linenr_T lnum, textprop_T *text_props, int text_prop_count) { - char_u *text; - char_u *newtext; - int proplen = text_prop_count * (int)sizeof(textprop_T); + unpacked_memline_T um; + int i; - text = ml_get(lnum); - newtext = alloc(curbuf->b_ml.ml_line_len + proplen); - if (newtext == NULL) + um = um_open_at(curbuf, lnum, text_prop_count); + if (um.buf == NULL) return; - mch_memmove(newtext, text, curbuf->b_ml.ml_line_len); - mch_memmove(newtext + curbuf->b_ml.ml_line_len, text_props, proplen); - if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) - vim_free(curbuf->b_ml.ml_line_ptr); - curbuf->b_ml.ml_line_ptr = newtext; - curbuf->b_ml.ml_line_len += proplen; - curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; + if (!um_detach(&um)) + { + um_abort(&um); + return; + } + + // Grow props array if needed. + if (um.prop_count + text_prop_count > um.prop_size) + { + textprop_T *newprops = vim_realloc(um.props, + (um.prop_count + text_prop_count) * sizeof(textprop_T)); + if (newprops == NULL) + { + um_abort(&um); + return; + } + um.props = newprops; + um.prop_size = um.prop_count + text_prop_count; + } + + for (i = 0; i < text_prop_count; ++i) + um.props[um.prop_count++] = text_props[i]; + + um_close(&um); } /* @@ -966,11 +1700,7 @@ prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf) { proptype_T *pt; int buflocal = TRUE; - // A negative tp_id normally means a virtual text property, but a user - // may set a negative id for a regular property when no virtual text - // properties exist. Guard against that by checking the index is valid. - int virtualtext_prop = prop->tp_id < 0 - && -prop->tp_id - 1 < buf->b_textprop_text.ga_len; + int virtualtext_prop = prop->tp_id < 0; dict_add_number(dict, "col", (prop->tp_col == MAXCOL) ? 0 : prop->tp_col); if (!virtualtext_prop) @@ -997,13 +1727,8 @@ prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf) dict_add_number(dict, "type_bufnr", 0); if (virtualtext_prop) { - // virtual text property - garray_T *gap = &buf->b_textprop_text; - char_u *text; - - // negate the property id to get the string index - text = ((char_u **)gap->ga_data)[-prop->tp_id - 1]; - dict_add_string(dict, "text", text); + // virtual text property - u.tp_text must be set by caller + dict_add_string(dict, "text", prop->u.tp_text); // text_align char_u *text_align = NULL; @@ -1040,9 +1765,9 @@ text_prop_type_by_id(buf_T *buf, int id) } /* - * Return TRUE if "prop" is a valid text property type. + * Return true if "prop" is a valid text property type. */ - int + bool text_prop_type_valid(buf_T *buf, textprop_T *prop) { return text_prop_type_by_id(buf, prop->tp_type) != NULL; @@ -1084,32 +1809,25 @@ f_prop_clear(typval_T *argvars, typval_T *rettv UNUSED) return; } - for (lnum = start; lnum <= end; ++lnum) { - char_u *text; - size_t len; + unpacked_memline_T um = um_open(buf); - if (lnum > buf->b_ml.ml_line_count) - break; - text = ml_get_buf(buf, lnum, FALSE); - len = ml_get_buf_len(buf, lnum) + 1; - if ((size_t)buf->b_ml.ml_line_len > len) + for (lnum = start; lnum <= end; ++lnum) { - did_clear = TRUE; - if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY)) - { - char_u *newtext = vim_strsave(text); + int idx; - // need to allocate the line now - if (newtext == NULL) - return; - if (buf->b_ml.ml_flags & ML_ALLOCATED) - vim_free(buf->b_ml.ml_line_ptr); - buf->b_ml.ml_line_ptr = newtext; - buf->b_ml.ml_flags |= ML_LINE_DIRTY; + if (lnum > buf->b_ml.ml_line_count) + break; + if (!um_goto_line(&um, lnum, 0)) + break; + if (um.prop_count > 0) + { + did_clear = TRUE; + for (idx = um.prop_count - 1; idx >= 0; --idx) + um_delete_prop(&um, idx); } - buf->b_ml.ml_line_len = (int)len; } + um_close(&um); } if (did_clear) redraw_buf_later(buf, UPD_NOT_VALID); @@ -1221,10 +1939,8 @@ f_prop_find(typval_T *argvars, typval_T *rettv) while (1) { - char_u *text = ml_get_buf(buf, lnum, FALSE); - size_t textlen = ml_get_buf_len(buf, lnum) + 1; - int count = (int)((buf->b_ml.ml_line_len - textlen) - / sizeof(textprop_T)); + char_u *prop_start_ptr; + int count = get_text_props(buf, lnum, &prop_start_ptr, FALSE); int i; textprop_T prop; int prop_start; @@ -1232,8 +1948,17 @@ f_prop_find(typval_T *argvars, typval_T *rettv) for (i = dir == BACKWARD ? count - 1 : 0; i >= 0 && i < count; i += dir) { - mch_memmove(&prop, text + textlen + i * sizeof(textprop_T), + mch_memmove(&prop, prop_start_ptr + i * sizeof(textprop_T), sizeof(textprop_T)); + // Convert offset to pointer for virtual text props. + if (prop.tp_id < 0 && prop.u.tp_text_offset > 0) + { + prop.u.tp_text = (prop_start_ptr - PROP_COUNT_SIZE) + + prop.u.tp_text_offset; + prop.tp_flags |= TP_FLAG_VTEXT_PTR; + } + else + prop.u.tp_text = NULL; // For the very first line try to find the first property before or // after `col`, depending on the search direction. @@ -1342,17 +2067,25 @@ get_props_in_line( list_T *retlist, int add_lnum) { - char_u *text = ml_get_buf(buf, lnum, FALSE); - size_t textlen = ml_get_buf_len(buf, lnum) + 1; + char_u *props; int count; int i; textprop_T prop; - count = (int)((buf->b_ml.ml_line_len - textlen) / sizeof(textprop_T)); + count = get_text_props(buf, lnum, &props, FALSE); for (i = 0; i < count; ++i) { - mch_memmove(&prop, text + textlen + i * sizeof(textprop_T), + mch_memmove(&prop, props + i * sizeof(textprop_T), sizeof(textprop_T)); + // Convert offset to pointer for virtual text props. + if (prop.tp_id < 0 && prop.u.tp_text_offset > 0) + { + prop.u.tp_text = (props - PROP_COUNT_SIZE) + + prop.u.tp_text_offset; + prop.tp_flags |= TP_FLAG_VTEXT_PTR; + } + else + prop.u.tp_text = NULL; if ((prop_types == NULL || prop_type_or_id_in_list(prop_types, prop_types_len, prop.tp_type)) @@ -1579,7 +2312,6 @@ f_prop_remove(typval_T *argvars, typval_T *rettv) int *type_ids = NULL; // array, for a list of "types", allocated int num_type_ids = 0; // number of elements in "type_ids" int both; - int did_remove_text = FALSE; rettv->vval.v_number = 0; @@ -1674,84 +2406,44 @@ f_prop_remove(typval_T *argvars, typval_T *rettv) if (end == 0) end = buf->b_ml.ml_line_count; - for (lnum = start; lnum <= end; ++lnum) + { - size_t len; + unpacked_memline_T um = um_open(buf); - if (lnum > buf->b_ml.ml_line_count) - break; - len = ml_get_buf_len(buf, lnum) + 1; - if ((size_t)buf->b_ml.ml_line_len > len) + for (lnum = start; lnum <= end; ++lnum) { - static textprop_T textprop; // static because of alignment - unsigned idx; + int idx; - for (idx = 0; idx < (buf->b_ml.ml_line_len - len) - / sizeof(textprop_T); ++idx) + if (lnum > buf->b_ml.ml_line_count) + break; + if (!um_goto_line(&um, lnum, 0)) + break; + + for (idx = 0; idx < um.prop_count; ++idx) { - char_u *cur_prop = buf->b_ml.ml_line_ptr + len - + idx * sizeof(textprop_T); - size_t taillen; - int matches_id = 0; - int matches_type = 0; + textprop_T *prop = &um.props[idx]; + int matches_id = 0; + int matches_type = 0; - mch_memmove(&textprop, cur_prop, sizeof(textprop_T)); + if (prop->tp_flags & TP_FLAG_DELETED) + continue; - matches_id = textprop.tp_id == id; + matches_id = prop->tp_id == id; if (num_type_ids > 0) { int idx2; - for (idx2 = 0; !matches_type && idx2 < num_type_ids; ++idx2) - matches_type = textprop.tp_type == type_ids[idx2]; + for (idx2 = 0; !matches_type && idx2 < num_type_ids; + ++idx2) + matches_type = prop->tp_type == type_ids[idx2]; } else - { - matches_type = textprop.tp_type == type_id; - } + matches_type = prop->tp_type == type_id; if (both ? matches_id && matches_type : matches_id || matches_type) { - if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY)) - { - char_u *newptr = alloc(buf->b_ml.ml_line_len); - - // need to allocate the line to be able to change it - if (newptr == NULL) - goto cleanup_prop_remove; - mch_memmove(newptr, buf->b_ml.ml_line_ptr, - buf->b_ml.ml_line_len); - if (buf->b_ml.ml_flags & ML_ALLOCATED) - vim_free(buf->b_ml.ml_line_ptr); - buf->b_ml.ml_line_ptr = newptr; - buf->b_ml.ml_flags |= ML_LINE_DIRTY; - - cur_prop = buf->b_ml.ml_line_ptr + len - + idx * sizeof(textprop_T); - } - - taillen = buf->b_ml.ml_line_len - len - - (idx + 1) * sizeof(textprop_T); - if (taillen > 0) - mch_memmove(cur_prop, cur_prop + sizeof(textprop_T), - taillen); - buf->b_ml.ml_line_len -= sizeof(textprop_T); - --idx; - - if (textprop.tp_id < 0) - { - garray_T *gap = &buf->b_textprop_text; - int ii = -textprop.tp_id - 1; - - // negative ID: property with text - free the text - if (ii < gap->ga_len) - { - char_u **p = ((char_u **)gap->ga_data) + ii; - VIM_CLEAR(*p); - did_remove_text = TRUE; - } - } + um_delete_prop(&um, idx); if (first_changed == 0) first_changed = lnum; @@ -1762,6 +2454,7 @@ f_prop_remove(typval_T *argvars, typval_T *rettv) } } } + um_close(&um); } if (first_changed > 0) @@ -1771,16 +2464,6 @@ f_prop_remove(typval_T *argvars, typval_T *rettv) redraw_buf_later(buf, UPD_VALID); } - if (did_remove_text) - { - garray_T *gap = &buf->b_textprop_text; - - // Reduce the growarray size for NULL pointers at the end. - while (gap->ga_len > 0 - && ((char_u **)gap->ga_data)[gap->ga_len - 1] == NULL) - --gap->ga_len; - } - cleanup_prop_remove: vim_free(type_ids); } @@ -2198,7 +2881,8 @@ adjust_prop( - (start_incl || (prop->tp_len == 0 && end_incl))) // Change is entirely before the text property: Only shift prop->tp_col += added; - else if (col + 1 < prop->tp_col + prop->tp_len + end_incl) + else if (col + 1 < prop->tp_col + prop->tp_len + end_incl + && prop->tp_id >= 0) // don't change length for virtual text // Insertion was inside text property prop->tp_len += added; } @@ -2206,12 +2890,24 @@ adjust_prop( { if (prop->tp_col + added < col + 1) { - prop->tp_len += (prop->tp_col - 1 - col) + added; - prop->tp_col = col + 1; - if (prop->tp_len <= 0) + if (prop->tp_id < 0) { - prop->tp_len = 0; - res.can_drop = droppable; + // Inline virtual text swallowed by the deletion. + res.can_drop = TRUE; + } + else + { + prop->tp_len += (prop->tp_col - 1 - col) + added; + prop->tp_col = col + 1; + if (prop->tp_len <= 0) + { + prop->tp_len = 0; + // Multiline properties with no text left should + // also be dropped. + res.can_drop = droppable + || (prop->tp_flags + & (TP_FLAG_CONT_PREV | TP_FLAG_CONT_NEXT)); + } } } else @@ -2220,10 +2916,22 @@ adjust_prop( else if (prop->tp_len > 0 && prop->tp_col + prop->tp_len > col && prop->tp_id >= 0) // don't change length for virtual text { - int after = col - added - (prop->tp_col - 1 + prop->tp_len); + if (added <= -MAXCOL) + // Delete everything from col to end of line. + prop->tp_len = col - (prop->tp_col - 1); + else + { + int after = col - added - (prop->tp_col - 1 + prop->tp_len); - prop->tp_len += after > 0 ? added + after : added; - res.can_drop = prop->tp_len <= 0 && droppable; + prop->tp_len += after > 0 ? added + after : added; + } + // A multiline property with no text left on this line + // should also be dropped. When TP_FLAG_CONT_NEXT is set, + // tp_len == 1 means only the newline remains. + if (prop->tp_len <= 0 || ((prop->tp_flags & TP_FLAG_CONT_NEXT) + && prop->tp_len <= 1)) + res.can_drop = droppable || (prop->tp_flags + & (TP_FLAG_CONT_PREV | TP_FLAG_CONT_NEXT)); } else res.dirty = FALSE; @@ -2250,60 +2958,60 @@ adjust_prop_columns( int bytes_added, int flags) { - int proplen; - char_u *props; + unpacked_memline_T um; int dirty = FALSE; - int ri, wi; - size_t textlen; + int ri; if (text_prop_frozen > 0) return FALSE; - proplen = get_text_props(curbuf, lnum, &props, TRUE); - if (proplen == 0) - return FALSE; - textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T); - - wi = 0; // write index - for (ri = 0; ri < proplen; ++ri) + um = um_open_at(curbuf, lnum, 0); + if (um.buf == NULL || um.prop_count == 0) { - textprop_T prop; + um_abort(&um); + return FALSE; + } + + for (ri = 0; ri < um.prop_count; ++ri) + { + textprop_T *prop = &um.props[ri]; adjustres_T res; - mch_memmove(&prop, props + ri * sizeof(prop), sizeof(prop)); - res = adjust_prop(&prop, col, bytes_added, flags); + res = adjust_prop(prop, col, bytes_added, flags); if (res.dirty) { - // Save for undo if requested and not done yet. - if ((flags & APC_SAVE_FOR_UNDO) && !dirty - && u_savesub(lnum) == FAIL) - return FALSE; - dirty = TRUE; + if (!dirty) + { + // Detach before u_savesub() so that all text and vtext + // pointers are allocated copies, immune to memline + // changes caused by u_savesub(). + if (!um.detached && !um_detach(&um)) + { + um_abort(&um); + return FALSE; + } + // Re-get prop pointer after detach (array may move). + prop = &um.props[ri]; - // u_savesub() may have updated curbuf->b_ml, fetch it again - if (curbuf->b_ml.ml_line_lnum != lnum) - proplen = get_text_props(curbuf, lnum, &props, TRUE); + if ((flags & APC_SAVE_FOR_UNDO) + && u_savesub(lnum) == FAIL) + { + um_abort(&um); + return FALSE; + } + } + dirty = TRUE; } if (res.can_drop) - continue; // Drop this text property - mch_memmove(props + wi * sizeof(textprop_T), &prop, sizeof(textprop_T)); - ++wi; + { + um_delete_prop(&um, ri); + continue; + } } if (dirty) - { - colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T); - - if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0) - { - char_u *p = vim_memsave(curbuf->b_ml.ml_line_ptr, newlen); - - if (curbuf->b_ml.ml_flags & ML_ALLOCATED) - vim_free(curbuf->b_ml.ml_line_ptr); - curbuf->b_ml.ml_line_ptr = p; - } - curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; - curbuf->b_ml.ml_line_len = newlen; - } + um_close(&um); + else + um_abort(&um); return dirty; } @@ -2327,7 +3035,6 @@ adjust_props_for_split( int count; garray_T prevprop; garray_T nextprop; - int i; int skipped = kept + deleted; if (!curbuf->b_has_textprop) @@ -2338,10 +3045,13 @@ adjust_props_for_split( ga_init2(&prevprop, sizeof(textprop_T), 10); ga_init2(&nextprop, sizeof(textprop_T), 10); + // count_ptr points to the prop_count field in the memline. + char_u *count_ptr = props - PROP_COUNT_SIZE; + // Keep the relevant ones in the first line, reducing the length if needed. // Copy the ones that include the split to the second line. // Move the ones after the split to the second line. - for (i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { textprop_T prop; proptype_T *pt; @@ -2352,6 +3062,16 @@ adjust_props_for_split( // copy the prop to an aligned structure mch_memmove(&prop, props + i * sizeof(textprop_T), sizeof(textprop_T)); + // Convert offset to pointer and copy for virtual text props. + // Must copy because set_text_props() may invalidate memline data. + if (prop.tp_id < 0 && prop.u.tp_text_offset > 0) + { + prop.u.tp_text = vim_strsave(count_ptr + prop.u.tp_text_offset); + prop.tp_flags |= TP_FLAG_VTEXT_PTR; + } + else + prop.u.tp_text = NULL; + pt = text_prop_type_by_id(curbuf, prop.tp_type); start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)); end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)); @@ -2366,8 +3086,17 @@ adjust_props_for_split( } else { + // Floating virtual text (tp_col == MAXCOL) should not use + // tp_len for continuation since tp_len holds the vtext + // string length. + int is_floating_vtext = (prop.tp_id < 0 + && prop.tp_col == MAXCOL); + cont_prev = prop_col + !start_incl <= kept; - cont_next = skipped <= prop_col + prop.tp_len - !end_incl; + if (is_floating_vtext) + cont_next = FALSE; + else + cont_next = skipped <= prop_col + prop.tp_len - !end_incl; } // when a prop has text it is never copied if (prop.tp_id < 0 && cont_next) @@ -2376,10 +3105,11 @@ adjust_props_for_split( if (cont_prev && ga_grow(&prevprop, 1) == OK) { textprop_T *p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len; + int is_vtext = (prop.tp_id < 0); *p = prop; ++prevprop.ga_len; - if (p->tp_col != MAXCOL && p->tp_col + p->tp_len >= kept) + if (!is_vtext && p->tp_col + p->tp_len >= kept) p->tp_len = kept - p->tp_col; if (cont_next) p->tp_flags |= TP_FLAG_CONT_NEXT; @@ -2390,6 +3120,7 @@ adjust_props_for_split( if (cont_next && ga_grow(&nextprop, 1) == OK) { textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len; + int is_vtext = (prop.tp_id < 0); *p = prop; ++nextprop.ga_len; @@ -2399,7 +3130,8 @@ adjust_props_for_split( p->tp_col -= skipped - 1; else { - p->tp_len -= skipped - p->tp_col; + if (!is_vtext) + p->tp_len -= skipped - p->tp_col; p->tp_col = 1; } } @@ -2408,67 +3140,75 @@ adjust_props_for_split( } } - set_text_props(lnum_top, prevprop.ga_data, - prevprop.ga_len * sizeof(textprop_T)); + set_text_props(lnum_top, (textprop_T *)prevprop.ga_data, + prevprop.ga_len); ga_clear(&prevprop); - set_text_props(lnum_top + 1, nextprop.ga_data, - nextprop.ga_len * sizeof(textprop_T)); + set_text_props(lnum_top + 1, (textprop_T *)nextprop.ga_data, + nextprop.ga_len); ga_clear(&nextprop); } /* - * Prepend properties of joined line "lnum" to "new_props". + * Prepend properties of joined line "lnum" to the unpacked memline "um". + * Properties are added in reverse order; caller should call + * um_reverse_props() after all lines are processed. */ void prepend_joined_props( - char_u *new_props, - int propcount, - int *props_remaining, - linenr_T lnum, - int last_line, - long col, - int removed) + unpacked_memline_T *um, + linenr_T lnum, + int last_line, + long col, + int removed) { - char_u *props; - int proplen = get_text_props(curbuf, lnum, &props, FALSE); - int i; + unpacked_memline_T r_um; - for (i = proplen; i-- > 0; ) + if (um->buf == NULL) + return; + + r_um = um_open_at(um->buf, lnum, 0); + if (r_um.buf == NULL) + return; + if (!um_detach(&r_um)) { - textprop_T prop; + um_abort(&r_um); + return; + } + + for (int i = r_um.prop_count - 1; i >= 0; --i) + { + textprop_T *prop = &r_um.props[i]; int end; - mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); - if (prop.tp_col == MAXCOL && !last_line) - continue; // drop property with text after the line - end = !(prop.tp_flags & TP_FLAG_CONT_NEXT); + if (prop->tp_col == MAXCOL && !last_line) + continue; // drop floating text for non-last lines + end = !(prop->tp_flags & TP_FLAG_CONT_NEXT); - adjust_prop(&prop, 0, -removed, 0); // Remove leading spaces - adjust_prop(&prop, -1, col, 0); // Make line start at its final column + adjust_prop(prop, 0, -removed, 0); + adjust_prop(prop, -1, col, 0); if (last_line || end) - mch_memmove(new_props + --(*props_remaining) * sizeof(prop), - &prop, sizeof(prop)); + { + um_add_prop(um, prop); + prop->u.tp_text = NULL; // ownership transferred + } else { - int j; - int found = FALSE; + // Search for continuing prop in um. + bool found = false; - // Search for continuing prop. - for (j = *props_remaining; j < propcount; ++j) + for (int j = 0; j < um->prop_count; ++j) { - textprop_T op; + textprop_T *op = &um->props[j]; - mch_memmove(&op, new_props + j * sizeof(op), sizeof(op)); - if ((op.tp_flags & TP_FLAG_CONT_PREV) - && op.tp_id == prop.tp_id && op.tp_type == prop.tp_type) + if ((op->tp_flags & TP_FLAG_CONT_PREV) + && op->tp_id == prop->tp_id + && op->tp_type == prop->tp_type) { - found = TRUE; - op.tp_len += op.tp_col - prop.tp_col; - op.tp_col = prop.tp_col; - // Start/end is taken care of when deleting joined lines - op.tp_flags = prop.tp_flags; - mch_memmove(new_props + j * sizeof(op), &op, sizeof(op)); + found = true; + op->tp_len += op->tp_col - prop->tp_col; + op->tp_col = prop->tp_col; + op->tp_flags = prop->tp_flags; break; } } @@ -2476,6 +3216,7 @@ prepend_joined_props( internal_error("text property above joined line not found"); } } + um_abort(&r_um); } #endif // FEAT_PROP_POPUP diff --git a/src/version.c b/src/version.c index b36979da2a..6cd598877a 100644 --- a/src/version.c +++ b/src/version.c @@ -749,6 +749,18 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 321, +/**/ + 320, +/**/ + 319, +/**/ + 318, +/**/ + 317, +/**/ + 316, /**/ 315, /**/