X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/471681497ab6e3ae9919f4e67f8edfc5e63a0670..79d1f9aef5454bf4cf75ef8f41c07d6439914569:/src/editor/modules/documentCanvas/canvas/canvas.js diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 70c0f49..663b8a6 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -89,9 +89,21 @@ $.extend(Canvas.prototype, { keyboard.handleKey(e, this); }.bind(this)); + var mouseDown; + this.wrapper.on('mousedown', '[document-node-element], [document-text-element]', function(e) { + mouseDown = e.target; + }); + this.wrapper.on('click', '[document-node-element], [document-text-element]', function(e) { e.stopPropagation(); - canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false}); + if(e.originalEvent.detail === 3) { + e.preventDefault(); + canvas._moveCaretToTextElement(canvas.getDocumentElement(e.currentTarget), 'whole'); + } else { + if(mouseDown === e.target) { + canvas.setCurrentElement(canvas.getDocumentElement(e.currentTarget), {caretTo: false}); + } + } }); this.wrapper.on('paste', function(e) { @@ -131,7 +143,6 @@ $.extend(Canvas.prototype, { canvas._moveCaretToTextElement(canvas.getDocumentElement(mutation.target), 'end'); } observer.observe(canvas.wrapper[0], config); - canvas.publisher('contentChanged'); var textElement = canvas.getDocumentElement(mutation.target), toSet = mutation.target.data !== utils.unicode.ZWS ? mutation.target.data : ''; @@ -245,7 +256,6 @@ $.extend(Canvas.prototype, { } else { this.wrapper.find('.current-node-element').removeClass('current-node-element'); element._container().addClass('current-node-element'); - this.publisher('currentElementChanged', element); } }.bind(this); @@ -289,12 +299,13 @@ $.extend(Canvas.prototype, { range.setStart(node, where); } - var collapseArg = true; - if(where === 'end') { - collapseArg = false; + if(where !== 'whole') { + var collapseArg = true; + if(where === 'end') { + collapseArg = false; + } + range.collapse(collapseArg); } - range.collapse(collapseArg); - var selection = document.getSelection(); selection.removeAllRanges(); @@ -357,16 +368,16 @@ $.extend(Cursor.prototype, { return { element: anchorElement, offset: selection.anchorOffset, - offsetAtBeginning: selection.anchorOffset === 0, - offsetAtEnd: selection.anchorNode.data.length === selection.anchorOffset + offsetAtBeginning: selection.anchorOffset === 0 || anchorElement.getText() === '', + offsetAtEnd: selection.anchorNode.data.length === selection.anchorOffset || anchorElement.getText() === '' }; } if(which === 'focus') { return { element: focusElement, offset: selection.focusOffset, - offsetAtBeginning: selection.focusOffset === 0, - offsetAtEnd: selection.focusNode.data.length === selection.focusOffset + offsetAtBeginning: selection.focusOffset === 0 || focusElement.getText() === '', + offsetAtEnd: selection.focusNode.data.length === selection.focusOffset || focusElement.getText() === '', }; } @@ -414,8 +425,8 @@ $.extend(Cursor.prototype, { return { element: placeData.element, offset: placeData.offset, - offsetAtBeginning: placeData.offset === 0, - offsetAtEnd: nodeLen === placeData.offset + offsetAtBeginning: placeData.offset === 0 || focusElement.getText() === '', + offsetAtEnd: nodeLen === placeData.offset || focusElement.getText() === '' }; } });