Skip to content

Commit

Permalink
fix(ui): display raw text while redirecting to markdown file (#2720)
Browse files Browse the repository at this point in the history
* fix(ui): display raw text while redirecting to markdown file

* update
  • Loading branch information
liangfung authored Jul 25, 2024
1 parent 2abb264 commit f180daa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ee/tabby-ui/app/files/components/chat-side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useClient } from 'tabby-chat-panel/react'
import { useLatest } from '@/lib/hooks/use-latest'
import { useMe } from '@/lib/hooks/use-me'
import { useStore } from '@/lib/hooks/use-store'
import { filename2prism } from '@/lib/language-utils'
import { useChatStore } from '@/lib/stores/chat-store'
import { cn, formatLineHashForCodeBrowser } from '@/lib/utils'
import { Button } from '@/components/ui/button'
Expand Down Expand Up @@ -42,6 +43,10 @@ export const ChatSideBar: React.FC<ChatSideBarProps> = ({
const defaultRef = getDefaultRepoRef(targetRepo.refs)
// navigate to files of the default branch
const refName = resolveRepoRef(defaultRef ?? '')?.name
const detectedLanguage = context.filepath
? filename2prism(context.filepath)[0]
: undefined
const isMarkdown = detectedLanguage === 'markdown'
updateActivePath(
generateEntryPath(
targetRepo,
Expand All @@ -51,7 +56,8 @@ export const ChatSideBar: React.FC<ChatSideBarProps> = ({
),
{
hash: lineHash,
replace: false
replace: false,
plain: isMarkdown && !!lineHash
}
)
return
Expand Down
16 changes: 14 additions & 2 deletions ee/tabby-ui/app/files/components/source-code-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type SourceCodeBrowserContextValue = {
options?: {
hash?: string
replace?: boolean
plain?: boolean
}
) => Promise<void>
repoMap: Record<string, RepositoryItem>
Expand Down Expand Up @@ -174,7 +175,12 @@ const SourceCodeBrowserContextProvider: React.FC<PropsWithChildren> = ({
})
} else {
const setParams: Record<string, string> = {}
let delList = ['plain', 'redirect_filepath', 'redirect_git_url', 'line']
let delList = ['redirect_filepath', 'redirect_git_url', 'line']
if (options?.plain) {
setParams['plain'] = '1'
} else {
delList.push('plain')
}

updateUrlComponents({
pathname: `/files/${path}`,
Expand Down Expand Up @@ -482,11 +488,17 @@ const SourceCodeBrowserRenderer: React.FC<SourceCodeBrowserProps> = ({
? window.location.hash
: formatLineHashForCodeBrowser({ start: startLineNumber })

const detectedLanguage = redirect_filepath
? filename2prism(redirect_filepath)[0]
: undefined
const isMarkdown = detectedLanguage === 'markdown'

updateActivePath(
generateEntryPath(targetRepo, refName, redirect_filepath, 'file'),
{
replace: true,
hash: nextHash
hash: nextHash,
plain: isMarkdown && !!nextHash
}
)
initializing.current = false
Expand Down

0 comments on commit f180daa

Please sign in to comment.