Skip to content

Commit a70a186

Browse files
committed
🐛 Fix decorate and undecorate in Vim
Without `id`, `undecorate` remove all decorations even if `start` and `end` are specified.
1 parent e1242f2 commit a70a186

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

buffer/decoration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ async function vimDecorate(
178178
});
179179
rs.add(highlight);
180180
}
181+
let id = 1;
181182
for (const [type, props] of decoMap.entries()) {
182-
await vimFn.prop_add_list(denops, { bufnr, type }, [...props]);
183+
await vimFn.prop_add_list(denops, { bufnr, type, id: id++ }, [...props]);
183184
}
184185
});
185186
}
@@ -193,7 +194,7 @@ async function vimUndecorate(
193194
const propList = await vimFn.prop_list(denops, start + 1, {
194195
bufnr,
195196
end_lnum: end,
196-
}) as { id: string; type: string }[];
197+
}) as { id: number; type: string }[];
197198
const propIds = new Set(
198199
propList
199200
.filter((p) => p.type.startsWith(`${prefix}:`))

buffer/decoration_test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assertEquals } from "@std/assert";
2+
import { omit } from "@std/collections";
23
import { test } from "@denops/test";
34
import * as fn from "../function/mod.ts";
45
import * as vimFn from "../function/vim/mod.ts";
@@ -24,7 +25,7 @@ test({
2425
type: string;
2526
type_bufnr: number;
2627
}[];
27-
return props;
28+
return props.map((prop) => omit(prop, ["id"]));
2829
};
2930
const bufnr = await fn.bufnr(denops);
3031
await buffer.replace(denops, bufnr, [
@@ -50,7 +51,6 @@ test({
5051
assertEquals(await collect(bufnr), [{
5152
col: 1,
5253
end: 1,
53-
id: 0,
5454
length: 5,
5555
lnum: 1,
5656
start: 1,
@@ -59,13 +59,28 @@ test({
5959
}, {
6060
col: 2,
6161
end: 1,
62-
id: 0,
6362
length: 3,
6463
lnum: 2,
6564
start: 1,
6665
type: "denops_std:buffer:decoration:decorate:Search",
6766
type_bufnr: 0,
6867
}]);
68+
69+
// Re-appling the same decorations is OK
70+
await decorate(denops, bufnr, [
71+
{
72+
line: 1,
73+
column: 1,
74+
length: 5,
75+
highlight: "Title",
76+
},
77+
{
78+
line: 2,
79+
column: 2,
80+
length: 3,
81+
highlight: "Search",
82+
},
83+
]);
6984
},
7085
});
7186

deno.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@lambdalisue/unreachable": "jsr:@lambdalisue/unreachable@^1.0.1",
5555
"@nick/dispose": "jsr:@nick/dispose@^1.1.0",
5656
"@std/assert": "jsr:@std/assert@^1.0.0",
57+
"@std/collections": "jsr:@std/collections@^1.0.9",
5758
"@std/fs": "jsr:@std/fs@^1.0.0",
5859
"@std/path": "jsr:@std/path@^1.0.2",
5960
"@std/semver": "jsr:@std/semver@^1.0.0",
@@ -69,8 +70,8 @@
6970
"jsr:@denops/std/bufname": "./bufname/mod.ts",
7071
"jsr:@denops/std/eval": "./eval/mod.ts",
7172
"jsr:@denops/std/eval/expression": "./eval/expression.ts",
72-
"jsr:@denops/std/eval/stringify": "./eval/stringify.ts",
7373
"jsr:@denops/std/eval/string": "./eval/string.ts",
74+
"jsr:@denops/std/eval/stringify": "./eval/stringify.ts",
7475
"jsr:@denops/std/eval/use-eval": "./eval/use_eval.ts",
7576
"jsr:@denops/std/function": "./function/mod.ts",
7677
"jsr:@denops/std/function/nvim": "./function/nvim/mod.ts",

0 commit comments

Comments
 (0)