prepare bulk editor for not having an active editor, fixes #1708
This commit is contained in:
parent
d9e53235c9
commit
eba220d39c
|
@ -6,7 +6,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import {workspace, TextDocument, window, Position, Uri, EventEmitter, CancellationTokenSource, Disposable} from 'vscode';
|
import {workspace, TextDocument, window, Position, Uri, EventEmitter, CancellationTokenSource, Disposable, WorkspaceEdit} from 'vscode';
|
||||||
import {createRandomFile, deleteFile, cleanUp, pathEquals} from './utils';
|
import {createRandomFile, deleteFile, cleanUp, pathEquals} from './utils';
|
||||||
import {join, basename} from 'path';
|
import {join, basename} from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
@ -304,7 +304,8 @@ suite('workspace-namespace', () => {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
workspace.onDidChangeTextDocument(event => {
|
let subscription = workspace.onDidChangeTextDocument(event => {
|
||||||
|
subscription.dispose();
|
||||||
assert.ok(event.document === doc);
|
assert.ok(event.document === doc);
|
||||||
assert.equal(event.document.getText(), 'call1');
|
assert.equal(event.document.getText(), 'call1');
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -334,4 +335,13 @@ suite('workspace-namespace', () => {
|
||||||
assert.equal(res, void 0);
|
assert.equal(res, void 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('applyEdit', () => {
|
||||||
|
|
||||||
|
return workspace.openTextDocument(Uri.parse('untitled://' + join(workspace.rootPath, './new2.txt'))).then(doc => {
|
||||||
|
let edit = new WorkspaceEdit();
|
||||||
|
edit.insert(doc.uri, new Position(0, 0), new Array(1000).join('Hello World'));
|
||||||
|
return workspace.applyEdit(edit);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -212,7 +212,7 @@ class BulkEditModel {
|
||||||
var textEditorModel = <IModel>model.textEditorModel,
|
var textEditorModel = <IModel>model.textEditorModel,
|
||||||
task: EditTask;
|
task: EditTask;
|
||||||
|
|
||||||
if (textEditorModel.getAssociatedResource().toString() === this._sourceModel.toString()) {
|
if (this._sourceModel && textEditorModel.getAssociatedResource().toString() === this._sourceModel.toString()) {
|
||||||
this._sourceModelTask = new SourceModelEditTask(textEditorModel, this._sourceSelections);
|
this._sourceModelTask = new SourceModelEditTask(textEditorModel, this._sourceSelections);
|
||||||
task = this._sourceModelTask;
|
task = this._sourceModelTask;
|
||||||
} else {
|
} else {
|
||||||
|
@ -287,7 +287,7 @@ export function createBulkEdit(eventService: IEventService, editorService: IEdit
|
||||||
let uri: URI;
|
let uri: URI;
|
||||||
let selections: IEditorSelection[];
|
let selections: IEditorSelection[];
|
||||||
|
|
||||||
if (editor) {
|
if (editor && editor.getModel()) {
|
||||||
uri = editor.getModel().getAssociatedResource();
|
uri = editor.getModel().getAssociatedResource();
|
||||||
selections = editor.getSelections();
|
selections = editor.getSelections();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue