aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/diff.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-27 21:35:20 +0800
committerGitHub <noreply@github.com>2025-03-27 13:35:20 +0000
commitd01d4764804bd73ce213aab76a394c62c9f7d193 (patch)
treef1232fb6c860315974a5ee53bea6080d4add8ac8 /src/nvim/diff.c
parent703f4037c475ee504b71d393e152fb1ae44c7bb9 (diff)
downloadrneovim-d01d4764804bd73ce213aab76a394c62c9f7d193.tar.gz
rneovim-d01d4764804bd73ce213aab76a394c62c9f7d193.tar.bz2
rneovim-d01d4764804bd73ce213aab76a394c62c9f7d193.zip
refactor(eval): move diff functions to diff.c (#33085)
They were moved in Vim in patch 8.1.1989. This change is required to port patch 9.1.1243.
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r--src/nvim/diff.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index c9ca58c816..4c5b86adc4 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -29,6 +29,7 @@
#include "nvim/drawscreen.h"
#include "nvim/errors.h"
#include "nvim/eval.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
@@ -3488,3 +3489,60 @@ static int xdiff_out(int start_a, int count_a, int start_b, int count_b, void *p
}));
return 0;
}
+
+/// "diff_filler()" function
+void f_diff_filler(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ rettv->vval.v_number = MAX(0, diff_check(curwin, tv_get_lnum(argvars)));
+}
+
+/// "diff_hlID()" function
+void f_diff_hlID(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ linenr_T lnum = tv_get_lnum(argvars);
+ static linenr_T prev_lnum = 0;
+ static varnumber_T changedtick = 0;
+ static int fnum = 0;
+ static int change_start = 0;
+ static int change_end = 0;
+ static hlf_T hlID = (hlf_T)0;
+
+ if (lnum < 0) { // ignore type error in {lnum} arg
+ lnum = 0;
+ }
+ if (lnum != prev_lnum
+ || changedtick != buf_get_changedtick(curbuf)
+ || fnum != curbuf->b_fnum) {
+ // New line, buffer, change: need to get the values.
+ int linestatus = 0;
+ int filler_lines = diff_check_with_linestatus(curwin, lnum, &linestatus);
+ if (filler_lines < 0 || linestatus < 0) {
+ if (filler_lines == -1 || linestatus == -1) {
+ change_start = MAXCOL;
+ change_end = -1;
+ if (diff_find_change(curwin, lnum, &change_start, &change_end)) {
+ hlID = HLF_ADD; // added line
+ } else {
+ hlID = HLF_CHD; // changed line
+ }
+ } else {
+ hlID = HLF_ADD; // added line
+ }
+ } else {
+ hlID = (hlf_T)0;
+ }
+ prev_lnum = lnum;
+ changedtick = buf_get_changedtick(curbuf);
+ fnum = curbuf->b_fnum;
+ }
+
+ if (hlID == HLF_CHD || hlID == HLF_TXD) {
+ int col = (int)tv_get_number(&argvars[1]) - 1; // Ignore type error in {col}.
+ if (col >= change_start && col <= change_end) {
+ hlID = HLF_TXD; // Changed text.
+ } else {
+ hlID = HLF_CHD; // Changed line.
+ }
+ }
+ rettv->vval.v_number = hlID;
+}