Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

Commit a6575dc

Browse files
committed
fixed console scrolling issues
1 parent 8f31ca1 commit a6575dc

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

frontend/desktop/src/components/dbfragments/console.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
left: 0;
2323
}
2424

25+
.consoleend {
26+
height: 100px;
27+
}
28+
2529
}

frontend/desktop/src/components/dbfragments/console.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const DBConsoleFragment = ({ }: DBConsolePropType) => {
1515

1616
const currentTab: Tab = useContext(TabContext)!
1717

18-
const consoleEndRef = useRef<HTMLSpanElement>(null)
18+
const consoleRef = useRef<HTMLDivElement>(null)
19+
const consoleEndRef = useRef<HTMLDivElement>(null)
1920

2021
const dbConnection = useAppSelector(selectDBConnection)
2122
const output = useAppSelector(selectBlocks)
@@ -27,7 +28,7 @@ const DBConsoleFragment = ({ }: DBConsolePropType) => {
2728
}, [dbConnection])
2829

2930
useEffect(() => {
30-
consoleEndRef.current?.scrollIntoView({ behavior: 'smooth' })
31+
scrollToBottom("smooth")
3132
}, [output])
3233

3334
const confirmInput = () => {
@@ -36,21 +37,27 @@ const DBConsoleFragment = ({ }: DBConsolePropType) => {
3637
}
3738

3839
const focus = (e: any) => {
39-
if (e.target.id === "console") {
40+
if (consoleRef.current?.contains(e.target)) {
4041
setFocus(Math.random())
4142
}
4243
}
4344

44-
return <div className={styles.console + " " + (currentTab.isActive ? "db-tab-active" : "db-tab")} id="console" onClick={focus}>
45+
const scrollToBottom = (behavior: ScrollBehavior) => {
46+
const mainContentDiv = consoleRef.current?.parentNode as HTMLDivElement
47+
if (mainContentDiv.scrollTop !== consoleEndRef.current?.offsetTop)
48+
mainContentDiv.scrollTo({ top: consoleEndRef.current?.offsetTop, behavior })
49+
}
50+
51+
return <div className={styles.console + " " + (currentTab.isActive ? "db-tab-active" : "db-tab")} id="console" ref={consoleRef} onClick={focus}>
4552
<OutputBlock block={{
4653
text: "Start typing command and press enter to run it.\nType 'help' for more info on console.",
4754
cmd: false
4855
}} />
4956
{output.map((block, idx) => {
5057
return <OutputBlock block={block} key={idx} />
5158
})}
52-
<PromptInputWithRef onChange={setInput} isActive={currentTab.isActive} nfocus={nfocus} confirmInput={confirmInput} history={history} />
53-
<span ref={consoleEndRef}></span>
59+
<PromptInputWithRef onChange={setInput} isActive={currentTab.isActive} nfocus={nfocus} scrollToBottom={scrollToBottom} confirmInput={confirmInput} history={history} />
60+
<div id="consoleend" className={styles.consoleend} ref={consoleEndRef}></div>
5461
</div>
5562
}
5663

@@ -68,6 +75,7 @@ const PromptInputWithRef = (props: any) => {
6875
const [pointer, setPointer] = useState<number>(-1)
6976
useEffect(() => {
7077
if (props.isActive) {
78+
props.scrollToBottom("instant")
7179
inputRef.current?.focus()
7280
}
7381
}, [props.isActive, props.nfocus])

frontend/server/src/components/dbfragments/console.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
left: 0;
2323
}
2424

25+
.consoleend {
26+
height: 100px;
27+
}
28+
2529
}

frontend/server/src/components/dbfragments/console.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const DBConsoleFragment = ({ }: DBConsolePropType) => {
1515

1616
const currentTab: Tab = useContext(TabContext)!
1717

18-
const consoleEndRef = useRef<HTMLSpanElement>(null)
18+
const consoleRef = useRef<HTMLDivElement>(null)
19+
const consoleEndRef = useRef<HTMLDivElement>(null)
1920

2021
const dbConnection = useAppSelector(selectDBConnection)
2122
const output = useAppSelector(selectBlocks)
@@ -27,7 +28,7 @@ const DBConsoleFragment = ({ }: DBConsolePropType) => {
2728
}, [dbConnection])
2829

2930
useEffect(() => {
30-
consoleEndRef.current?.scrollIntoView({ behavior: 'smooth' })
31+
scrollToBottom("smooth")
3132
}, [output])
3233

3334
const confirmInput = () => {
@@ -36,21 +37,27 @@ const DBConsoleFragment = ({ }: DBConsolePropType) => {
3637
}
3738

3839
const focus = (e: any) => {
39-
if (e.target.id === "console") {
40+
if (consoleRef.current?.contains(e.target)) {
4041
setFocus(Math.random())
4142
}
4243
}
4344

44-
return <div className={styles.console + " " + (currentTab.isActive ? "db-tab-active" : "db-tab")} id="console" onClick={focus}>
45+
const scrollToBottom = (behavior: ScrollBehavior) => {
46+
const mainContentDiv = consoleRef.current?.parentNode as HTMLDivElement
47+
if (mainContentDiv.scrollTop !== consoleEndRef.current?.offsetTop)
48+
mainContentDiv.scrollTo({ top: consoleEndRef.current?.offsetTop, behavior })
49+
}
50+
51+
return <div className={styles.console + " " + (currentTab.isActive ? "db-tab-active" : "db-tab")} id="console" ref={consoleRef} onClick={focus}>
4552
<OutputBlock block={{
4653
text: "Start typing command and press enter to run it.\nType 'help' for more info on console.",
4754
cmd: false
4855
}} />
4956
{output.map((block, idx) => {
5057
return <OutputBlock block={block} key={idx} />
5158
})}
52-
<PromptInputWithRef onChange={setInput} isActive={currentTab.isActive} nfocus={nfocus} confirmInput={confirmInput} history={history} />
53-
<span ref={consoleEndRef}></span>
59+
<PromptInputWithRef onChange={setInput} isActive={currentTab.isActive} nfocus={nfocus} scrollToBottom={scrollToBottom} confirmInput={confirmInput} history={history} />
60+
<div id="consoleend" className={styles.consoleend} ref={consoleEndRef}></div>
5461
</div>
5562
}
5663

@@ -69,6 +76,7 @@ const PromptInputWithRef = (props: any) => {
6976
const [pointer, setPointer] = useState<number>(-1)
7077
useEffect(() => {
7178
if (props.isActive) {
79+
props.scrollToBottom("instant")
7280
inputRef.current?.focus()
7381
}
7482
}, [props.isActive, props.nfocus])

0 commit comments

Comments
 (0)