From fe1a4110e7c2f6caf1da256a21e8d189ca517b17 Mon Sep 17 00:00:00 2001 From: Narciso Jaramillo Date: Thu, 13 Mar 2014 14:34:43 -0700 Subject: [PATCH] Add origin parameter to setSelection()/setSelections() --- src/editor/Editor.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index c1fdd9f1694..2a7f1676672 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1130,9 +1130,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); }; /** @@ -1147,15 +1149,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; + Editor.prototype.setSelections = function (selections, center, centerOptions, origin) { + var primIndex, 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); }