Skip to content

Commit

Permalink
Enhancement : cursor/selection preserved
Browse files Browse the repository at this point in the history
The cursor or the selection is now preserved when we close an editor
and when we use ctrlcmd + p to reopen it. It stays at the location where
we left it and doesn't end up at the beginning of the file like before.
  • Loading branch information
OmarSdt-EC committed Jun 14, 2021
1 parent 2880525 commit c7f5eeb
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit c7f5eeb

Please sign in to comment.