Editors can steal focus later when opening slowly (fix #128117) (#170328)

* Editors can steal focus later when opening slowly (fix #128117)

* play it a bit safer

* fix tests
This commit is contained in:
Benjamin Pasero
2023-01-01 16:31:26 +01:00
committed by GitHub
parent 4c0cecf300
commit f01a44b447
3 changed files with 92 additions and 58 deletions

View File

@@ -71,9 +71,7 @@ suite('vscode API - window', () => {
reg.dispose();
});
test('editor, onDidChangeTextEditorViewColumn (close editor)', () => {
let actualEvent: TextEditorViewColumnChangeEvent;
test('editor, onDidChangeTextEditorViewColumn (close editor)', async () => {
const registration1 = workspace.registerTextDocumentContentProvider('bikes', {
provideTextDocumentContent() {
@@ -81,33 +79,30 @@ suite('vscode API - window', () => {
}
});
return Promise.all([
workspace.openTextDocument(Uri.parse('bikes://testing/one')).then(doc => window.showTextDocument(doc, ViewColumn.One)),
workspace.openTextDocument(Uri.parse('bikes://testing/two')).then(doc => window.showTextDocument(doc, ViewColumn.Two))
]).then(async editors => {
const doc1 = await workspace.openTextDocument(Uri.parse('bikes://testing/one'));
await window.showTextDocument(doc1, ViewColumn.One);
const [one, two] = editors;
const doc2 = await workspace.openTextDocument(Uri.parse('bikes://testing/two'));
const two = await window.showTextDocument(doc2, ViewColumn.Two);
await new Promise<void>(resolve => {
const registration2 = window.onDidChangeTextEditorViewColumn(event => {
actualEvent = event;
registration2.dispose();
resolve();
});
// close editor 1, wait a little for the event to bubble
one.hide();
assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.Two);
const actualEvent = await new Promise<TextEditorViewColumnChangeEvent>(resolve => {
const registration2 = window.onDidChangeTextEditorViewColumn(event => {
registration2.dispose();
resolve(event);
});
assert.ok(actualEvent);
assert.ok(actualEvent.textEditor === two);
assert.ok(actualEvent.viewColumn === two.viewColumn);
registration1.dispose();
// close editor 1, wait a little for the event to bubble
commands.executeCommand('workbench.action.closeEditorsInOtherGroups');
});
assert.ok(actualEvent);
assert.ok(actualEvent.textEditor === two);
assert.ok(actualEvent.viewColumn === two.viewColumn);
registration1.dispose();
});
test('editor, onDidChangeTextEditorViewColumn (move editor group)', () => {
const actualEvents: TextEditorViewColumnChangeEvent[] = [];
test('editor, onDidChangeTextEditorViewColumn (move editor group)', async () => {
const registration1 = workspace.registerTextDocumentContentProvider('bikes', {
provideTextDocumentContent() {
@@ -115,38 +110,38 @@ suite('vscode API - window', () => {
}
});
return Promise.all([
workspace.openTextDocument(Uri.parse('bikes://testing/one')).then(doc => window.showTextDocument(doc, ViewColumn.One)),
workspace.openTextDocument(Uri.parse('bikes://testing/two')).then(doc => window.showTextDocument(doc, ViewColumn.Two))
]).then(editors => {
const doc1 = await workspace.openTextDocument(Uri.parse('bikes://testing/one'));
await window.showTextDocument(doc1, ViewColumn.One);
const [, two] = editors;
two.show();
const doc2 = await workspace.openTextDocument(Uri.parse('bikes://testing/two'));
await window.showTextDocument(doc2, ViewColumn.Two);
return new Promise<void>(resolve => {
assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.Two);
const registration2 = window.onDidChangeTextEditorViewColumn(event => {
actualEvents.push(event);
const actualEvents = await new Promise<TextEditorViewColumnChangeEvent[]>(resolve => {
if (actualEvents.length === 2) {
registration2.dispose();
resolve();
}
});
const actualEvents: TextEditorViewColumnChangeEvent[] = [];
// move active editor group left
return commands.executeCommand('workbench.action.moveActiveEditorGroupLeft');
const registration2 = window.onDidChangeTextEditorViewColumn(event => {
actualEvents.push(event);
}).then(() => {
assert.strictEqual(actualEvents.length, 2);
for (const event of actualEvents) {
assert.strictEqual(event.viewColumn, event.textEditor.viewColumn);
if (actualEvents.length === 2) {
registration2.dispose();
resolve(actualEvents);
}
registration1.dispose();
});
// move active editor group left
return commands.executeCommand('workbench.action.moveActiveEditorGroupLeft');
});
assert.strictEqual(actualEvents.length, 2);
for (const event of actualEvents) {
assert.strictEqual(event.viewColumn, event.textEditor.viewColumn);
}
registration1.dispose();
});
test('active editor not always correct... #49125', async function () {