Fix file path leading ellipsis

This commit is contained in:
Saoud Rizwan
2024-09-19 17:52:25 -04:00
parent 5fbb335bb6
commit 9351b4b633
3 changed files with 28 additions and 25 deletions

View File

@@ -4,11 +4,11 @@ import React, { memo, useMemo } from "react"
import ReactMarkdown from "react-markdown" import ReactMarkdown from "react-markdown"
import { ClaudeMessage, ClaudeSayTool } from "../../../src/shared/ExtensionMessage" import { ClaudeMessage, ClaudeSayTool } from "../../../src/shared/ExtensionMessage"
import { COMMAND_OUTPUT_STRING } from "../../../src/shared/combineCommandSequences" import { COMMAND_OUTPUT_STRING } from "../../../src/shared/combineCommandSequences"
import CodeAccordian, { formatFilePathForTruncation } from "./CodeAccordian"
import CodeBlock, { CODE_BLOCK_BG_COLOR } from "./CodeBlock"
import Thumbnails from "./Thumbnails"
import { vscode } from "../utils/vscode" import { vscode } from "../utils/vscode"
import CodeAccordian, { removeLeadingNonAlphanumeric } from "./CodeAccordian"
import CodeBlock, { CODE_BLOCK_BG_COLOR } from "./CodeBlock"
import { highlightMentions } from "./TaskHeader" import { highlightMentions } from "./TaskHeader"
import Thumbnails from "./Thumbnails"
interface ChatRowProps { interface ChatRowProps {
message: ClaudeMessage message: ClaudeMessage
@@ -209,7 +209,6 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa
style={{ style={{
color: "var(--vscode-descriptionForeground)", color: "var(--vscode-descriptionForeground)",
display: "flex", display: "flex",
justifyContent: "space-between",
alignItems: "center", alignItems: "center",
padding: "9px 10px", padding: "9px 10px",
cursor: "pointer", cursor: "pointer",
@@ -221,6 +220,7 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa
onClick={() => { onClick={() => {
vscode.postMessage({ type: "openFile", text: tool.content }) vscode.postMessage({ type: "openFile", text: tool.content })
}}> }}>
{tool.path?.startsWith(".") && <span>.</span>}
<span <span
style={{ style={{
whiteSpace: "nowrap", whiteSpace: "nowrap",
@@ -229,10 +229,10 @@ const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifiedMessa
marginRight: "8px", marginRight: "8px",
direction: "rtl", direction: "rtl",
textAlign: "left", textAlign: "left",
unicodeBidi: "plaintext",
}}> }}>
{formatFilePathForTruncation(tool.path ?? "") + "\u200E"} {removeLeadingNonAlphanumeric(tool.path ?? "") + "\u200E"}
</span> </span>
<div style={{ flexGrow: 1 }}></div>
<span <span
className={`codicon codicon-link-external`} className={`codicon codicon-link-external`}
style={{ fontSize: 13.5, margin: "1px 0" }}></span> style={{ fontSize: 13.5, margin: "1px 0" }}></span>

View File

@@ -13,12 +13,12 @@ interface CodeAccordianProps {
} }
/* /*
We need to remove leading non-alphanumeric/period characters from the path in order for our leading ellipses trick to work. We need to remove leading non-alphanumeric characters from the path in order for our leading ellipses trick to work.
^: Anchors the match to the start of the string. ^: Anchors the match to the start of the string.
[^a-zA-Z0-9.]+: Matches one or more characters that are not alphanumeric or a dot. [^a-zA-Z0-9]+: Matches one or more characters that are not alphanumeric.
The replace method removes these matched characters, effectively trimming the string up to the first alphanumeric/period character. The replace method removes these matched characters, effectively trimming the string up to the first alphanumeric character.
*/ */
export const formatFilePathForTruncation = (path: string): string => path.replace(/^[^a-zA-Z0-9.]+/, "") export const removeLeadingNonAlphanumeric = (path: string): string => path.replace(/^[^a-zA-Z0-9]+/, "")
const CodeAccordian = ({ code, diff, language, path, isFeedback, isExpanded, onToggleExpand }: CodeAccordianProps) => { const CodeAccordian = ({ code, diff, language, path, isFeedback, isExpanded, onToggleExpand }: CodeAccordianProps) => {
const inferredLanguage = useMemo( const inferredLanguage = useMemo(
@@ -39,7 +39,6 @@ const CodeAccordian = ({ code, diff, language, path, isFeedback, isExpanded, onT
style={{ style={{
color: "var(--vscode-descriptionForeground)", color: "var(--vscode-descriptionForeground)",
display: "flex", display: "flex",
justifyContent: "space-between",
alignItems: "center", alignItems: "center",
padding: "9px 10px", padding: "9px 10px",
cursor: "pointer", cursor: "pointer",
@@ -64,6 +63,7 @@ const CodeAccordian = ({ code, diff, language, path, isFeedback, isExpanded, onT
</div> </div>
) : ( ) : (
<> <>
{path?.startsWith(".") && <span>.</span>}
<span <span
style={{ style={{
whiteSpace: "nowrap", whiteSpace: "nowrap",
@@ -73,10 +73,10 @@ const CodeAccordian = ({ code, diff, language, path, isFeedback, isExpanded, onT
// trick to get ellipsis at beginning of string // trick to get ellipsis at beginning of string
direction: "rtl", direction: "rtl",
textAlign: "left", textAlign: "left",
unicodeBidi: "plaintext",
}}> }}>
{formatFilePathForTruncation(path ?? "") + "\u200E"} {removeLeadingNonAlphanumeric(path ?? "") + "\u200E"}
</span> </span>
<div style={{ flexGrow: 1 }}></div>
</> </>
)} )}
<span className={`codicon codicon-chevron-${isExpanded ? "up" : "down"}`}></span> <span className={`codicon codicon-chevron-${isExpanded ? "up" : "down"}`}></span>

View File

@@ -1,6 +1,6 @@
import React, { useEffect, useMemo, useRef } from "react" import React, { useEffect, useMemo, useRef } from "react"
import { ContextMenuOptionType, ContextMenuQueryItem, getContextMenuOptions } from "../utils/context-mentions" import { ContextMenuOptionType, ContextMenuQueryItem, getContextMenuOptions } from "../utils/context-mentions"
import { formatFilePathForTruncation } from "./CodeAccordian" import { removeLeadingNonAlphanumeric } from "./CodeAccordian"
interface ContextMenuProps { interface ContextMenuProps {
onSelect: (type: ContextMenuOptionType, value?: string) => void onSelect: (type: ContextMenuOptionType, value?: string) => void
@@ -56,17 +56,20 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
case ContextMenuOptionType.Folder: case ContextMenuOptionType.Folder:
if (option.value) { if (option.value) {
return ( return (
<span <>
style={{ <span>/</span>
whiteSpace: "nowrap", {option.value?.startsWith("/.") && <span>.</span>}
overflow: "hidden", <span
textOverflow: "ellipsis", style={{
direction: "rtl", whiteSpace: "nowrap",
textAlign: "left", overflow: "hidden",
unicodeBidi: "plaintext", textOverflow: "ellipsis",
}}> direction: "rtl",
{formatFilePathForTruncation(option.value || "") + "\u200E"} textAlign: "left",
</span> }}>
{removeLeadingNonAlphanumeric(option.value || "") + "\u200E"}
</span>
</>
) )
} else { } else {
return <span>Add {option.type === ContextMenuOptionType.File ? "File" : "Folder"}</span> return <span>Add {option.type === ContextMenuOptionType.File ? "File" : "Folder"}</span>