-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
document postEditor.setRange and change edit methods to use it #258
Comments
Things that need to be figured out:
|
Some way of getting the current cursor position & setting it again later would be useful if cursor itself is to become private. I'm currently using the following functions to stash & restore a cursor position when a document is updated externally: function stashCursor(editor) {
if (!editor || !editor.cursor.hasCursor()) {
return;
}
const { offset, section } = editor.cursor.offsets.head;
const index = editor.post.sections.toArray().indexOf(section);
return { index, offset };
}
function reapplyCursor(editor, selection) {
if (!editor || !selection) {
return;
}
const { index, offset } = selection;
const section = editor.post.sections.objectAt(index);
if (!section) {
return;
}
const position = new Position(section, offset);
const range = new Range(position, position);
editor.cursor.selectRange(range);
editor._reportSelectionState(); // TODO - should we have to do this?
} |
@rlivsey so what we're doing is moving away from
Some APIs:
So we're definitely going to keep a cursor range, but it should settle around |
Allow `Editor#selectRange`, `postEditor#setRange` to receive Range *or* Position Add `Position#toRange`, `Section#toRange` and `Post#toRange` Add `toRange` util to convert range|position into range Remove unused `Position#clone` Add `section#toPosition(offset)` Expose `Position` on global MobiledocKit export docs: label `postEditor#setRange` public fixes #258
Allow `Editor#selectRange`, `postEditor#setRange` to receive Range *or* Position Add `Position#toRange`, `Section#toRange` and `Post#toRange` Add `toRange` util to convert range|position into range Remove unused `Position#clone` Add `section#toPosition(offset)` Expose `Position` on global MobiledocKit export docs: label `postEditor#setRange` public fixes #258
* Allow `Editor#selectRange`, `postEditor#setRange`, * `postEditor#toggleSection`, and `postEditor#toggleMarkup` to receive * Range *or* Position * Add `Position#toRange`, `Section#toRange` and `Post#toRange` methods * Add `toRange` util to convert range|position into range * Remove unused `Position#clone`, `Range.fromSection` * Add `section#toPosition(offset)` * Expose `Position` on global MobiledocKit export * docs: label `postEditor#setRange` public fixes #258
released in v0.10.4 |
#248 added
postEditor.setRange
(andeditor.selectRange
). More of the edit methods in postEditor should be updated to usesetRange
where applicable, and write documentation to describe how to use this APIThe text was updated successfully, but these errors were encountered: