From 77118d0da8badc4135be430f4cbb15bc95bc760f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 20 Apr 2023 21:17:25 +0100 Subject: fix(api): use text_locked() to check textlock Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in #22634 that made functions checking textlock usable in `` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK. --- runtime/doc/api.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 87ea000047..203468cc8a 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1365,7 +1365,7 @@ nvim_set_current_buf({buffer}) *nvim_set_current_buf()* Sets the current buffer. Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {buffer} Buffer handle @@ -1389,7 +1389,7 @@ nvim_set_current_tabpage({tabpage}) *nvim_set_current_tabpage()* Sets the current tabpage. Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {tabpage} Tabpage handle @@ -1398,7 +1398,7 @@ nvim_set_current_win({window}) *nvim_set_current_win()* Sets the current window. Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {window} Window handle @@ -2163,7 +2163,7 @@ nvim_buf_delete({buffer}, {opts}) *nvim_buf_delete()* Deletes the buffer. See |:bwipeout| Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {buffer} Buffer handle, or 0 for current buffer @@ -2894,7 +2894,7 @@ nvim_win_hide({window}) *nvim_win_hide()* or |nvim_win_close()|, which will close the buffer. Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {window} Window handle, or 0 for current window @@ -2912,7 +2912,7 @@ nvim_win_set_buf({window}, {buffer}) *nvim_win_set_buf()* Sets the current buffer in a window, without side effects Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {window} Window handle, or 0 for current window @@ -2999,7 +2999,7 @@ nvim_open_win({buffer}, {enter}, {*config}) *nvim_open_win()* < Attributes: ~ - not allowed when |textlock| is active + not allowed when |textlock| is active or in the |cmdwin| Parameters: ~ • {buffer} Buffer to display, or 0 for current buffer -- cgit From aa4e47f704c53ab1d825260d2bf34e2872e3ca89 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 23 Jun 2023 22:32:07 +0100 Subject: fix(api): disallow some more functions during textlock Problem: nvim_buf_set_text(), nvim_open_term() and termopen() all change buffer text, which is forbidden during textlock. Additionally, nvim_open_term() and termopen() may be used to convert the cmdwin buffer into a terminal buffer, which is weird. Solution: Allow nvim_buf_set_text() and nvim_open_term() in the cmdwin, but disallow nvim_open_term() from converting the cmdwin buffer into a terminal buffer. termopen() is not allowed in the cmdwin (as it always operates on curbuf), so just check text_locked(). Also happens to improve the error in #21055: nvim_buf_set_text() was callable during textlock, but happened to check textlock indirectly via u_save(); however, this caused the error to be overwritten by an unhelpful "Failed to save undo information" message when msg_list == NULL (e.g: an `` mapping invoked outside of do_cmdline()). --- runtime/doc/api.txt | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 203468cc8a..46c5f2ea18 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1200,6 +1200,9 @@ nvim_open_term({buffer}, {opts}) *nvim_open_term()* |nvim_chan_send()| can be called immediately to process sequences in a virtual terminal having the intended size. + Attributes: ~ + not allowed when |textlock| is active + Parameters: ~ • {buffer} the buffer to use (expected to be empty) • {opts} Optional parameters. @@ -2426,6 +2429,9 @@ nvim_buf_set_text({buffer}, {start_row}, {start_col}, {end_row}, {end_col}, Prefer |nvim_buf_set_lines()| if you are only adding or deleting entire lines. + Attributes: ~ + not allowed when |textlock| is active + Parameters: ~ • {buffer} Buffer handle, or 0 for current buffer • {start_row} First line index -- cgit