Skip to content

Commit

Permalink
fix: open existing tab if its beside already
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Jun 1, 2022
1 parent 8cd851e commit 1fe66d8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"prettier.requireConfig": true,
"search.exclude": {
"**/dist": true
}
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"devDependencies": {
"@types/lodash-es": "4.17.3",
"@types/node": "10.14.18",
"@types/vscode": "1.37.0",
"@types/vscode": "1.67.0",
"@typescript-eslint/eslint-plugin": "2.4.0",
"@typescript-eslint/parser": "2.4.0",
"circular-dependency-plugin": "5.2.0",
Expand Down
19 changes: 18 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ export class Commands implements Disposable {
}
}

function findAlreadyOpenInOtherColumn(uri: Uri) {
const uriString = uri.toString();
const activeViewColumn = window.activeTextEditor && window.activeTextEditor.viewColumn;
const tabGroup = window.tabGroups.all.find(
(tg) =>
tg.viewColumn !== activeViewColumn &&
tg.tabs.some(
(tab) => {
const tabInput = tab.input;
const uri = typeof tabInput === 'object' && tabInput && (tabInput as { uri?: unknown }).uri;
return uri instanceof Uri && uri.toString() === uriString;
}
)
);
return tabGroup && tabGroup.viewColumn;
}

export async function openEditor(
uri: Uri,
options?: TextDocumentShowOptions & { openSideBySide?: boolean }
Expand All @@ -98,7 +115,7 @@ export async function openEditor(
preserveFocus: false,
preview: true,
viewColumn: openSideBySide
? ViewColumn.Beside
? findAlreadyOpenInOtherColumn(uri) || ViewColumn.Beside
: (window.activeTextEditor && window.activeTextEditor.viewColumn) || ViewColumn.One
};

Expand Down
2 changes: 1 addition & 1 deletion src/rulesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class RulesProvider implements Disposable {
Logger.log(`RulesProvider.findFiles(${pattern}, ${maxResults})`);

const files = await workspace.findFiles(
{ base: rootPath, pattern: pattern },
{ base: rootPath, baseUri: Uri.file(rootPath), pattern: pattern },
this._excludes,
maxResults,
token
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
dependencies:
source-map "^0.6.1"

"@types/vscode@1.37.0":
version "1.37.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.37.0.tgz#fb26ffabfabcd50ba70e8b454122a91b84548080"
integrity sha512-PRfeuqYuzk3vjf+puzxltIUWC+AhEGYpFX29/37w30DQSQnpf5AgMVf7GDBAdmTbWTBou+EMFz/Ne6XCM/KxzQ==
"@types/vscode@1.67.0":
version "1.67.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.67.0.tgz#8eaba41d1591aa02f5d960b7dfae3b16e066f08c"
integrity sha512-GH8BDf8cw9AC9080uneJfulhSa7KHSMI2s/CyKePXoGNos9J486w2V4YKoeNUqIEkW4hKoEAWp6/cXTwyGj47g==

"@types/webpack-sources@*":
version "0.1.5"
Expand Down

0 comments on commit 1fe66d8

Please sign in to comment.