Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Exposes legacy properties
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Jan 19, 2017
1 parent dc262d5 commit a589e50
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/bindings/em/patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ Patch * deserialize(std::vector<uint8_t> const & vec)
return new Patch(vec);
}

Point get_old_extent(Patch::Hunk const & hunk)
{
return hunk.old_end.traversal(hunk.old_start);
}

Point get_new_extent(Patch::Hunk const & hunk)
{
return hunk.new_end.traversal(hunk.new_start);
}

template <typename T>
void hunk_set_noop(Patch::Hunk & hunk, T const &)
{
}

EMSCRIPTEN_BINDINGS(Patch) {

emscripten::class_<Patch>("Patch")
Expand Down Expand Up @@ -81,6 +96,13 @@ EMSCRIPTEN_BINDINGS(Patch) {
.field("oldText", WRAP_FIELD(Patch::Hunk, old_text))
.field("newText", WRAP_FIELD(Patch::Hunk, new_text))

// The following fields are legacy only (most notably, TextBuffer doesn't work without them)

.field("start", WRAP_FIELD(Patch::Hunk, new_start))

.field("oldExtent", &get_old_extent, &hunk_set_noop<Point>)
.field("newExtent", &get_new_extent, &hunk_set_noop<Point>)

;

}
12 changes: 12 additions & 0 deletions test/js/patch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ describe('Patch', function () {
patch.delete();
})

it('expose legacy fields', function () {
const patch = new Patch({ mergeAdjacentHunks: false })

patch.splice({row: 0, column: 10}, {row: 0, column: 0}, {row: 1, column: 5})
patch.splice({row: 1, column: 5}, {row: 0, column: 2}, {row: 0, column: 8})

const hunk = patch.getHunks()[0];

assert.ok(hunk.oldExtent);
assert.ok(hunk.newExtent);
})

it('honors the mergeAdjacentHunks option set to true', function () {
const patch = new Patch({ mergeAdjacentHunks: true })

Expand Down

0 comments on commit a589e50

Please sign in to comment.