[FIX] summbernote lib: if a content selected with CTRL+a begin by an image, the editor switch to the image editor but the range is not correct. Need to display the image style only for real image edition.

This commit is contained in:
Christophe Matthieu
2015-01-16 16:38:08 +01:00
parent 75341ddcf9
commit 65fee06990
3 changed files with 26 additions and 15 deletions
@@ -408,6 +408,30 @@ define([
this.isOnAnchor = makeIsOn(dom.isAnchor);
// isOnAnchor: judge whether range is on cell node or not
this.isOnCell = makeIsOn(dom.isCell);
// isOnAnchor: judge whether range is an image node or not
this.isOnImg = function () {
var nb = 0;
var image;
var startPoint = {node: sc.childNodes.length && sc.childNodes[so] || sc};
startPoint.offset = startPoint.node === sc ? so : 0;
var endPoint = {node: ec.childNodes.length && ec.childNodes[eo] || ec};
endPoint.offset = endPoint.node === ec ? eo : 0;
dom.walkPoint(startPoint, endPoint, function (point) {
var node = point.node.childNodes.length && point.node.childNodes[point.offset] || point.node;
var offset = node === point.node ? point.offset : 0;
var isImg = dom.ancestor(node, dom.isImg);
if (!isImg && (node.nodeType !== 3 || (offset && node.textContent.length !== offset && node.textContent.match(/\S|\u00A0/)))) {
nb++;
}
if (isImg && image !== isImg) {
image = isImg;
nb ++;
}
});
return nb === 1 && image;
};
/**
* @param {Function} pred
@@ -595,15 +619,6 @@ define([
eo = endPoint.offset;
}
/* fir for some browser like PhantomJS
* if you select a span with PhantomJS put the carret on the last char of the previous text node
* instead of put the caret on the parent node with the the ofset to target the node
*/
if (sc.nodeType === 3 && sc.nextSibling && sc.nextSibling.nodeType !== 3 && sc.nextSibling.tagName !== "BR" && dom.nodeLength(sc) === so) {
so = dom.listPrev(ec).length-1;
sc = sc.parentNode;
}
} else if (arguments.length === 2) { //collapsed
ec = sc;
eo = so;
@@ -79,9 +79,7 @@ define([
styleInfo['line-height'] = lineHeight.toFixed(1);
}
var target = rng.sc.childNodes.length && rng.sc.childNodes[rng.so] || rng.sc;
styleInfo.image = dom.isImg(target) && target;
styleInfo.image = rng.isOnImg();
styleInfo.anchor = rng.isOnAnchor() && dom.ancestor(rng.sc, dom.isAnchor);
styleInfo.ancestors = dom.listAncestor(rng.sc, dom.isEditable);
styleInfo.range = rng;
@@ -278,9 +278,7 @@ define(['summernote/summernote'], function () {
/* hack for image and link editor */
function getImgTarget () {
var rng = range.create();
var target = rng.sc.childNodes.length && rng.sc.childNodes[rng.so] || rng.sc;
return target;
return $(".note-control-selection").data('target');
}
eventHandler.editor.padding = function ($editable, sValue) {
var $target = $(getImgTarget());