提交 acaf2503 编写于 作者: B Benjamin Pasero

editorgroup - reduce lookup overhead for known editors

上级 5f72d181
......@@ -222,7 +222,7 @@ export class EditorGroup extends Disposable {
// Handle active
if (makeActive) {
this.setActive(newEditor);
this.doSetActive(newEditor);
}
return newEditor;
......@@ -233,12 +233,12 @@ export class EditorGroup extends Disposable {
// Pin it
if (makePinned) {
this.pin(existingEditor);
this.doPin(existingEditor);
}
// Activate it
if (makeActive) {
this.setActive(existingEditor);
this.doSetActive(existingEditor);
}
// Respect index
......@@ -328,7 +328,7 @@ export class EditorGroup extends Disposable {
}
}
this.setActive(newActive);
this.doSetActive(newActive);
}
// One Editor
......@@ -406,6 +406,10 @@ export class EditorGroup extends Disposable {
return; // not found
}
this.doSetActive(editor);
}
private doSetActive(editor: EditorInput): void {
if (this.matches(this.active, editor)) {
return; // already active
}
......@@ -413,7 +417,9 @@ export class EditorGroup extends Disposable {
this.active = editor;
// Bring to front in MRU list
this.setMostRecentlyUsed(editor);
const mruIndex = this.indexOf(editor, this.mru);
this.mru.splice(mruIndex, 1);
this.mru.unshift(editor);
// Event
this._onDidEditorActivate.fire(editor);
......@@ -425,6 +431,10 @@ export class EditorGroup extends Disposable {
return; // not found
}
this.doPin(editor);
}
private doPin(editor: EditorInput): void {
if (!this.isPreview(editor)) {
return; // can only pin a preview editor
}
......@@ -442,6 +452,10 @@ export class EditorGroup extends Disposable {
return; // not found
}
this.doUnpin(editor);
}
private doUnpin(editor: EditorInput): void {
if (!this.isPinned(editor)) {
return; // can only unpin a pinned editor
}
......@@ -565,21 +579,6 @@ export class EditorGroup extends Disposable {
return false;
}
private setMostRecentlyUsed(candidate: EditorInput): void {
const editor = this.findEditor(candidate);
if (!editor) {
return; // not found
}
const mruIndex = this.indexOf(editor, this.mru);
// Remove old index
this.mru.splice(mruIndex, 1);
// Set editor as most recent one (first)
this.mru.unshift(editor);
}
private matches(editorA: IEditorInput | null, editorB: IEditorInput | null): boolean {
return !!editorA && !!editorB && editorA.matches(editorB);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册