Skip to content
Closed
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
10 changes: 9 additions & 1 deletion webview-ui/src/components/chat/ChatTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
return
}

if (type === ContextMenuOptionType.Export) {
// Handle export action for current mode
setInputValue("")
setShowContextMenu(false)
vscode.postMessage({ type: "exportMode", slug: mode })
return
}

if (type === ContextMenuOptionType.Mode && value) {
// Handle mode selection.
setMode(value)
Expand Down Expand Up @@ -325,7 +333,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[setInputValue, cursorPosition],
[setInputValue, cursorPosition, mode],
)

const handleKeyDown = useCallback(
Expand Down
16 changes: 16 additions & 0 deletions webview-ui/src/components/chat/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
const renderOptionContent = (option: ContextMenuQueryItem) => {
switch (option.type) {
case ContextMenuOptionType.Mode:
case ContextMenuOptionType.Export:
return (
<div style={{ display: "flex", flexDirection: "column", gap: "2px" }}>
<span style={{ lineHeight: "1.2" }}>{option.label}</span>
Expand Down Expand Up @@ -163,6 +164,8 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
switch (option.type) {
case ContextMenuOptionType.Mode:
return "symbol-misc"
case ContextMenuOptionType.Export:
return "export"
case ContextMenuOptionType.OpenedFile:
return "window"
case ContextMenuOptionType.File:
Expand Down Expand Up @@ -263,7 +266,20 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
}}
/>
)}
{(option.type === ContextMenuOptionType.Mode ||
option.type === ContextMenuOptionType.Export) && (
<i
className={`codicon codicon-${getIconForOption(option)}`}
style={{
marginRight: "6px",
flexShrink: 0,
fontSize: "14px",
marginTop: 0,
}}
/>
)}
{option.type !== ContextMenuOptionType.Mode &&
option.type !== ContextMenuOptionType.Export &&
option.type !== ContextMenuOptionType.File &&
option.type !== ContextMenuOptionType.Folder &&
option.type !== ContextMenuOptionType.OpenedFile &&
Expand Down
20 changes: 18 additions & 2 deletions webview-ui/src/utils/context-mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export enum ContextMenuOptionType {
Git = "git",
NoResults = "noResults",
Mode = "mode", // Add mode type
Export = "export", // Add export type
}

export interface ContextMenuQueryItem {
Expand All @@ -126,7 +127,18 @@ export function getContextMenuOptions(
// Handle slash commands for modes
if (query.startsWith("/") && inputValue.startsWith("/")) {
const modeQuery = query.slice(1)
if (!modes?.length) return [{ type: ContextMenuOptionType.NoResults }]

// Always include Export option at the top
const exportOption: ContextMenuQueryItem = {
type: ContextMenuOptionType.Export,
label: "Export current mode",
Copy link
Contributor

Choose a reason for hiding this comment

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

A new Export option is added to the slash-command branch in getContextMenuOptions. The export option’s label and description are hardcoded. To support localization (per translatable string guidelines), consider wrapping these strings with the translation function (e.g. t('...')).

Suggested change
label: "Export current mode",
label: t("Export current mode"),

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

description: "Export the current mode configuration",
}

if (!modes?.length) {
// If no modes, just show export option
return [exportOption]
}

// Create searchable strings array for fzf
const searchableItems = modes.map((mode) => ({
Expand Down Expand Up @@ -154,7 +166,11 @@ export function getContextMenuOptions(
description: getModeDescription(mode),
}))

return matchingModes.length > 0 ? matchingModes : [{ type: ContextMenuOptionType.NoResults }]
// Filter export option based on search query
const exportMatches = modeQuery === "" || "export".toLowerCase().includes(modeQuery.toLowerCase())
const filteredOptions = exportMatches ? [exportOption, ...matchingModes] : matchingModes

return filteredOptions.length > 0 ? filteredOptions : [{ type: ContextMenuOptionType.NoResults }]
}

const workingChanges: ContextMenuQueryItem = {
Expand Down