Skip to content

Commit

Permalink
Add postEditor#deleteAtPosition, deprecate deleteFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Aug 2, 2016
1 parent 27ba974 commit 92c3eb6
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 386 deletions.
39 changes: 16 additions & 23 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,30 +278,23 @@ class Editor {
this.keyCommands.unshift(keyCommand);
}

deleteInDirection(direction, {unit}) {
let { range } = this;

if (unit === 'word') {
return this.deleteWordInDirection(direction);
} else {
this.run(postEditor => {
let nextPosition = postEditor.deleteFrom(range.head, direction);
postEditor.setRange(new Range(nextPosition));
});
}
}

deleteWordInDirection(direction) {
let { range: { head: curPos } } = this;

let nextPos = curPos.moveWord(direction);

let head = direction === DIRECTION.FORWARD ? curPos : nextPos;
let tail = direction === DIRECTION.FORWARD ? nextPos : curPos;

return this.deleteRange(new Range(head, tail, direction));
/**
* Convenience for {@link PostEditor#deleteAtPosition}. Deletes and puts the
* cursor in the new position.
* @public
*/
deleteAtPosition(position, direction, {unit}) {
this.run(postEditor => {
let nextPosition = postEditor.deleteAtPosition(position, direction, {unit});
postEditor.setRange(new Range(nextPosition));
});
}

/**
* Convenience for {@link PostEditor#deleteRange}. Deletes and puts the
* cursor in the new position.
* @public
*/
deleteRange(range) {
this.run(postEditor => {
let nextPosition = postEditor.deleteRange(range);
Expand All @@ -316,7 +309,7 @@ class Editor {
let { range } = this;

if (range.isCollapsed) {
this.deleteInDirection(direction, {unit});
this.deleteAtPosition(range.head, direction, {unit});
} else {
this.deleteRange(range);
}
Expand Down
Loading

0 comments on commit 92c3eb6

Please sign in to comment.