From be2faf160b8527ac3d9d591456277e8c08caef7b Mon Sep 17 00:00:00 2001 From: liangfung Date: Mon, 23 Dec 2024 20:07:55 +0700 Subject: [PATCH] update: simpify --- ee/tabby-ui/app/files/components/chat-side-bar.tsx | 4 +--- .../app/search/components/assistant-message-section.tsx | 9 ++------- ee/tabby-ui/lib/utils/index.ts | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/ee/tabby-ui/app/files/components/chat-side-bar.tsx b/ee/tabby-ui/app/files/components/chat-side-bar.tsx index 91d48784844d..674bc25704c6 100644 --- a/ee/tabby-ui/app/files/components/chat-side-bar.tsx +++ b/ee/tabby-ui/app/files/components/chat-side-bar.tsx @@ -30,9 +30,7 @@ export const ChatSideBar: React.FC = ({ const repoMapRef = useLatest(repoMap) const onNavigate = async (context: Context) => { if (context?.filepath && context?.git_url) { - const lineHash = context.range - ? undefined - : formatLineHashForCodeBrowser(context?.range) + const lineHash = formatLineHashForCodeBrowser(context?.range) const repoMap = repoMapRef.current const matchedRepositoryKey = find( Object.keys(repoMap), diff --git a/ee/tabby-ui/app/search/components/assistant-message-section.tsx b/ee/tabby-ui/app/search/components/assistant-message-section.tsx index 6db85ebf5600..c9bd57cf54df 100644 --- a/ee/tabby-ui/app/search/components/assistant-message-section.tsx +++ b/ee/tabby-ui/app/search/components/assistant-message-section.tsx @@ -207,12 +207,7 @@ export function AssistantMessageSection({ searchParams.append('redirect_git_url', ctx.git_url) url.search = searchParams.toString() - const lineHash = ctx.range - ? formatLineHashForCodeBrowser({ - start: ctx.range.start, - end: ctx.range.end - }) - : undefined + const lineHash = formatLineHashForCodeBrowser(ctx.range) if (lineHash) { url.hash = lineHash } @@ -240,7 +235,7 @@ export function AssistantMessageSection({ searchParams.append('redirect_git_url', code.gitUrl) url.search = searchParams.toString() - const lineHash = range ? formatLineHashForCodeBrowser(range) : undefined + const lineHash = formatLineHashForCodeBrowser(range) if (lineHash) { url.hash = lineHash } diff --git a/ee/tabby-ui/lib/utils/index.ts b/ee/tabby-ui/lib/utils/index.ts index febf45bf59de..aab5b018659b 100644 --- a/ee/tabby-ui/lib/utils/index.ts +++ b/ee/tabby-ui/lib/utils/index.ts @@ -112,7 +112,7 @@ export function getRangeFromAttachmentCode(code: { startLine?: Maybe content: string }): LineRange | undefined { - if (!code?.startLine || typeof code.startLine !== 'number') return undefined + if (!code?.startLine) return undefined const start = code.startLine const lineCount = code.content.split('\n').length @@ -126,7 +126,7 @@ export function getRangeFromAttachmentCode(code: { export function getRangeTextFromAttachmentCode(code: AttachmentCodeItem) { const range = getRangeFromAttachmentCode(code) - return range ? formatLineHashForCodeBrowser(range) : '' + return formatLineHashForCodeBrowser(range) } export function getContent(item: AttachmentDocItem) {