diff --git a/www/apps/api-reference/app/globals.css b/www/apps/api-reference/app/globals.css index 3f3d74d08e..2ec89e36d4 100644 --- a/www/apps/api-reference/app/globals.css +++ b/www/apps/api-reference/app/globals.css @@ -55,6 +55,10 @@ body[data-modal="opened"] { @apply !overflow-hidden; } + + .text-wrap { + text-wrap: wrap; + } } .grecaptcha-badge { diff --git a/www/apps/book/app/globals.css b/www/apps/book/app/globals.css index 41d7c98507..4a75d63add 100644 --- a/www/apps/book/app/globals.css +++ b/www/apps/book/app/globals.css @@ -32,6 +32,10 @@ body[data-modal="opened"] { @apply !overflow-hidden; } + + .text-wrap { + text-wrap: wrap; + } } .grecaptcha-badge { diff --git a/www/apps/resources/app/globals.css b/www/apps/resources/app/globals.css index 336288f82d..a5b9e80f86 100644 --- a/www/apps/resources/app/globals.css +++ b/www/apps/resources/app/globals.css @@ -35,6 +35,10 @@ body[data-modal="opened"] { @apply !overflow-hidden; } + + .text-wrap { + text-wrap: wrap; + } } .grecaptcha-badge { diff --git a/www/apps/ui/src/styles/globals.css b/www/apps/ui/src/styles/globals.css index ac4daf4dc5..3c92254990 100644 --- a/www/apps/ui/src/styles/globals.css +++ b/www/apps/ui/src/styles/globals.css @@ -40,6 +40,10 @@ body[data-modal="opened"] { @apply !overflow-hidden text-ui-fg-base; } + + .text-wrap { + text-wrap: wrap; + } } .grecaptcha-badge { diff --git a/www/apps/user-guide/app/globals.css b/www/apps/user-guide/app/globals.css index 03dee4656a..1d4eb3275c 100644 --- a/www/apps/user-guide/app/globals.css +++ b/www/apps/user-guide/app/globals.css @@ -28,6 +28,10 @@ body[data-modal="opened"] { @apply !overflow-hidden; } + + .text-wrap { + text-wrap: wrap; + } } .grecaptcha-badge { diff --git a/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Footer/index.tsx b/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Footer/index.tsx index f5ec39c8aa..34a2d79372 100644 --- a/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Footer/index.tsx +++ b/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Footer/index.tsx @@ -12,7 +12,7 @@ export const AiAssistantChatWindowFooter = () => { )} > Chat is cleared on refresh - +
diff --git a/www/packages/docs-ui/src/hooks/use-ai-assistant-chat-navigation/index.ts b/www/packages/docs-ui/src/hooks/use-ai-assistant-chat-navigation/index.ts
index f7d411f5be..6dda96c8f6 100644
--- a/www/packages/docs-ui/src/hooks/use-ai-assistant-chat-navigation/index.ts
+++ b/www/packages/docs-ui/src/hooks/use-ai-assistant-chat-navigation/index.ts
@@ -7,6 +7,7 @@ import {
useKeyboardShortcut,
type useKeyboardShortcutOptions,
} from "../use-keyboard-shortcut"
+import { useAiAssistantChat } from "../../providers/AiAssistant/Chat"
export type UseAiAssistantChatNavigationProps = {
getChatWindowElm: () => HTMLElement | null
@@ -23,6 +24,7 @@ export const useAiAssistantChatNavigation = ({
}: UseAiAssistantChatNavigationProps) => {
const shortcutKeys = useMemo(() => ["ArrowUp", "ArrowDown", "Enter"], [])
const { chatOpened } = useAiAssistant()
+ const { question } = useAiAssistantChat()
const handleKeyAction = (e: KeyboardEvent) => {
const chatElm = getChatWindowElm()
@@ -30,7 +32,8 @@ export const useAiAssistantChatNavigation = ({
!chatOpened ||
e.metaKey ||
e.ctrlKey ||
- !chatElm?.contains(document.activeElement)
+ !chatElm?.contains(document.activeElement) ||
+ (question.length && question.includes("\n"))
) {
return
}
@@ -135,6 +138,7 @@ export const useAiAssistantChatNavigation = ({
shortcutKeys: shortcutKeys,
checkEditing: false,
isLoading: false,
+ preventDefault: false,
action: handleKeyAction,
...keyboardProps,
})
diff --git a/www/packages/docs-ui/src/hooks/use-collapsible-code-lines/index.tsx b/www/packages/docs-ui/src/hooks/use-collapsible-code-lines/index.tsx
index c2335c1e19..9bd86aa786 100644
--- a/www/packages/docs-ui/src/hooks/use-collapsible-code-lines/index.tsx
+++ b/www/packages/docs-ui/src/hooks/use-collapsible-code-lines/index.tsx
@@ -34,7 +34,7 @@ export const useCollapsibleCodeLines = ({
const collapsedRange:
| {
start: number
- end: number
+ end: number | undefined
}
| undefined = useMemo(() => {
if (!collapsibleLinesStr) {
@@ -46,8 +46,10 @@ export const useCollapsibleCodeLines = ({
.map((lineNumber) => parseInt(lineNumber))
if (
- splitCollapsedLines.length !== 2 ||
- (splitCollapsedLines[0] !== 1 && splitCollapsedLines[1] < 2)
+ !splitCollapsedLines.length ||
+ (splitCollapsedLines.length >= 2 &&
+ splitCollapsedLines[0] !== 1 &&
+ splitCollapsedLines[1] < 2)
) {
return
}
@@ -58,6 +60,13 @@ export const useCollapsibleCodeLines = ({
}
}, [collapsibleLinesStr])
+ const isCollapsible = useCallback(
+ (tokens: Token[][]) => {
+ return collapsedRange && collapsedRange.start < tokens.length
+ },
+ [collapsedRange]
+ )
+
const type: CollapsedCodeLinesPosition | undefined = useMemo(() => {
if (!collapsedRange) {
return undefined
@@ -81,7 +90,7 @@ export const useCollapsibleCodeLines = ({
tokens: Token[][]
highlightProps: HighlightProps
}) => {
- if (!collapsedRange || !type) {
+ if (!collapsedRange || !type || !isCollapsible(tokens)) {
return <>>
}
@@ -90,7 +99,9 @@ export const useCollapsibleCodeLines = ({
const lines = tokens.slice(
startIndex,
- Math.min(collapsedRange.end, tokens.length)
+ collapsedRange.end
+ ? Math.min(collapsedRange.end, tokens.length)
+ : tokens.length
)
return (
@@ -99,7 +110,7 @@ export const useCollapsibleCodeLines = ({
)
},
- [collapsedRange, collapsibleHookResult]
+ [collapsedRange, collapsibleHookResult, isCollapsible, type]
)
const getNonCollapsedLinesElm = useCallback(
@@ -110,13 +121,13 @@ export const useCollapsibleCodeLines = ({
tokens: Token[][]
highlightProps: HighlightProps
}) => {
- if (!collapsedRange) {
+ if (!collapsedRange || !isCollapsible(tokens)) {
return getLines(tokens, highlightProps)
}
const isCollapseBeginning = collapsedRange.start === 1
const lines = tokens.slice(
- isCollapseBeginning ? collapsedRange.end : 0,
+ isCollapseBeginning ? collapsedRange.end || tokens.length : 0,
isCollapseBeginning ? undefined : collapsedRange.start
)
@@ -126,13 +137,14 @@ export const useCollapsibleCodeLines = ({
isCollapseBeginning ? collapsedRange.end : 0
)
},
- [collapsedRange, collapsibleHookResult]
+ [collapsedRange, collapsibleHookResult, isCollapsible]
)
return {
getCollapsedLinesElm,
getNonCollapsedLinesElm,
type,
+ isCollapsible,
...collapsibleHookResult,
}
}
diff --git a/www/packages/docs-ui/src/providers/AiAssistant/Chat/index.tsx b/www/packages/docs-ui/src/providers/AiAssistant/Chat/index.tsx
index 18e5b1d160..93c60a40c5 100644
--- a/www/packages/docs-ui/src/providers/AiAssistant/Chat/index.tsx
+++ b/www/packages/docs-ui/src/providers/AiAssistant/Chat/index.tsx
@@ -260,45 +260,47 @@ export const AiAssistantChatProvider = ({
useEffect(() => {
if (
- !loading &&
- answer.length &&
- thread[lastAnswerIndex]?.content !== answer
+ loading ||
+ !answer.length ||
+ thread[lastAnswerIndex]?.content === answer
) {
- const uniqueAnswerSources = answerSources
- .filter(
- (source, index) =>
- answerSources.findIndex(
- (s) => s.source_url === source.source_url
- ) === index
- )
- .map((source) => {
- const separatorIndex = source.title.indexOf("|")
- return {
- ...source,
- title:
- separatorIndex !== -1
- ? source.title.slice(0, separatorIndex)
- : source.title,
- }
- })
- setThread((prevThread) => [
- ...prevThread,
- {
- type: "answer",
- content: answer,
- question_id: identifiers?.question_answer_id,
- order: getNewOrder(prevThread),
- sources:
- uniqueAnswerSources.length > 3
- ? uniqueAnswerSources.slice(0, 3)
- : uniqueAnswerSources,
- },
- ])
- setAnswer("")
- setAnswerSources([])
- setMessagesCount((prev) => prev + 1)
- inputRef.current?.focus()
+ return
}
+
+ const uniqueAnswerSources = answerSources
+ .filter(
+ (source, index) =>
+ answerSources.findIndex((s) => s.source_url === source.source_url) ===
+ index
+ )
+ .map((source) => {
+ const separatorIndex = source.title.indexOf("|")
+ return {
+ ...source,
+ title:
+ separatorIndex !== -1
+ ? source.title.slice(0, separatorIndex)
+ : source.title,
+ }
+ })
+ setThread((prevThread) => [
+ ...prevThread,
+ {
+ type: "answer",
+ content: answer,
+ question_id: identifiers?.question_answer_id,
+ order: getNewOrder(prevThread),
+ sources:
+ uniqueAnswerSources.length > 3
+ ? uniqueAnswerSources.slice(0, 3)
+ : uniqueAnswerSources,
+ },
+ ])
+ setAnswer("")
+ setAnswerSources([])
+ setMessagesCount((prev) => prev + 1)
+ inputRef.current?.focus()
+ scrollToBottom()
}, [loading, answer, thread, lastAnswerIndex, inputRef.current])
useResizeObserver(contentRef as React.RefObject