Skip to content

Commit

Permalink
Merge pull request #337 from sfyr111/feat_OpenInOppositeGroup
Browse files Browse the repository at this point in the history
feat: Implement "Open in Opposite Group" command
  • Loading branch information
kasecato authored Mar 31, 2024
2 parents bdfd3e3 + b134cbb commit 84b1b02
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ shift+f12 | shift+f12 | Restore Default layout | ✅

Linux, Windows | macOS | Feature | Supported
---------------|------|---------|----------
N/A | N/A | Open in Opposite Group | ✅
ctrl+d | cmd+d | Compare Files | ✅
ctrl+d | cmd+d | Compare Selected Files | ✅
f7 | f7 | Next difference | ✅
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"url": "https://github.com/kasecato/vscode-intellij-idea-keybindings/issues"
},
"activationEvents": [
"onCommand:intellij.importKeyMapsSchema"
"onCommand:intellij.importKeyMapsSchema",
"onCommand:intellij.openInOppositeGroup"
],
"extensionKind": [
"ui"
Expand Down Expand Up @@ -186,6 +187,11 @@
"intellij": "Implement methods"
},

{
"command": "intellij.openInOppositeGroup",
"when": "editorTextFocus",
"intellij": "Open in Opposite Group"
},
{
"key": "ctrl+[Slash]",
"mac": "cmd+[Slash]",
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { FileReaderDefault } from './importer/reader/FileReaderDefault';
import { Picker, UNSELECT } from './importer/reader/Picker';
import { IntelliJSyntaxAnalyzer } from './importer/syntax-analyzer/IntelliJSyntaxAnalyzer';
import { FileOpen } from './importer/writer/FileOpen';
import { IntelliJExtension } from './importer/extension/IntelliJExtension';

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('intellij.importKeyMapsSchema', async () => await importKeyMapsSchema(context))
vscode.commands.registerCommand('intellij.importKeyMapsSchema', async () => await importKeyMapsSchema(context)),
vscode.commands.registerCommand('intellij.openInOppositeGroup', async () => await IntelliJExtension.openInOppositeGroup())
);
}

Expand Down
43 changes: 43 additions & 0 deletions src/importer/extension/IntellijExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as vscode from 'vscode';

export class IntelliJExtension {
/**
* Opens the currently active editor tab in the opposite editor group.
* If the active editor is in the first group, it will open in the second group, and vice versa.
* Focus is moved to the newly opened editor.
*/
public static async openInOppositeGroup() {
const activeEditor = vscode.window.activeTextEditor;

// Check if there are any open text editors
if (vscode.window.visibleTextEditors.length === 0) {
// If there are no documents open, do nothing
return;
}

if (!activeEditor || !activeEditor.viewColumn) {
// Exit if there is no active text editor or view column
return;
}

// Determine if there's an opposite group by checking if there are editors open in a different group
const hasOppositeGroup = vscode.window.visibleTextEditors.some(
editor => editor.viewColumn !== activeEditor.viewColumn
);

// Only proceed if there's an opposite group
if (!hasOppositeGroup) {
return; // Exit if there is no opposite group
}

// Decide in which view column the document should be opened
let columnToShowIn = activeEditor.viewColumn === vscode.ViewColumn.One
? vscode.ViewColumn.Two
: vscode.ViewColumn.One;

// Open the document in the specified view column and move focus to the new editor
const openedEditor = await vscode.window.showTextDocument(activeEditor.document, { viewColumn: columnToShowIn, preview: false });
await vscode.window.showTextDocument(openedEditor.document, openedEditor.viewColumn);
}

}
8 changes: 7 additions & 1 deletion src/package-with-comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"url": "https://github.com/kasecato/vscode-intellij-idea-keybindings/issues"
},
"activationEvents": [
"onCommand:intellij.importKeyMapsSchema"
"onCommand:intellij.importKeyMapsSchema",
"onCommand:intellij.openInOppositeGroup"
],
"extensionKind": [
"ui"
Expand Down Expand Up @@ -232,6 +233,11 @@
"todo": "N/A"
},
*/
{
"command": "intellij.openInOppositeGroup",
"when": "editorTextFocus",
"intellij": "Open in Opposite Group"
},
{
"key": "ctrl+[Slash]",
"mac": "cmd+[Slash]",
Expand Down

0 comments on commit 84b1b02

Please sign in to comment.