mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Add Squire#moveCursorTo(Start|End) methods.
I've got 99 GitHub issues, but #99 ain't one (any more).
This commit is contained in:
parent
e59e6418af
commit
27b1532ca6
4 changed files with 45 additions and 3 deletions
14
README.md
14
README.md
|
@ -191,6 +191,20 @@ The method takes one argument:
|
||||||
|
|
||||||
Returns self (the Squire instance).
|
Returns self (the Squire instance).
|
||||||
|
|
||||||
|
### moveCursorToStart
|
||||||
|
|
||||||
|
Removes any current selection and moves the cursor to the very beginning of the
|
||||||
|
document.
|
||||||
|
|
||||||
|
Returns self (the Squire instance).
|
||||||
|
|
||||||
|
### moveCursorToEnd
|
||||||
|
|
||||||
|
Removes any current selection and moves the cursor to the very end of the
|
||||||
|
document.
|
||||||
|
|
||||||
|
Returns self (the Squire instance).
|
||||||
|
|
||||||
### undo
|
### undo
|
||||||
|
|
||||||
Undoes the most recent change.
|
Undoes the most recent change.
|
||||||
|
|
|
@ -1759,6 +1759,20 @@ proto._createRange =
|
||||||
return domRange;
|
return domRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto._moveCursorTo = function ( toStart ) {
|
||||||
|
var body = this._body,
|
||||||
|
range = this._createRange( body, toStart ? 0 : body.childNodes.length );
|
||||||
|
moveRangeBoundariesDownTree( range );
|
||||||
|
this.setSelection( range );
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
proto.moveCursorToStart = function () {
|
||||||
|
return this._moveCursorTo( true );
|
||||||
|
};
|
||||||
|
proto.moveCursorToEnd = function () {
|
||||||
|
return this._moveCursorTo( false );
|
||||||
|
};
|
||||||
|
|
||||||
proto.setSelection = function ( range ) {
|
proto.setSelection = function ( range ) {
|
||||||
if ( range ) {
|
if ( range ) {
|
||||||
// iOS bug: if you don't focus the iframe before setting the
|
// iOS bug: if you don't focus the iframe before setting the
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -301,6 +301,20 @@ proto._createRange =
|
||||||
return domRange;
|
return domRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto._moveCursorTo = function ( toStart ) {
|
||||||
|
var body = this._body,
|
||||||
|
range = this._createRange( body, toStart ? 0 : body.childNodes.length );
|
||||||
|
moveRangeBoundariesDownTree( range );
|
||||||
|
this.setSelection( range );
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
proto.moveCursorToStart = function () {
|
||||||
|
return this._moveCursorTo( true );
|
||||||
|
};
|
||||||
|
proto.moveCursorToEnd = function () {
|
||||||
|
return this._moveCursorTo( false );
|
||||||
|
};
|
||||||
|
|
||||||
proto.setSelection = function ( range ) {
|
proto.setSelection = function ( range ) {
|
||||||
if ( range ) {
|
if ( range ) {
|
||||||
// iOS bug: if you don't focus the iframe before setting the
|
// iOS bug: if you don't focus the iframe before setting the
|
||||||
|
|
Loading…
Reference in a new issue