repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

fix(neovim): let a pivi session keep one prompt and its unfinished draft

ee70235623de272377a02c3cee5070c5a8c45026

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (2)

+43 / −1 text lines

Diff layout

neovim/lua/bugabinga/pivi/command.lua

Modified

+22 / −1 text lines

9191end
9393--- Opens a modifiable prompt buffer bound to a session.
94local prompts = {}
96--- Shows a session's prompt, reusing the one it already has.
97--- A draft survives, because reopening a prompt is asking to continue writing,
98--- not to start over.
9499local open_prompt = function( current )
100 local existing = prompts[current.name]
101 if existing and vim.api.nvim_buf_is_valid( existing ) then
102 local win = vim.fn.bufwinid( existing )
103 if win == -1 and pcall( vim.cmd.split ) then
104 win = vim.api.nvim_get_current_win()
105 vim.api.nvim_win_set_buf( win, existing )
106 pcall( vim.api.nvim_win_set_height, win, 6 )
107 end
108 if win ~= -1 then
109 vim.api.nvim_set_current_win( win )
110 vim.cmd.startinsert()
111 end
112 return existing
113 end
95115 local bufnr = vim.api.nvim_create_buf( false, true )
96116 vim.bo[bufnr].buftype = 'nofile'
97 vim.bo[bufnr].bufhidden = 'wipe'
117 vim.bo[bufnr].bufhidden = 'hide'
98118 vim.bo[bufnr].filetype = INPUT_FILETYPE
99119 vim.b[bufnr].pivi_session = current.name
120 prompts[current.name] = bufnr
100121 pcall( vim.api.nvim_buf_set_name, bufnr, 'pivi://' .. current.name .. '/prompt' )
102123 vim.keymap.set( { 'n', 'i', }, '/', function()

neovim/tests/bugabinga/pivi/command_spec.lua

Modified

+21 / −0 text lines

7474 assert.same( { '', }, vim.api.nvim_buf_get_lines( bufnr, 0, -1, false ) )
7575 end )
77 it( 'reuses the prompt of a session and keeps an unfinished draft', function()
78 local channel = fake.new()
79 local current = session.create { spawn = channel.spawn, name = 'spec', extension = false, skill = false, env = {}, }
81 local first = command.open_prompt( current )
82 vim.cmd.stopinsert()
83 vim.api.nvim_buf_set_lines( first, 0, -1, false, { 'my unfinished draft', } )
85 local again = command.open_prompt( current )
86 vim.cmd.stopinsert()
88 assert.equal( first, again )
89 assert.same( { 'my unfinished draft', }, vim.api.nvim_buf_get_lines( again, 0, -1, false ) )
91 local alive = 0
92 for _, bufnr in ipairs( vim.api.nvim_list_bufs() ) do
93 if vim.bo[bufnr].filetype == command.input_filetype then alive = alive + 1 end
94 end
95 assert.equal( 1, alive )
96 end )
7798 it( 'never opens in an ordinary buffer', function()
7899 vim.cmd 'enew'
79100 local bufnr = vim.api.nvim_get_current_buf()