Skip to content

Commit 9215a24

Browse files
committed
Add escape button for @ mentions in context menu
Implements a new escape option in the context menu that allows users to escape @ symbols by converting them to \@ when they want to prevent mention expansion. Key changes: - Add Escape option type to ContextMenuOptionType enum - Implement escape functionality in insertMention() utility function - Add escape option rendering in ContextMenu component - Handle escape selection in ChatTextArea component The escape option appears at the bottom of context menus when @ symbols are present and converts @ to \@ with proper cursor positioning.
1 parent a29c488 commit 9215a24

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
275275
const newCursorPosition = newValue.indexOf(" ", mentionIndex + insertValue.length) + 1
276276
setCursorPosition(newCursorPosition)
277277
setIntendedCursorPosition(newCursorPosition)
278+
} else if (type === ContextMenuOptionType.Escape) {
279+
// Replace @ with \@ and position cursor after the escaped sequence
280+
const beforeCursor = textAreaRef.current.value.substring(0, cursorPosition - 1) // -1 to remove the '@'
281+
const afterCursor = textAreaRef.current.value.substring(cursorPosition)
282+
const newValue = beforeCursor + "\\@" + afterCursor
283+
setInputValue(newValue)
284+
// Position cursor after the escaped '@'
285+
const newCaretPosition = beforeCursor.length + 2 // +2 for '\@'
286+
setCursorPosition(newCaretPosition)
287+
setIntendedCursorPosition(newCaretPosition)
278288

279289
// Scroll to cursor.
280290
setTimeout(() => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
9393
return <span>Terminal</span>
9494
case ContextMenuOptionType.URL:
9595
return <span>Paste URL to fetch contents</span>
96+
case ContextMenuOptionType.Escape:
97+
return <span>Escape @ symbol</span>
9698
case ContextMenuOptionType.NoResults:
9799
return <span>No results found</span>
98100
case ContextMenuOptionType.Git:
@@ -175,6 +177,8 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
175177
return "terminal"
176178
case ContextMenuOptionType.URL:
177179
return "link"
180+
case ContextMenuOptionType.Escape:
181+
return "close"
178182
case ContextMenuOptionType.Git:
179183
return "git-commit"
180184
case ContextMenuOptionType.NoResults:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export enum ContextMenuOptionType {
9797
Git = "git",
9898
NoResults = "noResults",
9999
Mode = "mode", // Add mode type
100+
Escape = "escape", // Add escape type
100101
}
101102

102103
export interface ContextMenuQueryItem {
@@ -190,6 +191,7 @@ export function getContextMenuOptions(
190191
{ type: ContextMenuOptionType.Folder },
191192
{ type: ContextMenuOptionType.File },
192193
{ type: ContextMenuOptionType.Git },
194+
{ type: ContextMenuOptionType.Escape },
193195
]
194196
}
195197

0 commit comments

Comments
 (0)