Skip to content

feat: add "Roo Code: Open in This Tab" command #7051

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 packages/types/src/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const commandIds = [
"settingsButtonClicked",

"openInNewTab",
"openInThisTab",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition to the command IDs list. The placement is logical, right after the related 'openInNewTab' command.


"showHumanRelayDialog",
"registerHumanRelayCallback",
Expand Down
66 changes: 66 additions & 0 deletions src/activate/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
return openClineInNewTab({ context, outputChannel })
},
openInNewTab: () => openClineInNewTab({ context, outputChannel }),
openInThisTab: () => openClineInThisTab({ context, outputChannel }),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command registration looks good, following the same pattern as openInNewTab.

settingsButtonClicked: () => {
const visibleProvider = getVisibleProviderOrLog(outputChannel)

Expand Down Expand Up @@ -298,3 +299,68 @@ export const openClineInNewTab = async ({ context, outputChannel }: Omit<Registe

return tabProvider
}

export const openClineInThisTab = async ({ context, outputChannel }: Omit<RegisterCommandOptions, "provider">) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice there's significant code duplication between this new function and openClineInNewTab above. About 90% of the code is identical. Could we refactor these into a shared helper function that accepts parameters for the differences (view column selection and editor group locking)?

Also, is it intentional that this function doesn't lock the editor group like openClineInNewTab does? Without the lock, clicking on files might open them over the Roo Code panel.

const contextProxy = await ContextProxy.getInstance(context)
const codeIndexManager = CodeIndexManager.getInstance(context)

// Get the existing MDM service instance to ensure consistent policy enforcement
let mdmService: MdmService | undefined
try {
mdmService = MdmService.getInstance()
} catch (error) {
// MDM service not initialized, which is fine - extension can work without it
mdmService = undefined
}

const tabProvider = new ClineProvider(context, outputChannel, "editor", contextProxy, mdmService)

// Get the active text editor's view column, or use the first column if no editor is active
const activeColumn = vscode.window.activeTextEditor?.viewColumn || vscode.ViewColumn.One

// Create the webview panel in the current tab/column
const newPanel = vscode.window.createWebviewPanel(
ClineProvider.tabPanelId,
"Roo Code",
{ viewColumn: activeColumn, preserveFocus: false },
{
enableScripts: true,
retainContextWhenHidden: true,
localResourceRoots: [context.extensionUri],
},
)

// Save as tab type panel
setPanel(newPanel, "tab")

// Set the icon
newPanel.iconPath = {
light: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "panel_light.png"),
dark: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "panel_dark.png"),
}

await tabProvider.resolveWebviewView(newPanel)

// Add listener for visibility changes to notify webview
newPanel.onDidChangeViewState(
(e) => {
const panel = e.webviewPanel
if (panel.visible) {
panel.webview.postMessage({ type: "action", action: "didBecomeVisible" })
}
},
null,
context.subscriptions,
)

// Handle panel closing events
newPanel.onDidDispose(
() => {
setPanel(undefined, "tab")
},
null,
context.subscriptions,
)

return tabProvider
}
5 changes: 5 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
"title": "%command.openInNewTab.title%",
"category": "%configuration.title%"
},
{
"command": "roo-cline.openInThisTab",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command definition looks good and follows the existing pattern.

"title": "%command.openInThisTab.title%",
"category": "%configuration.title%"
},
{
"command": "roo-cline.explainCode",
"title": "%command.explainCode.title%",
Expand Down
1 change: 1 addition & 0 deletions src/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"command.settings.title": "Settings",
"command.documentation.title": "Documentation",
"command.openInNewTab.title": "Open In New Tab",
"command.openInThisTab.title": "Open In This Tab",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English localization added correctly. Should we also update the other language files in the locales directory (zh-CN, ja, etc.) with translations for this new command title?

"command.explainCode.title": "Explain Code",
"command.fixCode.title": "Fix Code",
"command.improveCode.title": "Improve Code",
Expand Down
Loading