mirror of
https://github.com/neovim/neovim
synced 2025-07-17 17:51:48 +00:00
@ -10,6 +10,7 @@
|
|||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/cursor.h"
|
#include "nvim/cursor.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
@ -33,6 +34,41 @@ Buffer nvim_win_get_buf(Window window, Error *err)
|
|||||||
return win->w_buffer->handle;
|
return win->w_buffer->handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the current buffer in a window, without side-effects
|
||||||
|
///
|
||||||
|
/// @param window Window handle
|
||||||
|
/// @param buffer Buffer handle
|
||||||
|
/// @param[out] err Error details, if any
|
||||||
|
void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
|
||||||
|
FUNC_API_SINCE(5)
|
||||||
|
{
|
||||||
|
win_T *win = find_window_by_handle(window, err), *save_curwin = curwin;
|
||||||
|
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||||
|
tabpage_T *tab = win_find_tabpage(win), *save_curtab = curtab;
|
||||||
|
|
||||||
|
if (!win || !buf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (switch_win(&save_curwin, &save_curtab, win, tab, false) == FAIL) {
|
||||||
|
api_set_error(err,
|
||||||
|
kErrorTypeException,
|
||||||
|
"Failed to switch to window %d",
|
||||||
|
window);
|
||||||
|
}
|
||||||
|
|
||||||
|
try_start();
|
||||||
|
int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
|
||||||
|
if (!try_end(err) && result == FAIL) {
|
||||||
|
api_set_error(err,
|
||||||
|
kErrorTypeException,
|
||||||
|
"Failed to set buffer %d",
|
||||||
|
buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
restore_win(save_curwin, save_curtab, false);
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the cursor position in the window
|
/// Gets the cursor position in the window
|
||||||
///
|
///
|
||||||
/// @param window Window handle
|
/// @param window Window handle
|
||||||
|
@ -11,6 +11,7 @@ local NIL = helpers.NIL
|
|||||||
local meth_pcall = helpers.meth_pcall
|
local meth_pcall = helpers.meth_pcall
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
|
local expect_err = helpers.expect_err
|
||||||
|
|
||||||
-- check if str is visible at the beginning of some line
|
-- check if str is visible at the beginning of some line
|
||||||
local function is_visible(str)
|
local function is_visible(str)
|
||||||
@ -31,7 +32,7 @@ local function is_visible(str)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
describe('api/win', function()
|
describe('API/win', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
describe('get_buf', function()
|
describe('get_buf', function()
|
||||||
@ -45,6 +46,21 @@ describe('api/win', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('set_buf', function()
|
||||||
|
it('works', function()
|
||||||
|
nvim('command', 'new')
|
||||||
|
local windows = nvim('list_wins')
|
||||||
|
neq(window('get_buf', windows[2]), window('get_buf', windows[1]))
|
||||||
|
window('set_buf', windows[2], window('get_buf', windows[1]))
|
||||||
|
eq(window('get_buf', windows[2]), window('get_buf', windows[1]))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('validates args', function()
|
||||||
|
expect_err('Invalid buffer id$', window, 'set_buf', nvim('get_current_win'), 23)
|
||||||
|
expect_err('Invalid window id$', window, 'set_buf', 23, nvim('get_current_buf'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('{get,set}_cursor', function()
|
describe('{get,set}_cursor', function()
|
||||||
it('works', function()
|
it('works', function()
|
||||||
eq({1, 0}, curwin('get_cursor'))
|
eq({1, 0}, curwin('get_cursor'))
|
||||||
|
Reference in New Issue
Block a user