Skip to content

Commit

Permalink
Fix #3093.
Browse files Browse the repository at this point in the history
 - Add 'npm run test: watch' to test while checking results.
  • Loading branch information
hackerwins committed Feb 20, 2019
1 parent 36a6bdc commit 57df9ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -24,6 +24,7 @@
"lint": "eslint src/js plugin lang test Gruntfile.js",
"download:selenium": "if [ ! -e test/libs/selenium-server-standalone.jar ]; then wget http://selenium-release.storage.googleapis.com/3.6/selenium-server-standalone-3.6.0.jar -O test/libs/selenium-server-standalone.jar; fi",
"test": "karma start karma.conf.js --single-run",
"test:watch": "karma start karma.conf.js",
"test:travis": "grunt test-travis --verbose",
"test:saucelabs": "grunt saucelabs-test"
},
Expand Down
18 changes: 14 additions & 4 deletions src/js/base/core/range.js
Expand Up @@ -219,14 +219,24 @@ class WrappedRange {
normalize() {
/**
* @param {BoundaryPoint} point
* @param {Boolean} isLeftToRight
* @param {Boolean} isLeftToRight - true: prefer to choose right node
* - false: prefer to choose left node
* @return {BoundaryPoint}
*/
const getVisiblePoint = function(point, isLeftToRight) {
// Just use the given point [XXX:Adhoc]
// - case 01. if the point is on the middle of the node
// - case 02. if the point is on the right edge and prefer to choose left node
// - case 03. if the point is on the left edge and prefer to choose right node
// - case 04. if the point is on the right edge and prefer to choose right node but the node is void
// - case 05. if the point is on the left edge and prefer to choose left node but the node is void
// - case 06. if the point is on the block node and there is no children
if ((dom.isVisiblePoint(point) && !dom.isEdgePoint(point)) ||
(dom.isVisiblePoint(point) && dom.isRightEdgePoint(point) && !isLeftToRight) ||
(dom.isVisiblePoint(point) && dom.isLeftEdgePoint(point) && isLeftToRight) ||
(dom.isVisiblePoint(point) && dom.isBlock(point.node) && dom.isEmpty(point.node))) {
(dom.isVisiblePoint(point) && dom.isRightEdgePoint(point) && !isLeftToRight) ||
(dom.isVisiblePoint(point) && dom.isLeftEdgePoint(point) && isLeftToRight) ||
(dom.isVisiblePoint(point) && dom.isRightEdgePoint(point) && isLeftToRight && dom.isVoid(point.node.nextSibling)) ||
(dom.isVisiblePoint(point) && dom.isLeftEdgePoint(point) && !isLeftToRight && dom.isVoid(point.node.previousSibling)) ||
(dom.isVisiblePoint(point) && dom.isBlock(point.node) && dom.isEmpty(point.node))) {
return point;
}

Expand Down
15 changes: 13 additions & 2 deletions test/base/core/range.spec.js
Expand Up @@ -178,7 +178,7 @@ describe('base:core.range', () => {
expect(rng.eo).to.equal(0);
});

it('should return <p>text</p><p>|text</b></p> for <p>text</p><p>|text</p>', () => {
it('should return <p>text</p><p>|text</p> for <p>text</p><p>|text</p>', () => {
var $cont = $('<div><p>text</p><p>text</p></div>');
var $p = $cont.find('p');

Expand All @@ -189,7 +189,7 @@ describe('base:core.range', () => {
expect(rng.eo).to.equal(0);
});

it('should return <p>|text</p><p>text|</b></p> for |<p>text</p><p>text</p>|', () => {
it('should return <p>|text</p><p>text|</p> for |<p>text</p><p>text</p>|', () => {
var $cont = $('<div class="note-editable"><p>text</p><p>text</p></div>');
var $p = $cont.find('p');

Expand All @@ -213,6 +213,17 @@ describe('base:core.range', () => {
expect(rng.ec).to.deep.equal($b[0].firstChild);
expect(rng.eo).to.equal(0);
});

it('should return <p><img>|text</p> for <p><img>|text</p>', () => {
var $cont = $('<div><p><img>text</p></div>');
var $img = $cont.find('img');
var text = $img[0].nextSibling;

var rng = range.create(text, 0, text, 0).normalize();
expect(rng.sc).to.equal(text);
expect(rng.so).to.equal(0);
expect(rng.isCollapsed()).to.true;
});
});

describe('insertNode', () => {
Expand Down

0 comments on commit 57df9ed

Please sign in to comment.