Skip to content

Commit

Permalink
Merge pull request #285 from bzy-debug/fix-233
Browse files Browse the repository at this point in the history
Check all editors when computing viewColumn, so that one magit status buffer won't be open in different editors (@bzy-debug
Bao Zhiyuan)
  • Loading branch information
kahole authored Dec 4, 2023
2 parents 0d17f57 + 6532b4a commit 5500837
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/commands/statusCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function magitStatus(): Promise<any> {
if (editor?.document.uri.path === MagitStatusView.UriPath) {
return;
}
return workspace.openTextDocument(view.uri).then(doc => window.showTextDocument(doc, { viewColumn: ViewUtils.showDocumentColumn(), preview: false }));
return workspace.openTextDocument(view.uri).then(doc => window.showTextDocument(doc, { viewColumn: ViewUtils.showDocumentColumn(doc), preview: false }));
}

repository = await internalMagitStatus(repository.gitRepository);
Expand Down
17 changes: 15 additions & 2 deletions src/utils/viewUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { MagitRepository } from '../models/magitRepository';
import { View } from '../views/general/view';
import { Selection, Position, Uri, workspace, window, TextDocumentShowOptions, ViewColumn } from 'vscode';
import { Selection, Position, Uri, workspace, window, TextDocumentShowOptions, ViewColumn, TextDocument } from 'vscode';
import { Ref, RefType } from '../typings/git';
import { Token } from '../views/general/semanticTextView';
import { SemanticTokenTypes } from '../common/constants';
import GitTextUtils from './gitTextUtils';
import { DocumentView } from '../views/general/documentView';
import { magitConfig, views } from '../extension';

function hasUri(obj: unknown): obj is { uri: Uri } {
return typeof obj === 'object' && obj !== null && 'uri' in obj && obj.uri instanceof Uri;
}

export default class ViewUtils {

public static createOrUpdateView(repository: MagitRepository, uri: Uri, viewFactory: () => DocumentView) {
Expand All @@ -26,7 +30,16 @@ export default class ViewUtils {
return window.showTextDocument(doc, { viewColumn: ViewUtils.showDocumentColumn(), ...textDocumentShowOptions });
}

public static showDocumentColumn(): ViewColumn {
public static showDocumentColumn(doc?: TextDocument): ViewColumn {
if (doc) {
for (const tabGroup of window.tabGroups.all) {
for (const tab of tabGroup.tabs) {
if (hasUri(tab.input) && tab.input.uri.toString() === doc.uri.toString()) {
return tabGroup.viewColumn;
}
}
}
}
const activeColumn = window.activeTextEditor?.viewColumn;

if (magitConfig.displayBufferSameColumn) {
Expand Down

0 comments on commit 5500837

Please sign in to comment.