Skip to content

Commit b539b4d

Browse files
SerxoLaxeDEVOP
andauthored
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 <[email protected]>
1 parent 2ee1cf4 commit b539b4d

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/components/ConversationCard/index.jsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import Browser from 'webextension-polyfill'
44
import InputBox from '../InputBox'
55
import ConversationItem from '../ConversationItem'
66
import { createElementAtPosition, isSafari } from '../../utils'
7-
import { DownloadIcon, LinkExternalIcon, ArchiveIcon } from '@primer/octicons-react'
7+
import {
8+
LinkExternalIcon,
9+
ArchiveIcon,
10+
DesktopDownloadIcon,
11+
MoveToBottomIcon,
12+
} from '@primer/octicons-react'
813
import { WindowDesktop, XLg, Pin } from 'react-bootstrap-icons'
914
import FileSaver from 'file-saver'
1015
import { render } from 'preact'
@@ -73,11 +78,23 @@ function ConversationCard(props) {
7378
}, [session, conversationItemData])
7479

7580
useEffect(() => {
76-
bodyRef.current.scrollTop = bodyRef.current.scrollHeight
81+
bodyRef.current.scrollTo({
82+
top: bodyRef.current.scrollHeight,
83+
behavior: 'instant',
84+
})
7785
}, [session])
7886

7987
useEffect(() => {
80-
if (config.lockWhenAnswer) bodyRef.current.scrollTop = bodyRef.current.scrollHeight
88+
const { offsetHeight, scrollHeight, scrollTop } = bodyRef.current
89+
if (
90+
config.lockWhenAnswer &&
91+
scrollHeight <= scrollTop + offsetHeight + config.answerScrollMargin
92+
) {
93+
bodyRef.current.scrollTo({
94+
top: scrollHeight,
95+
behavior: 'smooth',
96+
})
97+
}
8198
}, [conversationItemData])
8299

83100
useEffect(() => {
@@ -361,7 +378,23 @@ function ConversationCard(props) {
361378
FileSaver.saveAs(blob, 'conversation.md')
362379
}}
363380
>
364-
<DownloadIcon size={16} />
381+
<DesktopDownloadIcon size={16} />
382+
</span>
383+
<span>
384+
{conversationItemData.length > 0 && (
385+
<span
386+
title={t('Jump to bottom')}
387+
className="gpt-util-icon"
388+
onClick={() => {
389+
bodyRef.current.scrollTo({
390+
top: bodyRef.current.scrollHeight,
391+
behavior: 'smooth',
392+
})
393+
}}
394+
>
395+
<MoveToBottomIcon size={16} />
396+
</span>
397+
)}
365398
</span>
366399
</span>
367400
</div>

src/config/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const defaultConfig = {
104104
clickIconAction: 'popup',
105105
insertAtTop: isMobile(),
106106
lockWhenAnswer: false,
107+
answerScrollMargin: 200,
107108
autoRegenAfterSwitchModel: false,
108109
selectionToolsNextToInputBox: false,
109110
alwaysPinWindow: false,

0 commit comments

Comments
 (0)