+46
-18
lines changedFilter options
+46
-18
lines changed Original file line number Diff line number Diff line change
@@ -1377,18 +1377,6 @@ character_offset({bufnr}, {row}, {col})
1377
1377
(number, number) UTF-32 and UTF-16 index of the character
1378
1378
in line {row} column {col} in buffer {buf}
1379
1379
1380
-
*vim.lsp.util.close_preview_autocmd()*
1381
-
close_preview_autocmd({events}, {winnr})
1382
-
Creates autocommands to close a preview window when events
1383
-
happen.
1384
-
1385
-
Parameters: ~
1386
-
{events} (table) list of events
1387
-
{winnr} (number) window id of preview window
1388
-
1389
-
See also: ~
1390
-
|autocmd-events|
1391
-
1392
1380
*vim.lsp.util.convert_input_to_markdown_lines()*
1393
1381
convert_input_to_markdown_lines({input}, {contents})
1394
1382
Converts any of `MarkedString` | `MarkedString[]` |
Original file line number Diff line number Diff line change
@@ -1253,17 +1253,57 @@ function M.stylize_markdown(bufnr, contents, opts)
1253
1253
return stripped
1254
1254
end
1255
1255
1256
+
---@private
1256
1257
--- Creates autocommands to close a preview window when events happen.
1257
1258
---
1258
-
---@param events (table) list of events
1259
-
---@param winnr (number) window id of preview window
1259
+
---@param events table list of events
1260
+
---@param winnr number window id of preview window
1261
+
---@param bufnrs table list of buffers where the preview window will remain visible
1260
1262
---@see |autocmd-events|
1261
-
function M.close_preview_autocmd(events, winnr)
1263
+
local function close_preview_autocmd(events, winnr, bufnrs)
1264
+
local augroup = 'preview_window_'..winnr
1265
+
1266
+
-- close the preview window when entered a buffer that is not
1267
+
-- the floating window buffer or the buffer that spawned it
1268
+
vim.cmd(string.format([[
1269
+
augroup %s
1270
+
autocmd!
1271
+
autocmd BufEnter * lua vim.lsp.util._close_preview_window(%d, {%s})
1272
+
augroup end
1273
+
]], augroup, winnr, table.concat(bufnrs, ',')))
1274
+
1262
1275
if #events > 0 then
1263
-
api.nvim_command("autocmd "..table.concat(events, ',').." <buffer> ++once lua pcall(vim.api.nvim_win_close, "..winnr..", true)")
1276
+
vim.cmd(string.format([[
1277
+
augroup %s
1278
+
autocmd %s <buffer> lua vim.lsp.util._close_preview_window(%d)
1279
+
augroup end
1280
+
]], augroup, table.concat(events, ','), winnr))
1264
1281
end
1265
1282
end
1266
1283
1284
+
---@private
1285
+
--- Closes the preview window
1286
+
---
1287
+
---@param winnr number window id of preview window
1288
+
---@param bufnrs table|nil optional list of ignored buffers
1289
+
function M._close_preview_window(winnr, bufnrs)
1290
+
vim.schedule(function()
1291
+
-- exit if we are in one of ignored buffers
1292
+
if bufnrs and vim.tbl_contains(bufnrs, api.nvim_get_current_buf()) then
1293
+
return
1294
+
end
1295
+
1296
+
local augroup = 'preview_window_'..winnr
1297
+
vim.cmd(string.format([[
1298
+
augroup %s
1299
+
autocmd!
1300
+
augroup end
1301
+
augroup! %s
1302
+
]], augroup, augroup))
1303
+
pcall(vim.api.nvim_win_close, winnr, true)
1304
+
end)
1305
+
end
1306
+
1267
1307
---@internal
1268
1308
--- Computes size of float needed to show contents (with optional wrapping)
1269
1309
---
@@ -1370,7 +1410,7 @@ function M.open_floating_preview(contents, syntax, opts)
1370
1410
opts.wrap = opts.wrap ~= false -- wrapping by default
1371
1411
opts.stylize_markdown = opts.stylize_markdown ~= false
1372
1412
opts.focus = opts.focus ~= false
1373
-
opts.close_events = opts.close_events or {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre"}
1413
+
opts.close_events = opts.close_events or {"CursorMoved", "CursorMovedI", "InsertCharPre"}
1374
1414
1375
1415
local bufnr = api.nvim_get_current_buf()
1376
1416
@@ -1439,7 +1479,7 @@ function M.open_floating_preview(contents, syntax, opts)
1439
1479
api.nvim_buf_set_option(floating_bufnr, 'modifiable', false)
1440
1480
api.nvim_buf_set_option(floating_bufnr, 'bufhidden', 'wipe')
1441
1481
api.nvim_buf_set_keymap(floating_bufnr, "n", "q", "<cmd>bdelete<cr>", {silent = true, noremap = true, nowait = true})
1442
-
M.close_preview_autocmd(opts.close_events, floating_winnr)
1482
+
close_preview_autocmd(opts.close_events, floating_winnr, {floating_bufnr, bufnr})
1443
1483
1444
1484
-- save focus_id
1445
1485
if opts.focus_id then
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4