Skip to content

Commit

Permalink
4.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nmielnik committed Jun 16, 2015
1 parent ed8065e commit e98d7b5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
4.12.5 / 2015-06-16
==================
* Fix issue with restoring selection with nested block elements


4.12.4 / 2015-06-15
==================
* Ensure auto-link will never select an empty element (br, hr, input, etc.)


4.12.3 / 2015-06-12
==================
* Fix bug with un-linked auto-links causing unexpected cursor positioning
Expand Down
37 changes: 28 additions & 9 deletions dist/js/medium-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ var Util;

var parentNode = node.parentNode,
tagName = parentNode.tagName.toLowerCase();
while (this.parentElements.indexOf(tagName) === -1 && tagName !== 'div') {
while (!this.isBlockContainer(parentNode) && tagName !== 'div') {
if (tagName === 'li') {
return true;
}
Expand Down Expand Up @@ -1050,8 +1050,7 @@ var Util;
isElementAtBeginningOfBlock: function (node) {
var textVal,
sibling;
while (node.nodeType === 3 ||
(this.parentElements.indexOf(node.tagName.toLowerCase()) === -1 && !node.getAttribute('data-medium-element'))) { // TODO: Change this in v5.0.0
while (!this.isBlockContainer(node) && !this.isMediumEditorElement(node)) {
sibling = node;
while (sibling = sibling.previousSibling) {
textVal = sibling.nodeType === 3 ? sibling.nodeValue : sibling.textContent;
Expand All @@ -1064,16 +1063,36 @@ var Util;
return true;
},

isMediumEditorElement: function (element) {
return element && element.nodeType !== 3 && !!element.getAttribute('data-medium-element');
},

isBlockContainer: function (element) {
return element && element.nodeType !== 3 && this.parentElements.indexOf(element.nodeName.toLowerCase()) !== -1;
},

getBlockContainer: function (element) {
return this.traverseUp(element, function (el) {
return Util.parentElements.indexOf(el.tagName.toLowerCase()) !== -1;
return Util.isBlockContainer(el) && !Util.isBlockContainer(el.parentNode);
});
},

getFirstLeafNode: function (element) {
getFirstSelectableLeafNode: function (element) {
while (element && element.firstChild) {
element = element.firstChild;
}
var emptyElements = ['br', 'col', 'colgroup', 'hr', 'img', 'input', 'source', 'wbr'];
while (emptyElements.indexOf(element.nodeName.toLowerCase()) !== -1) {
// We don't want to set the selection to an element that can't have children, this messes up Gecko.
element = element.parentNode;
}
// Selecting at the beginning of a table doesn't work in PhantomJS.
if (element.nodeName.toLowerCase() === 'table') {
var firstCell = element.querySelector('th, td');
if (firstCell) {
element = firstCell;
}
}
return element;
},

Expand Down Expand Up @@ -1702,7 +1721,7 @@ var Selection;
'use strict';

function filterOnlyParentElements(node) {
if (Util.parentElements.indexOf(node.nodeName.toLowerCase()) !== -1) {
if (Util.isBlockContainer(node)) {
return NodeFilter.FILTER_ACCEPT;
} else {
return NodeFilter.FILTER_SKIP;
Expand Down Expand Up @@ -1975,7 +1994,7 @@ var Selection;
tagName = el.tagName.toLowerCase();
}

while (el && Util.parentElements.indexOf(tagName) === -1) {
while (el && !Util.isBlockContainer(el)) {
el = el.parentNode;
if (el && el.tagName) {
tagName = el.tagName.toLowerCase();
Expand Down Expand Up @@ -6523,7 +6542,7 @@ function MediumEditor(elements, options) {

// We're selecting a high-level block node, so make sure the cursor gets moved into the deepest
// element at the beginning of the block
range.setStart(Util.getFirstLeafNode(targetNode), 0);
range.setStart(Util.getFirstSelectableLeafNode(targetNode), 0);
range.collapse(true);
}

Expand Down Expand Up @@ -6596,7 +6615,7 @@ MediumEditor.version = (function (major, minor, revision) {
};
}).apply(this, ({
// grunt-bump looks for this:
'version': '4.12.3'
'version': '4.12.4'
}).version.split('.'));

return MediumEditor;
Expand Down
7 changes: 4 additions & 3 deletions dist/js/medium-editor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medium-editor",
"version": "4.12.3",
"version": "4.12.4",
"author": "Davi Ferreira <hi@daviferreira.com>",
"contributors": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/js/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ MediumEditor.version = (function (major, minor, revision) {
};
}).apply(this, ({
// grunt-bump looks for this:
'version': '4.12.3'
'version': '4.12.4'

This comment has been minimized.

Copy link
@j0k3r

j0k3r Jun 16, 2015

Contributor

Shouldn't this be 4.12.5? :trollface:

This comment has been minimized.

Copy link
@nmielnik

nmielnik Jun 16, 2015

Author Member

I'm hoping this commit is not part of the 4.12.x branch now, this one should be instead: 1bc86ab

}).version.split('.'));

0 comments on commit e98d7b5

Please sign in to comment.