Skip to content

Commit

Permalink
fix(ui): prevent extra newline on line break in question input box (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung authored Dec 12, 2024
1 parent 675c654 commit 92a15e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ee/tabby-ui/components/prompt-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '@tiptap/react'
import type { Content as TiptapContent } from '@tiptap/react'

import { NEWLINE_CHARACTER } from '@/lib/constants'
import { ContextInfo, ContextSource } from '@/lib/gql/generates/graphql'
import { useLatest } from '@/lib/hooks/use-latest'
import { cn, isCodeSourceContext, isDocSourceContext } from '@/lib/utils'
Expand Down Expand Up @@ -106,7 +107,7 @@ export const PromptEditor = forwardRef<PromptEditorRef, PromptEditorProps>(
const doSubmit = useLatest((editor: Editor) => {
if (submitting) return

const text = editor.getText()
const text = editor.getText({ blockSeparator: NEWLINE_CHARACTER }).trim()
if (!text) return

onSubmit?.(editor)
Expand Down
17 changes: 15 additions & 2 deletions ee/tabby-ui/components/textarea-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMemo, useRef, useState } from 'react'
import { Editor } from '@tiptap/react'
import { Maybe } from 'graphql/jsutils/Maybe'

import { NEWLINE_CHARACTER } from '@/lib/constants'
import { ContextInfo } from '@/lib/gql/generates/graphql'
import { useCurrentTheme } from '@/lib/hooks/use-current-theme'
import { ThreadRunContexts } from '@/lib/types'
Expand Down Expand Up @@ -98,7 +99,11 @@ export default function TextAreaSearch({
return
}

const text = editor.getText().trim()
const text = editor
.getText({
blockSeparator: NEWLINE_CHARACTER
})
.trim()
if (!text) return

const mentions = getMentionsFromText(text, contextInfo?.sources)
Expand Down Expand Up @@ -175,7 +180,15 @@ export default function TextAreaSearch({
autoFocus={autoFocus}
onFocus={() => setIsFocus(true)}
onBlur={() => setIsFocus(false)}
onUpdate={({ editor }) => setValue(editor.getText().trim())}
onUpdate={({ editor }) =>
setValue(
editor
.getText({
blockSeparator: NEWLINE_CHARACTER
})
.trim()
)
}
ref={editorRef}
placement={isFollowup ? 'bottom' : 'top'}
className={cn(
Expand Down
2 changes: 2 additions & 0 deletions ee/tabby-ui/lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const SLUG_TITLE_MAX_LENGTH = 48
export * as regex from './regex'

export const ERROR_CODE_NOT_FOUND = 'NOT_FOUND'

export const NEWLINE_CHARACTER = '\n'

0 comments on commit 92a15e4

Please sign in to comment.