From d47008f0b49b810f1318f8414b318319298ff85a Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Tue, 17 Sep 2024 06:07:58 -0400 Subject: [PATCH] Fix url menu showing --- webview-ui/src/components/ChatTextArea.tsx | 23 +++++++++++++++------- webview-ui/src/utils/mention-context.ts | 5 ++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/webview-ui/src/components/ChatTextArea.tsx b/webview-ui/src/components/ChatTextArea.tsx index 8639a5f..7d295eb 100644 --- a/webview-ui/src/components/ChatTextArea.tsx +++ b/webview-ui/src/components/ChatTextArea.tsx @@ -109,18 +109,27 @@ const ChatTextArea = forwardRef( event.preventDefault() setSelectedMenuIndex((prevIndex) => { const direction = event.key === "ArrowUp" ? -1 : 1 - let newIndex = prevIndex + direction const options = getContextMenuOptions(searchQuery, selectedType) const optionsLength = options.length - if (newIndex < 0) newIndex = optionsLength - 1 - if (newIndex >= optionsLength) newIndex = 0 + if (optionsLength === 0) return prevIndex - while (options[newIndex]?.type === "url") { - newIndex = (newIndex + direction + optionsLength) % optionsLength - } + // Find selectable options (non-URL types) + const selectableOptions = options.filter((option) => option.type !== "url") - return newIndex + if (selectableOptions.length === 0) return -1 // No selectable options + + // Find the index of the next selectable option + const currentSelectableIndex = selectableOptions.findIndex( + (option) => option === options[prevIndex] + ) + + const newSelectableIndex = + (currentSelectableIndex + direction + selectableOptions.length) % + selectableOptions.length + + // Find the index of the selected option in the original options array + return options.findIndex((option) => option === selectableOptions[newSelectableIndex]) }) return } diff --git a/webview-ui/src/utils/mention-context.ts b/webview-ui/src/utils/mention-context.ts index e10cdd3..b882303 100644 --- a/webview-ui/src/utils/mention-context.ts +++ b/webview-ui/src/utils/mention-context.ts @@ -117,6 +117,9 @@ export function shouldShowContextMenu(text: string, position: number): boolean { // Check if there's any whitespace after the '@' if (/\s/.test(textAfterAt)) return false - // Show the menu if there's just '@' or '@' followed by some text + // Don't show the menu if it's a URL + if (textAfterAt.toLowerCase().startsWith("http")) return false + + // Show the menu if there's just '@' or '@' followed by some text (but not a URL) return true }