Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7196 from adobe/nj/selection-origin
Browse files Browse the repository at this point in the history
Add origin parameter to setSelection()/setSelections()
  • Loading branch information
redmunds committed Mar 19, 2014
2 parents 8670907 + 9014ac7 commit 7d34cf7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,11 @@ define(function (require, exports, module) {
* @param {{line:number, ch:number}=} end If not specified, defaults to start.
* @param {boolean} center true to center the viewport
* @param {number} centerOptions Option value, or 0 for no options; one of the BOUNDARY_* constants above.
* @param {?string} origin An optional string that describes what other selection or edit operations this
* should be merged with for the purposes of undo. See Document.replaceRange() for more details.
*/
Editor.prototype.setSelection = function (start, end, center, centerOptions) {
this.setSelections([{start: start, end: end || start}], center, centerOptions);
Editor.prototype.setSelection = function (start, end, center, centerOptions, origin) {
this.setSelections([{start: start, end: end || start}], center, centerOptions, origin);
};

/**
Expand All @@ -1158,15 +1160,20 @@ define(function (require, exports, module) {
* one selection has primary set to true. If none has primary set to true, the last one is primary.
* @param {boolean} center true to center the viewport around the primary selection.
* @param {number} centerOptions Option value, or 0 for no options; one of the BOUNDARY_* constants above.
* @param {?string} origin An optional string that describes what other selection or edit operations this
* should be merged with for the purposes of undo. See Document.replaceRange() for more details.
*/
Editor.prototype.setSelections = function (selections, center, centerOptions) {
var primIndex = selections.length - 1;
Editor.prototype.setSelections = function (selections, center, centerOptions, origin) {
var primIndex = selections.length - 1, options;
if (origin) {
options = { origin: origin };
}
this._codeMirror.setSelections(_.map(selections, function (sel, index) {
if (sel.primary) {
primIndex = index;
}
return { anchor: sel.reversed ? sel.end : sel.start, head: sel.reversed ? sel.start : sel.end };
}), primIndex);
}), primIndex, options);
if (center) {
this.centerOnCursor(centerOptions);
}
Expand Down

0 comments on commit 7d34cf7

Please sign in to comment.