Skip to content

Commit

Permalink
remove unused MarkupSection#split
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Aug 12, 2015
1 parent ded8e43 commit c42329b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 60 deletions.
31 changes: 0 additions & 31 deletions src/js/models/markup-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,6 @@ export default class Section extends LinkedItem {
}
}

/**
* @return {Array} 2 new sections
*/
split(offset) {
let left = [], right = [], middle;

middle = this.markerContaining(offset);
// end of section
if (!middle) {
return [
new this.constructor(this.tagName, this.markers),
new this.constructor(this.tagName, [])
];
}

left = (middle.prev ? this.markers.readRange(null, middle.prev) : []);
right = (middle.next ? this.markers.readRange(middle.next, null) : []);

let leftLength = left.reduce((prev, cur) => prev + cur.length, 0);
let middleOffset = offset - leftLength;

let [leftMiddle, rightMiddle] = middle.split(middleOffset);
left.push(leftMiddle);
right.push(rightMiddle);

return [
new this.constructor(this.tagName, left),
new this.constructor(this.tagName, right)
];
}

// mutates this by appending the other section's (cloned) markers to it
join(otherSection) {
otherSection.markers.forEach(m => {
Expand Down
29 changes: 0 additions & 29 deletions tests/unit/models/markup-section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,6 @@ test('#markerContaining finds the marker at the given offset when multiple marke
}
});

test('a section can be split, splitting its markers', (assert) => {
const m = builder.createMarker('hi there!', [builder.createMarkup('b')]);
const s = builder.createMarkupSection('p', [m]);

const [s1, s2] = s.split(5);
assert.equal(s1.markers.length, 1, 's1 has marker');
assert.equal(s2.markers.length, 1, 's2 has marker');

assert.ok(s1.markers.head.hasMarkup('b'));
assert.equal(s1.markers.head.value, 'hi th');

assert.ok(s2.markers.head.hasMarkup('b'));
assert.equal(s2.markers.head.value, 'ere!');
});

test('a section can be split, splitting its markers when multiple markers', (assert) => {
const m1 = builder.createMarker('hi ');
const m2 = builder.createMarker('there!');
const s = builder.createMarkupSection('h2', [m1,m2]);

const [s1, s2] = s.split(5);
assert.equal(s1.markers.length, 2, 's1 has 2 markers');
assert.equal(s2.markers.length, 1, 's2 has 1 marker');

assert.equal(s1.markers.head.value, 'hi ');
assert.equal(s1.markers.tail.value, 'th');
assert.equal(s2.markers.head.value, 'ere!');
});

test('#splitMarker splits the marker at the offset', (assert) => {
const m1 = builder.createMarker('hi ');
const m2 = builder.createMarker('there!');
Expand Down

0 comments on commit c42329b

Please sign in to comment.