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: correct chat input cursor behavior when content is scrollable #3979

Merged
merged 1 commit into from
Nov 8, 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 @@ -139,32 +139,32 @@

if (startMatch) {
// If it's the start of a code block, store the language
currentLanguage.current = startMatch[1] || 'plaintext'

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

View workflow job for this annotation

GitHub Actions / coverage-check

142 line is not covered with tests
} else if (endMatch) {
// Reset language when code block ends
currentLanguage.current = 'plaintext'

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

View workflow job for this annotation

GitHub Actions / coverage-check

145 line is not covered with tests
} else if (currentLanguage.current !== 'plaintext') {
// Highlight entire code line if in a code block
const leadingSpaces = text.match(/^\s*/)?.[0] ?? '' // Capture leading spaces
const codeContent = text.trimStart() // Remove leading spaces for highlighting

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

View workflow job for this annotation

GitHub Actions / coverage-check

148-149 lines are not covered with tests

let highlighted = ''
highlighted = hljs.highlightAuto(codeContent).value
try {
highlighted = hljs.highlight(codeContent, {

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

View workflow job for this annotation

GitHub Actions / coverage-check

151-154 lines are not covered with tests
language:
currentLanguage.current.length > 1
? currentLanguage.current
: 'plaintext',
}).value
} catch (err) {
highlighted = hljs.highlight(codeContent, {

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

View workflow job for this annotation

GitHub Actions / coverage-check

161 line is not covered with tests
language: 'javascript',
}).value
}

const parser = new DOMParser()
const doc = parser.parseFromString(highlighted, 'text/html')

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

View workflow job for this annotation

GitHub Actions / coverage-check

166-167 lines are not covered with tests

let slateTextIndex = 0

Expand Down Expand Up @@ -269,6 +269,10 @@
? '100px'
: '40px'
textareaRef.current.style.height = textareaRef.current.scrollHeight + 'px'
textareaRef.current?.scrollTo({
top: textareaRef.current.scrollHeight,
behavior: 'instant',
})
textareaRef.current.style.overflow =
textareaRef.current.clientHeight >= 390 ? 'auto' : 'hidden'
}
Expand Down
Loading