Skip to content

Commit

Permalink
fix(codelens): Deleting line does not remove codelens (onivim#2839)
Browse files Browse the repository at this point in the history
__Issue:__ When deleting a line with a codelens, the codelens persists until the file is saved

__Defect:__ There was a bug with our shift logic - if the item would be deleted, there were cases were it could be kept (in a sparse mapping, where it wouldn't be overwritten - like the code lens / inline elements)

__Fix:__ Remove elements that are deleted in `shift`, and case to cover
  • Loading branch information
bryphe authored Dec 15, 2020
1 parent 21cc8e9 commit 08ab39f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- #2845 - Workspace: Opening a file should not always open a folder (fixes #1983)
- #2842 - CLI: AppImage - fix argument parsing in `AppRun` (fixes #2803)
- #2839 - Extensions: CodeLens - fix lens persisting when line is deleted

### Performance

Expand Down
17 changes: 11 additions & 6 deletions src/Core/Kernel/IntMap.re
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ let shift =
let newMap =
map
|> bindings
|> List.map(((key, v)) =>
|> List.filter_map(((key, v)) =>
if (delta > 0) {
if (key < startPos) {
(key, v);
Some((key, v));
} else {
(key + delta, v);
Some((key + delta, v));
};
} else if (key <= endPos) {
(key, v);
} else if (key < startPos) {
Some((key, v));
} else {
(key + delta, v);
let newPosition = key + delta;
if (newPosition < startPos) {
None;
} else {
Some((newPosition, v));
};
}
)
|> List.to_seq
Expand Down
14 changes: 14 additions & 0 deletions test/Core/IntMapTests.re
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,19 @@ describe("IntMap", ({describe, _}) => {
expect.string(val0).toEqual("a");
expect.string(val1).toEqual("c");
});

test("remove line in sparse list", ({expect, _}) => {
let map = [(1, "b")] |> List.to_seq |> IntMap.of_seq;
let newMap =
map
|> IntMap.shift(~default=_ => None, ~startPos=1, ~endPos=1, ~delta=-1);
let val0 = IntMap.find_opt(0, newMap);
let val1 = IntMap.find_opt(1, newMap);
let val2 = IntMap.find_opt(2, newMap);

expect.equal(val0, None);
expect.equal(val1, None);
expect.equal(val2, None);
});
})
});

0 comments on commit 08ab39f

Please sign in to comment.