Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset prompt when send click button #3876

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
// Match bold text pattern *text*
const boldMatches = [...text.matchAll(/(\*.*?\*)/g)] // Find bold patterns
boldMatches.forEach((match) => {
const startOffset = match.index + 1 || 0
const length = match[0].length - 2

Check warning on line 94 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

93-94 lines are not covered with tests

ranges.push({

Check warning on line 96 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

96 line is not covered with tests
anchor: { path: [...path, childIndex], offset: startOffset },
focus: {
path: [...path, childIndex],
Expand All @@ -113,10 +113,10 @@
// Match bold text pattern **text**
const boldMatches = [...text.matchAll(/(\*\*.*?\*\*)/g)] // Find bold patterns
boldMatches.forEach((match) => {
const startOffset = match.index + 2 || 0
const length = match[0].length - 4

Check warning on line 117 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

116-117 lines are not covered with tests

ranges.push({

Check warning on line 119 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

119 line is not covered with tests
anchor: { path: [...path, childIndex], offset: startOffset },
focus: {
path: [...path, childIndex],
Expand All @@ -130,25 +130,25 @@
}

if (Editor.isBlock(editor, node) && node.type === 'code') {
node.children.forEach((child: { text: any }, childIndex: number) => {
const text = child.text

Check warning on line 134 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

133-134 lines are not covered with tests

// Match code block start and end
const startMatch = text.match(/^```(\w*)$/)
const endMatch = text.match(/^```$/)
const inlineMatch = text.match(/^`([^`]+)`$/) // Match inline code

Check warning on line 139 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

137-139 lines are not covered with tests

if (startMatch) {

Check warning on line 141 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

141 line is not covered with tests
// If it's the start of a code block, store the language
currentLanguage.current = startMatch[1] || 'plaintext'
} else if (endMatch) {

Check warning on line 144 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

143-144 lines are not covered with tests
// Reset language when code block ends
currentLanguage.current = 'plaintext'
} else if (inlineMatch) {

Check warning on line 147 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

146-147 lines are not covered with tests
// Apply syntax highlighting to inline code
const codeContent = inlineMatch[1] // Get the content within the backticks
try {
hljs.highlight(codeContent, {

Check warning on line 151 in web/screens/Thread/ThreadCenterPanel/ChatInput/RichTextEditor.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

149-151 lines are not covered with tests
language:
currentLanguage.current.length > 1
? currentLanguage.current
Expand Down Expand Up @@ -301,6 +301,11 @@
textareaRef.current.style.overflow =
textareaRef.current.clientHeight >= 390 ? 'auto' : 'hidden'
}

if (currentPrompt.length === 0) {
resetEditor()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [textareaRef.current?.clientHeight, currentPrompt, activeSettingInputBox])

const onStopInferenceClick = async () => {
Expand All @@ -317,13 +322,15 @@

// Adjust the height of the textarea to its initial state
if (textareaRef.current) {
textareaRef.current.style.height = '40px' // Reset to the initial height or your desired height
textareaRef.current.style.height = activeSettingInputBox
? '100px'
: '44px'
textareaRef.current.style.overflow = 'hidden' // Reset overflow style
}

// Ensure the editor re-renders decorations
editor.onChange()
}, [editor])
}, [activeSettingInputBox, editor])

const handleKeyDown = useCallback(
(event: React.KeyboardEvent) => {
Expand Down
Loading