medium-editor
Advanced tools
Comparing version 5.5.2 to 5.5.3
@@ -0,1 +1,7 @@ | ||
5.5.3 / 2015-08-03 | ||
================== | ||
* Fix issue with replacing a pre-existing link | ||
* Fix issue with selection after creating a link after empty paragraphs | ||
5.5.2 / 2015-08-02 | ||
@@ -2,0 +8,0 @@ ================== |
{ | ||
"name": "medium-editor", | ||
"version": "5.5.2", | ||
"version": "5.5.3", | ||
"author": "Davi Ferreira <hi@daviferreira.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -265,2 +265,36 @@ /*global MediumEditor, describe, it, expect, spyOn, | ||
}); | ||
it('should not select empty paragraphs when link is created at beginning of paragraph', function () { | ||
spyOn(MediumEditor.prototype, 'createLink').and.callThrough(); | ||
this.el.innerHTML = '<p>Some text</p><p><br/></p><p><br/></p><p>link text more text</p>'; | ||
var editor = this.newMediumEditor('.editor'), | ||
lastP = this.el.lastChild, | ||
anchorExtension = editor.getExtensionByName('anchor'), | ||
toolbar = editor.getExtensionByName('toolbar'); | ||
// Select the text 'link text' in the last paragraph | ||
MediumEditor.selection.select(document, lastP.firstChild, 0, lastP.firstChild, 'link text'.length); | ||
fireEvent(editor.elements[0], 'focus'); | ||
jasmine.clock().tick(1); | ||
// Click the 'anchor' button in the toolbar | ||
fireEvent(toolbar.getToolbarElement().querySelector('[data-action="createLink"]'), 'click'); | ||
// Input a url and save | ||
var input = anchorExtension.getInput(); | ||
input.value = 'http://www.example.com'; | ||
fireEvent(input, 'keyup', { | ||
keyCode: Util.keyCode.ENTER | ||
}); | ||
expect(editor.createLink).toHaveBeenCalledWith({ | ||
url: 'http://www.example.com', | ||
target: '_self' | ||
}); | ||
// Make sure selection is only the link | ||
var range = window.getSelection().getRangeAt(0); | ||
expect(MediumEditor.util.isDescendant(lastP, range.startContainer, true)).toBe(true, 'The start of the selection is incorrect'); | ||
expect(MediumEditor.util.isDescendant(lastP, range.endContainer, true)).toBe(true, 'The end of the selection is incorrect'); | ||
}); | ||
}); | ||
@@ -267,0 +301,0 @@ |
@@ -900,4 +900,3 @@ /*global Util, Selection, Extension, | ||
createLink: function (opts) { | ||
var customEvent, | ||
i; | ||
var customEvent, i; | ||
@@ -912,6 +911,4 @@ if (opts.url && opts.url.trim().length > 0) { | ||
startContainerParentElement = Util.getClosestBlockContainer( | ||
currentSelection.getRangeAt(0).startContainer); | ||
endContainerParentElement = Util.getClosestBlockContainer( | ||
currentSelection.getRangeAt(0).endContainer); | ||
startContainerParentElement = Util.getClosestBlockContainer(currentSelection.getRangeAt(0).startContainer); | ||
endContainerParentElement = Util.getClosestBlockContainer(currentSelection.getRangeAt(0).endContainer); | ||
@@ -922,4 +919,11 @@ if (startContainerParentElement === endContainerParentElement) { | ||
fragment = this.options.ownerDocument.createDocumentFragment(); | ||
// since we are going to create a link from an extracted text, | ||
// be sure that if we are updating a link, we won't let an empty link behind (see #754) | ||
// (Workaroung for Chrome) | ||
this.execAction('unlink'); | ||
exportedSelection = this.exportSelection(); | ||
fragment.appendChild(parentElement.cloneNode(true)); | ||
if (currentEditor === parentElement) { | ||
@@ -937,20 +941,32 @@ // We have to avoid the editor itself being wiped out when it's the only block element, | ||
Selection.select(this.options.ownerDocument, | ||
parentElement.firstChild, 0, | ||
parentElement.lastChild, parentElement.lastChild.nodeType === 3 ? | ||
parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length); | ||
Selection.select( | ||
this.options.ownerDocument, | ||
parentElement.firstChild, | ||
0, | ||
parentElement.lastChild, | ||
parentElement.lastChild.nodeType === 3 ? | ||
parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length | ||
); | ||
} else { | ||
Selection.select(this.options.ownerDocument, | ||
parentElement, 0, | ||
parentElement, parentElement.childNodes.length); | ||
Selection.select( | ||
this.options.ownerDocument, | ||
parentElement, | ||
0, | ||
parentElement, | ||
parentElement.childNodes.length | ||
); | ||
} | ||
var modifiedExportedSelection = this.exportSelection(); | ||
textNodes = Util.findOrCreateMatchingTextNodes(this.options.ownerDocument, | ||
fragment, | ||
{ | ||
start: exportedSelection.start - modifiedExportedSelection.start, | ||
end: exportedSelection.end - modifiedExportedSelection.start, | ||
editableElementIndex: exportedSelection.editableElementIndex | ||
}); | ||
textNodes = Util.findOrCreateMatchingTextNodes( | ||
this.options.ownerDocument, | ||
fragment, | ||
{ | ||
start: exportedSelection.start - modifiedExportedSelection.start, | ||
end: exportedSelection.end - modifiedExportedSelection.start, | ||
editableElementIndex: exportedSelection.editableElementIndex | ||
} | ||
); | ||
// Creates the link in the document fragment | ||
@@ -961,6 +977,6 @@ Util.createLink(this.options.ownerDocument, textNodes, opts.url.trim()); | ||
// Now move the created link back into the original document in a way to preserve undo/redo history | ||
Util.insertHTMLCommand(this.options.ownerDocument, | ||
fragment.firstChild.innerHTML.replace(/^\s+/, '')); | ||
Util.insertHTMLCommand(this.options.ownerDocument, fragment.firstChild.innerHTML.replace(/^\s+/, '')); | ||
exportedSelection.start -= leadingWhitespacesCount; | ||
exportedSelection.end -= leadingWhitespacesCount; | ||
this.importSelection(exportedSelection); | ||
@@ -970,2 +986,3 @@ } else { | ||
} | ||
if (this.options.targetBlank || opts.target === '_blank') { | ||
@@ -972,0 +989,0 @@ Util.setTargetBlank(Selection.getSelectionStart(this.options.ownerDocument), opts.url); |
@@ -122,3 +122,3 @@ /*global Util */ | ||
if (selectionState.emptyBlocksIndex && selectionState.end === nextCharIndex) { | ||
if (selectionState.emptyBlocksIndex) { | ||
var targetNode = Util.getTopBlockContainer(range.startContainer), | ||
@@ -178,2 +178,3 @@ index = 0; | ||
range.setStart(currentNode.parentNode, currentNodeIndex + 1); | ||
range.collapse(true); | ||
} | ||
@@ -180,0 +181,0 @@ } |
@@ -20,3 +20,3 @@ /*global MediumEditor */ | ||
// grunt-bump looks for this: | ||
'version': '5.5.2' | ||
'version': '5.5.3' | ||
}).version); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1497406
18352