mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
feat(inccommand): preview 'nomodifiable' buffers #32034
Problem: Incremental preview is not allowed on 'nomodifiable' buffers. Solution: - Allow preview on 'nomodifiable' buffers. - Restore the 'modifiable' option in case the preview function changes it.
This commit is contained in:
@@ -319,6 +319,8 @@ PLUGINS
|
|||||||
|
|
||||||
• EditorConfig
|
• EditorConfig
|
||||||
• spelling_language property is now supported.
|
• spelling_language property is now supported.
|
||||||
|
• 'inccommand' incremental preview can run on 'nomodifiable' buffers and
|
||||||
|
restores their 'modifiable' state
|
||||||
|
|
||||||
STARTUP
|
STARTUP
|
||||||
|
|
||||||
|
@@ -163,6 +163,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
OptInt save_b_p_ul;
|
OptInt save_b_p_ul;
|
||||||
|
int save_b_p_ma;
|
||||||
int save_b_changed;
|
int save_b_changed;
|
||||||
pos_T save_b_op_start;
|
pos_T save_b_op_start;
|
||||||
pos_T save_b_op_end;
|
pos_T save_b_op_end;
|
||||||
@@ -2419,6 +2420,7 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
|
|||||||
if (!set_has(ptr_t, &saved_bufs, buf)) {
|
if (!set_has(ptr_t, &saved_bufs, buf)) {
|
||||||
CpBufInfo cp_bufinfo;
|
CpBufInfo cp_bufinfo;
|
||||||
cp_bufinfo.buf = buf;
|
cp_bufinfo.buf = buf;
|
||||||
|
cp_bufinfo.save_b_p_ma = buf->b_p_ma;
|
||||||
cp_bufinfo.save_b_p_ul = buf->b_p_ul;
|
cp_bufinfo.save_b_p_ul = buf->b_p_ul;
|
||||||
cp_bufinfo.save_b_changed = buf->b_changed;
|
cp_bufinfo.save_b_changed = buf->b_changed;
|
||||||
cp_bufinfo.save_b_op_start = buf->b_op_start;
|
cp_bufinfo.save_b_op_start = buf->b_op_start;
|
||||||
@@ -2509,6 +2511,7 @@ static void cmdpreview_restore_state(CpInfo *cpinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf->b_p_ul = cp_bufinfo.save_b_p_ul; // Restore 'undolevels'
|
buf->b_p_ul = cp_bufinfo.save_b_p_ul; // Restore 'undolevels'
|
||||||
|
buf->b_p_ma = cp_bufinfo.save_b_p_ma; // Restore 'modifiable'
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < cpinfo->win_info.size; i++) {
|
for (size_t i = 0; i < cpinfo->win_info.size; i++) {
|
||||||
@@ -2704,7 +2707,6 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
&& current_sctx.sc_sid == 0 // only if interactive
|
&& current_sctx.sc_sid == 0 // only if interactive
|
||||||
&& *p_icm != NUL // 'inccommand' is set
|
&& *p_icm != NUL // 'inccommand' is set
|
||||||
&& !exmode_active // not in ex mode
|
&& !exmode_active // not in ex mode
|
||||||
&& curbuf->b_p_ma // buffer is modifiable
|
|
||||||
&& cmdline_star == 0 // not typing a password
|
&& cmdline_star == 0 // not typing a password
|
||||||
&& !vpeekc_any()
|
&& !vpeekc_any()
|
||||||
&& cmdpreview_may_show(s)) {
|
&& cmdpreview_may_show(s)) {
|
||||||
|
@@ -253,6 +253,50 @@ describe("'inccommand' for user commands", function()
|
|||||||
]]
|
]]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("can preview 'nomodifiable' buffer", function()
|
||||||
|
exec_lua([[
|
||||||
|
vim.api.nvim_create_user_command("PreviewTest", function() end, {
|
||||||
|
preview = function(ev)
|
||||||
|
vim.bo.modifiable = true
|
||||||
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"cats"})
|
||||||
|
return 2
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
]])
|
||||||
|
command('set inccommand=split')
|
||||||
|
|
||||||
|
command('set nomodifiable')
|
||||||
|
eq(false, api.nvim_get_option_value('modifiable', { buf = 0 }))
|
||||||
|
|
||||||
|
feed(':PreviewTest')
|
||||||
|
|
||||||
|
screen:expect([[
|
||||||
|
cats |
|
||||||
|
{1:~ }|*8
|
||||||
|
{3:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
{1:~ }|*4
|
||||||
|
{2:[Preview] }|
|
||||||
|
:PreviewTest^ |
|
||||||
|
]])
|
||||||
|
feed('<Esc>')
|
||||||
|
screen:expect([[
|
||||||
|
text on line 1 |
|
||||||
|
more text on line 2 |
|
||||||
|
oh no, even more text |
|
||||||
|
will the text ever stop |
|
||||||
|
oh well |
|
||||||
|
did the text stop |
|
||||||
|
why won't it stop |
|
||||||
|
make the text stop |
|
||||||
|
^ |
|
||||||
|
{1:~ }|*7
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
|
||||||
|
eq(false, api.nvim_get_option_value('modifiable', { buf = 0 }))
|
||||||
|
end)
|
||||||
|
|
||||||
it('works with inccommand=nosplit', function()
|
it('works with inccommand=nosplit', function()
|
||||||
command('set inccommand=nosplit')
|
command('set inccommand=nosplit')
|
||||||
feed(':Replace text cats')
|
feed(':Replace text cats')
|
||||||
|
Reference in New Issue
Block a user