Skip to content

Commit cdb17e4

Browse files
committed
feat: add export option to slash command menu
- Added Export as a new ContextMenuOptionType - Modified getContextMenuOptions to include Export option at the top when "/" is typed - Updated ContextMenu component to render Export option with appropriate icon - Modified ChatTextArea to handle Export selection and trigger exportMode message - Export option triggers the same action as the export button in mode settings
1 parent a824557 commit cdb17e4

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
264264
return
265265
}
266266

267+
if (type === ContextMenuOptionType.Export) {
268+
// Handle export action for current mode
269+
setInputValue("")
270+
setShowContextMenu(false)
271+
vscode.postMessage({ type: "exportMode", slug: mode })
272+
return
273+
}
274+
267275
if (type === ContextMenuOptionType.Mode && value) {
268276
// Handle mode selection.
269277
setMode(value)
@@ -325,7 +333,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
325333
}
326334
},
327335
// eslint-disable-next-line react-hooks/exhaustive-deps
328-
[setInputValue, cursorPosition],
336+
[setInputValue, cursorPosition, mode],
329337
)
330338

331339
const handleKeyDown = useCallback(

webview-ui/src/components/chat/ContextMenu.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
6969
const renderOptionContent = (option: ContextMenuQueryItem) => {
7070
switch (option.type) {
7171
case ContextMenuOptionType.Mode:
72+
case ContextMenuOptionType.Export:
7273
return (
7374
<div style={{ display: "flex", flexDirection: "column", gap: "2px" }}>
7475
<span style={{ lineHeight: "1.2" }}>{option.label}</span>
@@ -163,6 +164,8 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
163164
switch (option.type) {
164165
case ContextMenuOptionType.Mode:
165166
return "symbol-misc"
167+
case ContextMenuOptionType.Export:
168+
return "export"
166169
case ContextMenuOptionType.OpenedFile:
167170
return "window"
168171
case ContextMenuOptionType.File:
@@ -263,7 +266,20 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
263266
}}
264267
/>
265268
)}
269+
{(option.type === ContextMenuOptionType.Mode ||
270+
option.type === ContextMenuOptionType.Export) && (
271+
<i
272+
className={`codicon codicon-${getIconForOption(option)}`}
273+
style={{
274+
marginRight: "6px",
275+
flexShrink: 0,
276+
fontSize: "14px",
277+
marginTop: 0,
278+
}}
279+
/>
280+
)}
266281
{option.type !== ContextMenuOptionType.Mode &&
282+
option.type !== ContextMenuOptionType.Export &&
267283
option.type !== ContextMenuOptionType.File &&
268284
option.type !== ContextMenuOptionType.Folder &&
269285
option.type !== ContextMenuOptionType.OpenedFile &&

webview-ui/src/utils/context-mentions.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export enum ContextMenuOptionType {
105105
Git = "git",
106106
NoResults = "noResults",
107107
Mode = "mode", // Add mode type
108+
Export = "export", // Add export type
108109
}
109110

110111
export interface ContextMenuQueryItem {
@@ -126,7 +127,18 @@ export function getContextMenuOptions(
126127
// Handle slash commands for modes
127128
if (query.startsWith("/") && inputValue.startsWith("/")) {
128129
const modeQuery = query.slice(1)
129-
if (!modes?.length) return [{ type: ContextMenuOptionType.NoResults }]
130+
131+
// Always include Export option at the top
132+
const exportOption: ContextMenuQueryItem = {
133+
type: ContextMenuOptionType.Export,
134+
label: "Export current mode",
135+
description: "Export the current mode configuration",
136+
}
137+
138+
if (!modes?.length) {
139+
// If no modes, just show export option
140+
return [exportOption]
141+
}
130142

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

157-
return matchingModes.length > 0 ? matchingModes : [{ type: ContextMenuOptionType.NoResults }]
169+
// Filter export option based on search query
170+
const exportMatches = modeQuery === "" || "export".toLowerCase().includes(modeQuery.toLowerCase())
171+
const filteredOptions = exportMatches ? [exportOption, ...matchingModes] : matchingModes
172+
173+
return filteredOptions.length > 0 ? filteredOptions : [{ type: ContextMenuOptionType.NoResults }]
158174
}
159175

160176
const workingChanges: ContextMenuQueryItem = {

0 commit comments

Comments
 (0)