From 44518f852ebc1dfaf9d61ae99992af5213771fea Mon Sep 17 00:00:00 2001 From: Cory Forsyth Date: Tue, 18 Aug 2015 12:04:31 -0400 Subject: [PATCH] Remove unused MarkupSection#markerContaining --- src/js/models/markup-section.js | 33 ------------ tests/unit/models/markup-section-test.js | 68 ------------------------ 2 files changed, 101 deletions(-) diff --git a/src/js/models/markup-section.js b/src/js/models/markup-section.js index b3c139a3d..fd33e055e 100644 --- a/src/js/models/markup-section.js +++ b/src/js/models/markup-section.js @@ -121,37 +121,4 @@ export default class Section extends LinkedItem { this.markers.append(m.clone()); }); } - - /** - * A marker contains this offset if: - * * The offset is between the marker's start and end - * * the offset is between two markers and this is the right marker (and leftInclusive is true) - * * the offset is between two markers and this is the left marker (and leftInclusive is false) - * - * @return {Marker} The marker that contains this offset - */ - markerContaining(offset, leftInclusive=true) { - let length = 0; - let lastMarker = null; - - if (offset === 0) { - return this.markers.head; - } - - this.markers.detect((marker) => { - if (length < offset) { - lastMarker = marker; - length += marker.length; - return false; - } else { - return true; // stop iteration - } - }); - - if (length > offset) { - return lastMarker; - } else if (length === offset) { - return (leftInclusive ? lastMarker.next : lastMarker); - } - } } diff --git a/tests/unit/models/markup-section-test.js b/tests/unit/models/markup-section-test.js index b1295778d..10369c449 100644 --- a/tests/unit/models/markup-section-test.js +++ b/tests/unit/models/markup-section-test.js @@ -20,74 +20,6 @@ test('a section can append a marker', (assert) => { assert.equal(s1.markers.length, 1); }); -test('#markerContaining finds the marker at the given offset when 1 marker', (assert) => { - const m = builder.createMarker('hi there!'); - const s = builder.createMarkupSection('h2',[m]); - - for (let i=0; i { - const m1 = builder.createMarker('hi '); - const m2 = builder.createMarker('there!'); - const s = builder.createMarkupSection('h2',[m1,m2]); - - assert.equal(s.markerContaining(0), m1, - 'first marker is always found at offset 0'); - assert.equal(s.markerContaining(m1.length + m2.length, false), m2, - 'last marker is found at offset === length when right-inclusive'); - assert.ok(!s.markerContaining(m1.length + m2.length + 1), - 'when offset > length && left-inclusive, no marker is found'); - assert.ok(!s.markerContaining(m1.length + m2.length + 1, false), - 'when offset > length && right-inclusive, no marker is found'); - - for (let i=1; i { - const m1 = builder.createMarker('hi '); - const m2 = builder.createMarker('there!'); - const m3 = builder.createMarker(' and more'); - const markerLength = [m1,m2,m3].reduce((prev, cur) => prev + cur.length, 0); - const s = builder.createMarkupSection('h2',[m1,m2,m3]); - - assert.equal(s.markerContaining(0), m1, - 'first marker is always found at offset 0'); - assert.ok(!s.markerContaining(markerLength), - 'last marker is undefined at offset === length (left-inclusive)'); - assert.equal(s.markerContaining(markerLength, false), m3, - 'last marker is found at offset === length (right-inclusive)'); - assert.ok(!s.markerContaining(markerLength + 1), - 'no marker is found at offset > length'); - - for (let i=1; i { const m1 = builder.createMarker('hi '); const m2 = builder.createMarker('there!');