Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Feb 18, 2016
1 parent 7bc065e commit 176a906
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Editor {

formatLine(index, length, formats = {}, source = Emitter.sources.API) {
Object.keys(formats).forEach((format) => {
this.scroll.descendants(index, length).forEach(function(line) {
this.scroll.descendants(Block, index, Math.max(length, 1)).forEach(function(line) {
line.format(format, formats[format]);
});
});
Expand Down
1 change: 0 additions & 1 deletion core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class Quill {
}
}

// TODO is this necessary given formatText
formatLine(index, length, name, value, source) {
let formats;
[index, length, formats, source] = overload(index, length, name, value, source);
Expand Down
17 changes: 9 additions & 8 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,17 @@ class Selection {
}

getBounds(index) {
let pos = this.scroll.path(index).pop();
if (pos == null) return null;
let blot, [line, offset] = this.scroll.descendant(BlockBlot, index);
[blot, offset] = line.descendant(Parchment.Leaf, offset, true);
if (blot == null) return null;
let containerBounds = this.root.parentNode.getBoundingClientRect();
let side = 'left';
let bounds, blot = pos[0], offset = pos[1];
if (blot.length() === 0) {
bounds = blot.parent.domNode.getBoundingClientRect();
} else if (blot instanceof EmbedBlot) {
let bounds, side = 'left';
if (blot instanceof EmbedBlot) {
bounds = blot.domNode.getBoundingClientRect();
if (offset > 0) {
side = 'right';
}
} else {
} else if (blot instanceof Parchment.Text) {
let range = document.createRange();
if (offset < blot.length()) {
range.setStart(blot.domNode, offset);
Expand All @@ -91,6 +89,9 @@ class Selection {
side = 'right';
}
bounds = range.getBoundingClientRect();
} else {
// TODO handle
return null;
}
return {
height: bounds.height,
Expand Down
14 changes: 8 additions & 6 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import extend from 'extend';
import Parchment from 'parchment';
import Module from '../core/module';
import logger from '../core/logger';

Expand Down Expand Up @@ -57,7 +58,11 @@ class Toolbar extends Module {
if (range.length === 0) {
this.quill.formatCursor(format, value, Quill.sources.USER);
} else {
this.quill.formatText(range, format, value, Quill.sources.USER);
if (Parchment.query(format, Parchment.Scope.BLOCK)) {
this.quill.formatLine(range, format, value, Quill.sources.USER);
} else {
this.quill.formatText(range, format, value, Quill.sources.USER);
}
this.quill.setSelection(range, Quill.sources.SILENT);
}
}
Expand All @@ -72,7 +77,8 @@ class Toolbar extends Module {
if (formats[format] == null) {
input.querySelector('option[selected]').selected = true;
} else {
input.value = Array.isArray(formats[format]) ? '' : value;
// TODO never reports array
input.value = Array.isArray(formats[format]) ? '' : formats[format];
}
} else {
input.classList.toggle('ql-active', formats[format]);
Expand Down Expand Up @@ -109,10 +115,6 @@ function addControls(container, groups) {
});
}

function addGroup(container, controls) {

}

function addButton(container, format, value) {
let input = document.createElement('button');
input.classList.add('ql-' + format);
Expand Down
7 changes: 4 additions & 3 deletions test/unit/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ describe('Selection', function() {
this.initialize(HTMLElement, '<p><span>0</span></p>', this.div);
this.reference = {
height: this.div.firstChild.firstChild.offsetHeight,
lineHeight: this.div.firstChild.offsetHeight,
width: this.div.firstChild.firstChild.offsetWidth,
top: this.div.firstChild.firstChild.offsetTop
};
Expand Down Expand Up @@ -279,7 +280,7 @@ describe('Selection', function() {
this.bounds = selection.getBounds(5);
expect(this.bounds.height).toBeApproximately(this.reference.height, 1);
expect(this.bounds.left).toBeApproximately(0, 1);
expect(this.bounds.top).toBeApproximately(this.reference.top + this.reference.height, 1);
expect(this.bounds.top).toBeApproximately(this.reference.top + this.reference.lineHeight, 1);
});

it('plain text', function() {
Expand All @@ -298,7 +299,7 @@ describe('Selection', function() {
this.bounds = selection.getBounds(5);
expect(this.bounds.height).toBeApproximately(this.reference.height, 1);
expect(this.bounds.left).toBeApproximately(0, 1);
expect(this.bounds.top).toBeApproximately(this.reference.top + this.reference.height, 1);
expect(this.bounds.top).toBeApproximately(this.reference.top + this.reference.lineHeight, 1);
});

it('end of line', function() {
Expand All @@ -310,7 +311,7 @@ describe('Selection', function() {
this.bounds = selection.getBounds(9);
expect(this.bounds.height).toBeApproximately(this.reference.height, 1);
expect(this.bounds.left).toBeApproximately(this.reference.width * 4, 4);
expect(this.bounds.top).toBeApproximately(this.reference.top + this.reference.height, 1);
expect(this.bounds.top).toBeApproximately(this.reference.top + this.reference.lineHeight, 1);
});

it('large text', function() {
Expand Down

0 comments on commit 176a906

Please sign in to comment.