Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement "Open in Opposite Group" command #337

Merged
merged 5 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
---------------|------|---------|----------
ctrl+\ | cmd+\ | Open in Opposite Group | ✅
ctrl+d | cmd+d | Compare Files | ✅
ctrl+d | cmd+d | Compare Selected Files | ✅
f7 | f7 | Next difference | ✅
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "intellij-idea-keybindings",
"version": "1.6.0",
"version": "1.6.1",
"publisher": "k--kato",
"engines": {
"vscode": "^1.86.0"
Expand Down 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,13 @@
"intellij": "Implement methods"
},

{
"command": "intellij.openInOppositeGroup",
"key": "ctrl+[Backslash]",
"mac": "cmd+[Backslash]",
"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
34 changes: 34 additions & 0 deletions src/importer/extension/IntellijExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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;
if (!activeEditor) {
// console.log('No active text editor found.');
return; // Exit if there is no active text editor
}

// Determine the current view column of the active editor
const currentViewColumn = activeEditor.viewColumn;

// Decide in which view column the document should be opened
let columnToShowIn: vscode.ViewColumn;
if (currentViewColumn === vscode.ViewColumn.One || currentViewColumn === undefined) {
columnToShowIn = vscode.ViewColumn.Two; // If in the first group or undefined, open in the second group
} else if (currentViewColumn === vscode.ViewColumn.Two) {
columnToShowIn = vscode.ViewColumn.One; // If in the second group, open in the first group
} else {
// Default to the first group if in any other group
columnToShowIn = 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 });
vscode.window.showTextDocument(openedEditor.document, openedEditor.viewColumn);
}
}
7 changes: 7 additions & 0 deletions src/package-with-comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@
"todo": "N/A"
},
*/
{
"command": "extension.openInOppositeGroup",
"key": "ctrl+[Backslash]",
"mac": "cmd+[Backslash]",
"when": "editorTextFocus",
"intellij": "Open in Opposite Group"
},
{
"key": "ctrl+[Slash]",
"mac": "cmd+[Slash]",
Expand Down