0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Make createRange method public

This commit is contained in:
Neil Jenkins 2018-05-09 17:43:11 +10:00
parent 74d0127974
commit db005b379b
5 changed files with 23 additions and 14 deletions

View file

@ -210,6 +210,15 @@ Returns the path through the DOM tree from the `<body>` element to the current c
Returns an object containing the active font family, size, colour and background colour for the the current cursor position, if any are set. The property names are respectively `family`, `size`, `color` and `backgroundColor`. It looks at style attributes to detect this, so will not detect `<FONT>` tags or non-inline styles. If a selection across multiple elements has been made, it will return an empty object.
### createRange
Creates a range in the document belonging to the editor. Takes 4 arguments, matching the [W3C Range properties](https://developer.mozilla.org/en-US/docs/Web/API/Range) they set:
* **startContainer**
* **startOffset**
* **endContainer** (optional; if not collapsed)
* **endOffset** (optional; if not collapsed)
### getCursorPosition
Returns a bounding client rect (top/left/right/bottom properties relative to

View file

@ -1518,7 +1518,7 @@ var keyHandlers = {
}
nodeAfterSplit = child;
}
range = self._createRange( nodeAfterSplit, 0 );
range = self.createRange( nodeAfterSplit, 0 );
self.setSelection( range );
self._updatePath( range, true );
},
@ -2425,7 +2425,7 @@ var onPaste = function ( event ) {
html += pasteArea.innerHTML;
}
range = self._createRange(
range = self.createRange(
startContainer, startOffset, endContainer, endOffset );
self.setSelection( range );
@ -2834,7 +2834,7 @@ proto.removeEventListener = function ( type, fn ) {
// --- Selection and Path ---
proto._createRange =
proto.createRange =
function ( range, startOffset, endContainer, endOffset ) {
if ( range instanceof this._win.Range ) {
return range.cloneRange();
@ -2872,7 +2872,7 @@ proto.getCursorPosition = function ( range ) {
proto._moveCursorTo = function ( toStart ) {
var root = this._root,
range = this._createRange( root, toStart ? 0 : root.childNodes.length );
range = this.createRange( root, toStart ? 0 : root.childNodes.length );
moveRangeBoundariesDownTree( range );
this.setSelection( range );
return this;
@ -2954,7 +2954,7 @@ proto.getSelection = function () {
}
}
if ( !selection ) {
selection = this._createRange( root.firstChild, 0 );
selection = this.createRange( root.firstChild, 0 );
}
return selection;
};
@ -3555,7 +3555,7 @@ proto._addFormat = function ( tag, attributes, range ) {
}
// Now set the selection to as it was before
range = this._createRange(
range = this.createRange(
startContainer, startOffset, endContainer, endOffset );
}
return range;
@ -4180,7 +4180,7 @@ proto.setHTML = function ( html ) {
// Record undo state
var range = this._getRangeAndRemoveBookmark() ||
this._createRange( root.firstChild, 0 );
this.createRange( root.firstChild, 0 );
this.saveUndoState( range );
// IE will also set focus when selecting text so don't use
// setSelection. Instead, just store it in lastSelection, so if

View file

@ -292,7 +292,7 @@ var onPaste = function ( event ) {
html += pasteArea.innerHTML;
}
range = self._createRange(
range = self.createRange(
startContainer, startOffset, endContainer, endOffset );
self.setSelection( range );

View file

@ -371,7 +371,7 @@ proto.removeEventListener = function ( type, fn ) {
// --- Selection and Path ---
proto._createRange =
proto.createRange =
function ( range, startOffset, endContainer, endOffset ) {
if ( range instanceof this._win.Range ) {
return range.cloneRange();
@ -409,7 +409,7 @@ proto.getCursorPosition = function ( range ) {
proto._moveCursorTo = function ( toStart ) {
var root = this._root,
range = this._createRange( root, toStart ? 0 : root.childNodes.length );
range = this.createRange( root, toStart ? 0 : root.childNodes.length );
moveRangeBoundariesDownTree( range );
this.setSelection( range );
return this;
@ -491,7 +491,7 @@ proto.getSelection = function () {
}
}
if ( !selection ) {
selection = this._createRange( root.firstChild, 0 );
selection = this.createRange( root.firstChild, 0 );
}
return selection;
};
@ -1092,7 +1092,7 @@ proto._addFormat = function ( tag, attributes, range ) {
}
// Now set the selection to as it was before
range = this._createRange(
range = this.createRange(
startContainer, startOffset, endContainer, endOffset );
}
return range;
@ -1717,7 +1717,7 @@ proto.setHTML = function ( html ) {
// Record undo state
var range = this._getRangeAndRemoveBookmark() ||
this._createRange( root.firstChild, 0 );
this.createRange( root.firstChild, 0 );
this.saveUndoState( range );
// IE will also set focus when selecting text so don't use
// setSelection. Instead, just store it in lastSelection, so if

View file

@ -247,7 +247,7 @@ var keyHandlers = {
}
nodeAfterSplit = child;
}
range = self._createRange( nodeAfterSplit, 0 );
range = self.createRange( nodeAfterSplit, 0 );
self.setSelection( range );
self._updatePath( range, true );
},