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

Preserve cursor and selection when reopening editors #9557

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/file-search/src/browser/quick-file-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { NavigationLocationService } from '@theia/editor/lib/browser/navigation/
import * as fuzzy from '@theia/core/shared/fuzzy';
import { MessageService } from '@theia/core/lib/common/message-service';
import { FileSystemPreferences } from '@theia/filesystem/lib/browser';
import { EditorOpenerOptions, Position, Range } from '@theia/editor/lib/browser';
import { EditorOpenerOptions, EditorWidget, Position, Range } from '@theia/editor/lib/browser';

export const quickFileOpen: Command = {
id: 'file-search.openFile',
Expand Down Expand Up @@ -361,9 +361,15 @@ export class QuickFileOpenService implements QuickOpenModel, QuickOpenHandler {

openFile(uri: URI): void {
const options = this.buildOpenerOptions();
const resolvedOpener = this.openerService.getOpener(uri, options);
resolvedOpener
const closedEditor = this.navigationLocationService.closedEditorsStack.find(editor => editor.uri.path.toString() === uri.path.toString());
this.openerService.getOpener(uri, options)
.then(opener => opener.open(uri, options))
.then(widget => {
// Attempt to restore the editor state if it exists, and no selection is explicitly requested.
if (widget instanceof EditorWidget && closedEditor && !options.selection) {
widget.editor.restoreViewState(closedEditor.viewState);
}
})
.catch(error => this.messageService.error(error));
}

Expand Down