Skip to content

Commit 1d029ed

Browse files
authored
refactor(context-menu): handle filename display better (RooCodeInc#2684)
* refactor(context-menu): handle filename display better * refactor(context-menu): reduce string computation
1 parent c980662 commit 1d029ed

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,38 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
109109
case ContextMenuOptionType.OpenedFile:
110110
case ContextMenuOptionType.Folder:
111111
if (option.value) {
112+
// remove trailing slash
113+
const path = removeLeadingNonAlphanumeric(option.value || "").replace(/\/$/, "")
114+
const pathList = path.split("/")
115+
const filename = pathList.at(-1)
116+
const folderPath = pathList.slice(0, -1).join("/")
112117
return (
113-
<>
114-
<span>/</span>
115-
{option.value?.startsWith("/.") && <span>.</span>}
118+
<div
119+
style={{
120+
flex: 1,
121+
overflow: "hidden",
122+
display: "flex",
123+
gap: "0.5em",
124+
whiteSpace: "nowrap",
125+
alignItems: "center",
126+
justifyContent: "space-between",
127+
textAlign: "left",
128+
}}>
129+
<span>{filename}</span>
116130
<span
117131
style={{
118132
whiteSpace: "nowrap",
119133
overflow: "hidden",
120134
textOverflow: "ellipsis",
121135
direction: "rtl",
122-
textAlign: "left",
136+
textAlign: "right",
137+
flex: 1,
138+
opacity: 0.75,
139+
fontSize: "0.75em",
123140
}}>
124-
{removeLeadingNonAlphanumeric(option.value || "") + "\u200E"}
141+
{folderPath}
125142
</span>
126-
</>
143+
</div>
127144
)
128145
} else {
129146
return <span>Add {option.type === ContextMenuOptionType.File ? "File" : "Folder"}</span>
@@ -189,10 +206,9 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
189206
key={`${option.type}-${option.value || index}`}
190207
onClick={() => isOptionSelectable(option) && onSelect(option.type, option.value)}
191208
style={{
192-
padding: "8px 12px",
209+
padding: "4px 6px",
193210
cursor: isOptionSelectable(option) ? "pointer" : "default",
194211
color: "var(--vscode-dropdown-foreground)",
195-
borderBottom: "1px solid var(--vscode-editorGroup-border)",
196212
display: "flex",
197213
alignItems: "center",
198214
justifyContent: "space-between",
@@ -232,7 +248,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
232248
!option.value && (
233249
<i
234250
className="codicon codicon-chevron-right"
235-
style={{ fontSize: "14px", flexShrink: 0, marginLeft: 8 }}
251+
style={{ fontSize: "10px", flexShrink: 0, marginLeft: 8 }}
236252
/>
237253
)}
238254
{(option.type === ContextMenuOptionType.Problems ||
@@ -244,15 +260,15 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
244260
option.value)) && (
245261
<i
246262
className="codicon codicon-add"
247-
style={{ fontSize: "14px", flexShrink: 0, marginLeft: 8 }}
263+
style={{ fontSize: "10px", flexShrink: 0, marginLeft: 8 }}
248264
/>
249265
)}
250266
</div>
251267
))
252268
) : (
253269
<div
254270
style={{
255-
padding: "12px",
271+
padding: "4px",
256272
display: "flex",
257273
alignItems: "center",
258274
justifyContent: "center",

0 commit comments

Comments
 (0)