Просмотр исходного кода

refactor(context-menu): handle filename display better (#2684)

* refactor(context-menu): handle filename display better

* refactor(context-menu): reduce string computation
Dicha Zelianivan Arkana 10 месяцев назад
Родитель
Сommit
1d029ed0cb
1 измененных файлов с 27 добавлено и 11 удалено
  1. 27 11
      webview-ui/src/components/chat/ContextMenu.tsx

+ 27 - 11
webview-ui/src/components/chat/ContextMenu.tsx

@@ -109,21 +109,38 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
 			case ContextMenuOptionType.OpenedFile:
 			case ContextMenuOptionType.OpenedFile:
 			case ContextMenuOptionType.Folder:
 			case ContextMenuOptionType.Folder:
 				if (option.value) {
 				if (option.value) {
+					// remove trailing slash
+					const path = removeLeadingNonAlphanumeric(option.value || "").replace(/\/$/, "")
+					const pathList = path.split("/")
+					const filename = pathList.at(-1)
+					const folderPath = pathList.slice(0, -1).join("/")
 					return (
 					return (
-						<>
-							<span>/</span>
-							{option.value?.startsWith("/.") && <span>.</span>}
+						<div
+							style={{
+								flex: 1,
+								overflow: "hidden",
+								display: "flex",
+								gap: "0.5em",
+								whiteSpace: "nowrap",
+								alignItems: "center",
+								justifyContent: "space-between",
+								textAlign: "left",
+							}}>
+							<span>{filename}</span>
 							<span
 							<span
 								style={{
 								style={{
 									whiteSpace: "nowrap",
 									whiteSpace: "nowrap",
 									overflow: "hidden",
 									overflow: "hidden",
 									textOverflow: "ellipsis",
 									textOverflow: "ellipsis",
 									direction: "rtl",
 									direction: "rtl",
-									textAlign: "left",
+									textAlign: "right",
+									flex: 1,
+									opacity: 0.75,
+									fontSize: "0.75em",
 								}}>
 								}}>
-								{removeLeadingNonAlphanumeric(option.value || "") + "\u200E"}
+								{folderPath}
 							</span>
 							</span>
-						</>
+						</div>
 					)
 					)
 				} else {
 				} else {
 					return <span>Add {option.type === ContextMenuOptionType.File ? "File" : "Folder"}</span>
 					return <span>Add {option.type === ContextMenuOptionType.File ? "File" : "Folder"}</span>
@@ -189,10 +206,9 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
 							key={`${option.type}-${option.value || index}`}
 							key={`${option.type}-${option.value || index}`}
 							onClick={() => isOptionSelectable(option) && onSelect(option.type, option.value)}
 							onClick={() => isOptionSelectable(option) && onSelect(option.type, option.value)}
 							style={{
 							style={{
-								padding: "8px 12px",
+								padding: "4px 6px",
 								cursor: isOptionSelectable(option) ? "pointer" : "default",
 								cursor: isOptionSelectable(option) ? "pointer" : "default",
 								color: "var(--vscode-dropdown-foreground)",
 								color: "var(--vscode-dropdown-foreground)",
-								borderBottom: "1px solid var(--vscode-editorGroup-border)",
 								display: "flex",
 								display: "flex",
 								alignItems: "center",
 								alignItems: "center",
 								justifyContent: "space-between",
 								justifyContent: "space-between",
@@ -232,7 +248,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
 								!option.value && (
 								!option.value && (
 									<i
 									<i
 										className="codicon codicon-chevron-right"
 										className="codicon codicon-chevron-right"
-										style={{ fontSize: "14px", flexShrink: 0, marginLeft: 8 }}
+										style={{ fontSize: "10px", flexShrink: 0, marginLeft: 8 }}
 									/>
 									/>
 								)}
 								)}
 							{(option.type === ContextMenuOptionType.Problems ||
 							{(option.type === ContextMenuOptionType.Problems ||
@@ -244,7 +260,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
 									option.value)) && (
 									option.value)) && (
 								<i
 								<i
 									className="codicon codicon-add"
 									className="codicon codicon-add"
-									style={{ fontSize: "14px", flexShrink: 0, marginLeft: 8 }}
+									style={{ fontSize: "10px", flexShrink: 0, marginLeft: 8 }}
 								/>
 								/>
 							)}
 							)}
 						</div>
 						</div>
@@ -252,7 +268,7 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
 				) : (
 				) : (
 					<div
 					<div
 						style={{
 						style={{
-							padding: "12px",
+							padding: "4px",
 							display: "flex",
 							display: "flex",
 							alignItems: "center",
 							alignItems: "center",
 							justifyContent: "center",
 							justifyContent: "center",