Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: No way to find out that an editor has closed #643

Closed
bpasero opened this issue Nov 25, 2015 · 5 comments
Closed

API: No way to find out that an editor has closed #643

bpasero opened this issue Nov 25, 2015 · 5 comments
Assignees
Labels
api feature-request Request for new features or functionality
Milestone

Comments

@bpasero
Copy link
Member

bpasero commented Nov 25, 2015

For the VS Code API tests I have a clean up function that signals that it is done when all editors are closed. Currently the solution is hacky, it needs to install a setInterval to periodically check on the vscode.window.visibleTextEditors property to eventually become 0 (see https://github.com/Microsoft/vscode/blob/master/extensions/vscode-api-tests/src/utils.ts#L52).

The issue is that the window.onDidChangeActiveTextEditor event is not good enough for testing on the visible text editors as shown by the following test:

test('visibleTextEditors', () => {
    return workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => {
        return window.showTextDocument(doc).then((editor) => {
            return new Promise((c, e) => {
                const listener = window.onDidChangeActiveTextEditor(d => {
                    console.log('editor is null?: ' + !d);
                    if (window.visibleTextEditors.length > 0) {
                        console.log('visibleTextEditors count is: ' + window.visibleTextEditors.length);
                        return;
                    }

                    listener.dispose();
                    c();
                });

                commands.executeCommand('workbench.action.closeAllEditors').then(null, e);
            });
        });
    });
});

The value passed in from the event is null as expected because I am running the close all editors action. However, window.visibleTextEditors.length is still 1 at that point.

@jrieken jrieken assigned alexdima and unassigned jrieken Nov 26, 2015
@jrieken
Copy link
Member

jrieken commented Nov 26, 2015

@bpasero I don't see setInterval in your code.

@alexandrudima I think this is a duplicate of the editor change event firing to often

@egamma egamma modified the milestone: Backlog Dec 10, 2015
@alexdima alexdima assigned jrieken and unassigned alexdima Jul 4, 2016
@alexdima
Copy link
Member

alexdima commented Jul 4, 2016

@jrieken Maybe a new onDidChangeVisibleTextEditors ?

@jrieken
Copy link
Member

jrieken commented Oct 13, 2016

fyi @joaomoreno - please give it a try

@joaomoreno
Copy link
Member

Seems to work like a charm. 🎆

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants
@joaomoreno @egamma @bpasero @jrieken @alexdima and others