mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -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
16
README.md
16
README.md
|
@ -51,7 +51,7 @@ pass a set of attributes to apply to each default block:
|
|||
blockAttributes: { style: 'font-size: 16px;' }
|
||||
})
|
||||
|
||||
If using the simple setup, call `editor.setConfig(…);` with your
|
||||
If using the simple setup, call `editor.setConfig(…);` with your
|
||||
config object instead. Be sure to do this *before* calling `editor.setHTML()`.
|
||||
|
||||
### Determining button state
|
||||
|
@ -191,6 +191,20 @@ The method takes one argument:
|
|||
|
||||
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
|
||||
|
||||
Undoes the most recent change.
|
||||
|
|
|
@ -1759,6 +1759,20 @@ proto._createRange =
|
|||
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 ) {
|
||||
if ( range ) {
|
||||
// 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;
|
||||
};
|
||||
|
||||
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 ) {
|
||||
if ( range ) {
|
||||
// iOS bug: if you don't focus the iframe before setting the
|
||||
|
|
Loading…
Reference in a new issue