X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/26de8c3163f128baa02c78d172effcdf38a8adbc..93a6d4524f7101fa0f97148adf379a28f4545444:/modules/documentCanvas/canvas/canvas.js?ds=sidebyside diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index a5d4825..7143b79 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -434,6 +434,9 @@ $.extend(Cursor.prototype, { getSelectionAnchor: function() { return this.getSelectionBoundry('anchor'); }, + getSelectionFocus: function() { + return this.getSelectionBoundry('focus'); + }, getSelectionBoundry: function(which) { var selection = window.getSelection(), anchorElement = this.canvas.getDocumentElement(selection.anchorNode), @@ -450,6 +453,14 @@ $.extend(Cursor.prototype, { offsetAtEnd: anchorElement && anchorElement.getText().length === selection.anchorOffset }; } + if(which === 'focus') { + return { + element: focusElement, + offset: selection.focusOffset, + offsetAtBeginning: selection.focusOffset === 0, + offsetAtEnd: focusElement && focusElement.getText().length === selection.focusOffset + }; + } var element, offset; @@ -477,7 +488,7 @@ $.extend(Cursor.prototype, { } } } else { - // TODO: Handle order + // TODO: Handle order via https://developer.mozilla.org/en-US/docs/Web/API/Node.compareDocumentPosition if(which === 'start') { element = anchorElement; offset = selection.anchorOffset