aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/window.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-07-16 18:02:53 +0800
committerGitHub <noreply@github.com>2023-07-16 18:02:53 +0800
commitabe39f2b243dc813456225a779fbeb7ae6affc27 (patch)
treefa4008f79ff2b51ed16b6827c24097e68b480362 /src/nvim/api/window.c
parent622ae2f53e77873a114f86f5acaff341ef3098ac (diff)
downloadrneovim-abe39f2b243dc813456225a779fbeb7ae6affc27.tar.gz
rneovim-abe39f2b243dc813456225a779fbeb7ae6affc27.tar.bz2
rneovim-abe39f2b243dc813456225a779fbeb7ae6affc27.zip
feat(api)!: change return type of nvim_win_text_height to Dict (#24365)
Diffstat (limited to 'src/nvim/api/window.c')
-rw-r--r--src/nvim/api/window.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 07aad2cd88..5480584aa5 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -488,15 +488,20 @@ void nvim_win_set_hl_ns(Window window, Integer ns_id, Error *err)
/// - end_vcol: Ending virtual column index on "end_row",
/// 0-based exclusive, rounded up to full screen lines.
/// When omitted include the whole line.
-/// @return The number of screen lines that the range of text occupy.
+/// @return Dictionary containing text height information, with these keys:
+/// - all: The total number of screen lines occupied by the range.
+/// - fill: The number of diff filler or virtual lines among them.
///
/// @see |virtcol()| for text width.
-Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *err)
+Dictionary nvim_win_text_height(Window window, Dict(win_text_height) *opts, Arena *arena,
+ Error *err)
FUNC_API_SINCE(12)
{
+ Dictionary rv = arena_dict(arena, 2);
+
win_T *const win = find_window_by_handle(window, err);
if (!win) {
- return NIL;
+ return rv;
}
buf_T *const buf = win->w_buffer;
const linenr_T line_count = buf->b_ml.ml_line_count;
@@ -510,58 +515,65 @@ Object nvim_win_text_height(Window window, Dict(win_text_height) *opts, Error *e
if (HAS_KEY(opts->start_row)) {
VALIDATE_T("start_row", kObjectTypeInteger, opts->start_row.type, {
- return NIL;
+ return rv;
});
start_lnum = (linenr_T)normalize_index(buf, opts->start_row.data.integer, false, &oob);
}
if (HAS_KEY(opts->end_row)) {
VALIDATE_T("end_row", kObjectTypeInteger, opts->end_row.type, {
- return NIL;
+ return rv;
});
end_lnum = (linenr_T)normalize_index(buf, opts->end_row.data.integer, false, &oob);
}
VALIDATE(!oob, "%s", "Line index out of bounds", {
- return NIL;
+ return rv;
});
VALIDATE((start_lnum <= end_lnum), "%s", "'start_row' is higher than 'end_row'", {
- return NIL;
+ return rv;
});
if (HAS_KEY(opts->start_vcol)) {
VALIDATE(HAS_KEY(opts->start_row), "%s", "'start_vcol' specified without 'start_row'", {
- return NIL;
+ return rv;
});
VALIDATE_T("start_vcol", kObjectTypeInteger, opts->start_vcol.type, {
- return NIL;
+ return rv;
});
start_vcol = opts->start_vcol.data.integer;
VALIDATE_RANGE((start_vcol >= 0 && start_vcol <= MAXCOL), "start_vcol", {
- return NIL;
+ return rv;
});
}
if (HAS_KEY(opts->end_vcol)) {
VALIDATE(HAS_KEY(opts->end_row), "%s", "'end_vcol' specified without 'end_row'", {
- return NIL;
+ return rv;
});
VALIDATE_T("end_vcol", kObjectTypeInteger, opts->end_vcol.type, {
- return NIL;
+ return rv;
});
end_vcol = opts->end_vcol.data.integer;
VALIDATE_RANGE((end_vcol >= 0 && end_vcol <= MAXCOL), "end_vcol", {
- return NIL;
+ return rv;
});
}
if (start_lnum == end_lnum && start_vcol >= 0 && end_vcol >= 0) {
VALIDATE((start_vcol <= end_vcol), "%s", "'start_vcol' is higher than 'end_vcol'", {
- return NIL;
+ return rv;
});
}
- const int64_t res = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol)
- + (HAS_KEY(opts->end_row) ? 0 : win_get_fill(win, line_count + 1));
- return INTEGER_OBJ(res);
+ int64_t fill = 0;
+ int64_t all = win_text_height(win, start_lnum, start_vcol, end_lnum, end_vcol, &fill);
+ if (!HAS_KEY(opts->end_row)) {
+ const int64_t end_fill = win_get_fill(win, line_count + 1);
+ fill += end_fill;
+ all += end_fill;
+ }
+ PUT_C(rv, "all", INTEGER_OBJ(all));
+ PUT_C(rv, "fill", INTEGER_OBJ(fill));
+ return rv;
}