Bug 956943 - Replace Editor.extendSelection with CM version. r=vporof

This commit is contained in:
Anton Kovalyov 2014-01-07 13:01:38 -08:00
parent 5814ec2ee9
commit ee2d651834
3 changed files with 10 additions and 16 deletions

View File

@ -2792,7 +2792,15 @@ GlobalSearchView.prototype = Heritage.extend(WidgetMethods, {
let line = lineResultsItem.instance.line;
DebuggerView.setEditorLocation(url, line + 1, { noDebug: true });
DebuggerView.editor.extendSelection(lineResultsItem.lineData.range);
let range = lineResultsItem.lineData.range;
let cursor = DebuggerView.editor.getOffset({ line: line, ch: 0 });
let [ anchor, head ] = DebuggerView.editor.getPosition(
cursor + range.start,
cursor + range.start + range.length
);
DebuggerView.editor.setSelection(anchor, head);
},
/**

View File

@ -73,6 +73,7 @@ const CM_MAPPING = [
"setSelection",
"getSelection",
"replaceSelection",
"extendSelection",
"undo",
"redo",
"clearHistory",
@ -366,18 +367,6 @@ Editor.prototype = {
this.setCursor(this.getCursor());
},
/**
* Extends the current selection to the position specified
* by the provided {line, ch} object.
*/
extendSelection: function (pos) {
let cm = editors.get(this);
let cursor = cm.indexFromPos(cm.getCursor());
let anchor = cm.posFromIndex(cursor + pos.start);
let head = cm.posFromIndex(cursor + pos.start + pos.length);
cm.setSelection(anchor, head);
},
/**
* Gets the first visible line number in the editor.
*/

View File

@ -25,9 +25,6 @@ function test() {
ed.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 5 });
is(ed.getSelection(), "Hello", "setSelection");
ed.extendSelection({ start: 0, length: 5 });
is(ed.getSelection(), ".\nHow", "extendSelection");
ed.dropSelection();
is(ed.getSelection(), "", "dropSelection");