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 87d1c25
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"build:all": "npm run build:node && npm run build:browser",
"install": "npm run build:node && npm run build:browser:maybe",
"test-native": "script/test-native.js",
"test": "mocha test/js/*.js",
"test:node": "mocha test/js/*.js",
"test:browser": "FORCE_BROWSER_FALLBACK=1 mocha test/js/*.js",
"test:all": "npm run test:node && npm run test:browser",
"test": "npm run test:all",
"benchmark": "node benchmark/marker-index.benchmark.js",
"prepublish": "npm run standard",
"standard": "standard --recursive src test",
Expand Down
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", WRAP(&get_old_extent), WRAP(&hunk_set_noop<Point>))
.field("newExtent", WRAP(&get_new_extent), WRAP(&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 87d1c25

Please sign in to comment.