Skip to content

Commit 24fc2ec

Browse files
committed
5.5.3
1 parent 32865a6 commit 24fc2ec

5 files changed

Lines changed: 52 additions & 28 deletions

File tree

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
5.5.3 / 2015-08-03
2+
==================
3+
* Fix issue with replacing a pre-existing link
4+
* Fix issue with selection after creating a link after empty paragraphs
5+
6+
17
5.5.2 / 2015-08-02
28
==================
39
* Fix issue where block elements where cleaned up incorrectly when pasting

dist/js/medium-editor.js

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ var Selection;
19051905
}
19061906
}
19071907

1908-
if (selectionState.emptyBlocksIndex && selectionState.end === nextCharIndex) {
1908+
if (selectionState.emptyBlocksIndex) {
19091909
var targetNode = Util.getTopBlockContainer(range.startContainer),
19101910
index = 0;
19111911
// Skip over empty blocks until we hit the block we want the selection to be in
@@ -1960,6 +1960,7 @@ var Selection;
19601960
}
19611961
}
19621962
range.setStart(currentNode.parentNode, currentNodeIndex + 1);
1963+
range.collapse(true);
19631964
}
19641965
}
19651966
return range;
@@ -6128,8 +6129,7 @@ function MediumEditor(elements, options) {
61286129
},
61296130

61306131
createLink: function (opts) {
6131-
var customEvent,
6132-
i;
6132+
var customEvent, i;
61336133

61346134
if (opts.url && opts.url.trim().length > 0) {
61356135
var currentSelection = this.options.contentWindow.getSelection();
@@ -6139,17 +6139,22 @@ function MediumEditor(elements, options) {
61396139
endContainerParentElement,
61406140
textNodes;
61416141

6142-
startContainerParentElement = Util.getClosestBlockContainer(
6143-
currentSelection.getRangeAt(0).startContainer);
6144-
endContainerParentElement = Util.getClosestBlockContainer(
6145-
currentSelection.getRangeAt(0).endContainer);
6142+
startContainerParentElement = Util.getClosestBlockContainer(currentSelection.getRangeAt(0).startContainer);
6143+
endContainerParentElement = Util.getClosestBlockContainer(currentSelection.getRangeAt(0).endContainer);
61466144

61476145
if (startContainerParentElement === endContainerParentElement) {
61486146
var currentEditor = Selection.getSelectionElement(this.options.contentWindow),
61496147
parentElement = (startContainerParentElement || currentEditor),
61506148
fragment = this.options.ownerDocument.createDocumentFragment();
6149+
6150+
// since we are going to create a link from an extracted text,
6151+
// be sure that if we are updating a link, we won't let an empty link behind (see #754)
6152+
// (Workaroung for Chrome)
6153+
this.execAction('unlink');
6154+
61516155
exportedSelection = this.exportSelection();
61526156
fragment.appendChild(parentElement.cloneNode(true));
6157+
61536158
if (currentEditor === parentElement) {
61546159
// We have to avoid the editor itself being wiped out when it's the only block element,
61556160
// as our reference inside this.elements gets detached from the page when insertHTML runs.
@@ -6162,37 +6167,50 @@ function MediumEditor(elements, options) {
61626167
// In WebKit:
61636168
// an invented <br /> tag at the end in the same situation
61646169

6165-
Selection.select(this.options.ownerDocument,
6166-
parentElement.firstChild, 0,
6167-
parentElement.lastChild, parentElement.lastChild.nodeType === 3 ?
6168-
parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length);
6170+
Selection.select(
6171+
this.options.ownerDocument,
6172+
parentElement.firstChild,
6173+
0,
6174+
parentElement.lastChild,
6175+
parentElement.lastChild.nodeType === 3 ?
6176+
parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length
6177+
);
61696178
} else {
6170-
Selection.select(this.options.ownerDocument,
6171-
parentElement, 0,
6172-
parentElement, parentElement.childNodes.length);
6179+
Selection.select(
6180+
this.options.ownerDocument,
6181+
parentElement,
6182+
0,
6183+
parentElement,
6184+
parentElement.childNodes.length
6185+
);
61736186
}
6187+
61746188
var modifiedExportedSelection = this.exportSelection();
61756189

6176-
textNodes = Util.findOrCreateMatchingTextNodes(this.options.ownerDocument,
6177-
fragment,
6178-
{
6179-
start: exportedSelection.start - modifiedExportedSelection.start,
6180-
end: exportedSelection.end - modifiedExportedSelection.start,
6181-
editableElementIndex: exportedSelection.editableElementIndex
6182-
});
6190+
textNodes = Util.findOrCreateMatchingTextNodes(
6191+
this.options.ownerDocument,
6192+
fragment,
6193+
{
6194+
start: exportedSelection.start - modifiedExportedSelection.start,
6195+
end: exportedSelection.end - modifiedExportedSelection.start,
6196+
editableElementIndex: exportedSelection.editableElementIndex
6197+
}
6198+
);
6199+
61836200
// Creates the link in the document fragment
61846201
Util.createLink(this.options.ownerDocument, textNodes, opts.url.trim());
61856202
// Chrome trims the leading whitespaces when inserting HTML, which messes up restoring the selection.
61866203
var leadingWhitespacesCount = (fragment.firstChild.innerHTML.match(/^\s+/) || [''])[0].length;
61876204
// Now move the created link back into the original document in a way to preserve undo/redo history
6188-
Util.insertHTMLCommand(this.options.ownerDocument,
6189-
fragment.firstChild.innerHTML.replace(/^\s+/, ''));
6205+
Util.insertHTMLCommand(this.options.ownerDocument, fragment.firstChild.innerHTML.replace(/^\s+/, ''));
61906206
exportedSelection.start -= leadingWhitespacesCount;
61916207
exportedSelection.end -= leadingWhitespacesCount;
6208+
61926209
this.importSelection(exportedSelection);
61936210
} else {
61946211
this.options.ownerDocument.execCommand('createLink', false, opts.url);
61956212
}
6213+
61966214
if (this.options.targetBlank || opts.target === '_blank') {
61976215
Util.setTargetBlank(Selection.getSelectionStart(this.options.ownerDocument), opts.url);
61986216
}
@@ -6249,7 +6267,7 @@ MediumEditor.parseVersionString = function (release) {
62496267

62506268
MediumEditor.version = MediumEditor.parseVersionString.call(this, ({
62516269
// grunt-bump looks for this:
6252-
'version': '5.5.2'
6270+
'version': '5.5.3'
62536271
}).version);
62546272

62556273
return MediumEditor;

dist/js/medium-editor.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "medium-editor",
3-
"version": "5.5.2",
3+
"version": "5.5.3",
44
"author": "Davi Ferreira <hi@daviferreira.com>",
55
"contributors": [
66
{

src/js/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ MediumEditor.parseVersionString = function (release) {
1717

1818
MediumEditor.version = MediumEditor.parseVersionString.call(this, ({
1919
// grunt-bump looks for this:
20-
'version': '5.5.2'
20+
'version': '5.5.3'
2121
}).version);

0 commit comments

Comments
 (0)