This commit is contained in:
Will Hopkins 2024-05-05 10:05:59 -04:00 committed by GitHub
commit 09b3abc4c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 0 deletions

View File

@ -22,6 +22,12 @@ typedef struct {
LuaRef _on_spell_nav;
} Dict(set_decoration_provider);
typedef struct {
OptionalKeys is_set__win_fold_;
Boolean recursive;
Boolean open;
} Dict(win_fold);
typedef struct {
OptionalKeys is_set__set_extmark_;
Integer id;

View File

@ -19,6 +19,7 @@
#include "nvim/eval/typval.h"
#include "nvim/eval/vars.h"
#include "nvim/ex_eval.h"
#include "nvim/fold.h"
#include "nvim/garray_defs.h"
#include "nvim/globals.h"
#include "nvim/highlight_group.h"

View File

@ -13,8 +13,10 @@
#include "nvim/buffer_defs.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/window.h"
#include "nvim/ex_docmd.h"
#include "nvim/fold.h"
#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/lua/executor.h"
@ -30,6 +32,46 @@
# include "api/window.c.generated.h"
#endif
/// Opens or closes the fold at or around the specified line in a window.
///
/// @param window Window handle, or 0 for current window
/// @param lnum Line number
/// @param opts Dictionary
/// - "open": Open or close folds
/// - "recurse": Recurse over all folds within the specified fold, like |zC| / |zO|
/// @param[out] err Error details, if any
void nvim_win_fold(Window window, Integer lnum, Dict(win_fold) *opts, Error *err)
FUNC_API_SINCE(12)
{
bool recurse = HAS_KEY(opts, win_fold, recursive) && opts->recursive;
bool open = HAS_KEY(opts, win_fold, open) && opts->open;
win_T *win = find_window_by_handle(window, err);
if (!win) {
return;
}
if (lnum > INT32_MAX || lnum < 0) {
api_set_error(err, kErrorTypeValidation, "Line value outside range");
return;
}
foldinfo_T fi = fold_info(win, (linenr_T)lnum);
pos_T start;
start.lnum = fi.fi_lnum;
start.col = 0;
start.coladd = 0;
pos_T end;
end.lnum = fi.fi_lnum + fi.fi_lines;
end.col = 0;
end.coladd = 0;
try_start();
opFoldRange(start, end, open, recurse, false);
try_end(err);
}
/// Gets the current buffer in a window
///
/// @param window Window handle, or 0 for current window