Skip to content

Commit

Permalink
Make createRange method public
Browse files Browse the repository at this point in the history
  • Loading branch information
neilj committed May 9, 2018
1 parent 74d0127 commit db005b3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions build/squire-raw.js
Expand Up @@ -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 );
},
Expand Down Expand Up @@ -2425,7 +2425,7 @@ var onPaste = function ( event ) {
html += pasteArea.innerHTML;
}

range = self._createRange(
range = self.createRange(
startContainer, startOffset, endContainer, endOffset );
self.setSelection( range );

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2954,7 +2954,7 @@ proto.getSelection = function () {
}
}
if ( !selection ) {
selection = this._createRange( root.firstChild, 0 );
selection = this.createRange( root.firstChild, 0 );
}
return selection;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/Clipboard.js
Expand Up @@ -292,7 +292,7 @@ var onPaste = function ( event ) {
html += pasteArea.innerHTML;
}

range = self._createRange(
range = self.createRange(
startContainer, startOffset, endContainer, endOffset );
self.setSelection( range );

Expand Down
10 changes: 5 additions & 5 deletions source/Editor.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -491,7 +491,7 @@ proto.getSelection = function () {
}
}
if ( !selection ) {
selection = this._createRange( root.firstChild, 0 );
selection = this.createRange( root.firstChild, 0 );
}
return selection;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/KeyHandlers.js
Expand Up @@ -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 );
},
Expand Down

0 comments on commit db005b3

Please sign in to comment.