Added a scroll to bottom button, made the automatic scroll stop when the user scrolls up (#401)

* Added go to bottom, Smooth scroll in markdown body

* scroll margin prameter added to config

---------

Co-authored-by: DEVOP <DEVOP@EXAMPLE.COM>
This commit is contained in:
Sergio Lage
2023-06-08 10:48:22 +02:00
committed by GitHub
parent 2ee1cf4d08
commit b539b4d847
2 changed files with 38 additions and 4 deletions
+37 -4
View File
@@ -4,7 +4,12 @@ import Browser from 'webextension-polyfill'
import InputBox from '../InputBox'
import ConversationItem from '../ConversationItem'
import { createElementAtPosition, isSafari } from '../../utils'
import { DownloadIcon, LinkExternalIcon, ArchiveIcon } from '@primer/octicons-react'
import {
LinkExternalIcon,
ArchiveIcon,
DesktopDownloadIcon,
MoveToBottomIcon,
} from '@primer/octicons-react'
import { WindowDesktop, XLg, Pin } from 'react-bootstrap-icons'
import FileSaver from 'file-saver'
import { render } from 'preact'
@@ -73,11 +78,23 @@ function ConversationCard(props) {
}, [session, conversationItemData])
useEffect(() => {
bodyRef.current.scrollTop = bodyRef.current.scrollHeight
bodyRef.current.scrollTo({
top: bodyRef.current.scrollHeight,
behavior: 'instant',
})
}, [session])
useEffect(() => {
if (config.lockWhenAnswer) bodyRef.current.scrollTop = bodyRef.current.scrollHeight
const { offsetHeight, scrollHeight, scrollTop } = bodyRef.current
if (
config.lockWhenAnswer &&
scrollHeight <= scrollTop + offsetHeight + config.answerScrollMargin
) {
bodyRef.current.scrollTo({
top: scrollHeight,
behavior: 'smooth',
})
}
}, [conversationItemData])
useEffect(() => {
@@ -361,7 +378,23 @@ function ConversationCard(props) {
FileSaver.saveAs(blob, 'conversation.md')
}}
>
<DownloadIcon size={16} />
<DesktopDownloadIcon size={16} />
</span>
<span>
{conversationItemData.length > 0 && (
<span
title={t('Jump to bottom')}
className="gpt-util-icon"
onClick={() => {
bodyRef.current.scrollTo({
top: bodyRef.current.scrollHeight,
behavior: 'smooth',
})
}}
>
<MoveToBottomIcon size={16} />
</span>
)}
</span>
</span>
</div>
+1
View File
@@ -104,6 +104,7 @@ export const defaultConfig = {
clickIconAction: 'popup',
insertAtTop: isMobile(),
lockWhenAnswer: false,
answerScrollMargin: 200,
autoRegenAfterSwitchModel: false,
selectionToolsNextToInputBox: false,
alwaysPinWindow: false,