Skip to content

Commit 8e3ceb0

Browse files
committed
fix: handle when the user has manually scrolled up in terminal
Signed-off-by: Evan Song <theevansong@gmail.com>
1 parent d4f9ece commit 8e3ceb0

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

apps/frontend/src/components/ui/servers/PanelTerminal.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
<div
2727
class="absolute -bottom-2 -right-2 h-7 w-7"
2828
:style="{
29-
// background should be solid red bottom right corner of a circle
3029
background: `radial-gradient(circle at 0% 0%, transparent 50%, var(--color-raised-bg) 52%)`,
3130
}"
3231
></div>
3332
<div
3433
class="absolute -bottom-2 -left-2 h-7 w-7"
3534
:style="{
36-
// background should be solid red bottom right corner of a circle
3735
background: `radial-gradient(circle at 100% 0%, transparent 50%, var(--color-raised-bg) 52%)`,
3836
}"
3937
></div>
@@ -118,6 +116,8 @@ const clientHeight = ref(0);
118116
const isFullScreen = ref(props.fullScreen);
119117
120118
const initial = ref(false);
119+
const userHasScrolled = ref(false);
120+
const isScrolledToBottom = ref(true);
121121
122122
const totalHeight = computed(
123123
() =>
@@ -126,7 +126,6 @@ const totalHeight = computed(
126126
);
127127
128128
watch(totalHeight, () => {
129-
console.log(initial.value);
130129
if (!initial.value) {
131130
scrollToBottom();
132131
}
@@ -136,7 +135,7 @@ watch(totalHeight, () => {
136135
const lerp = (start: number, end: number, t: number) => start * (1 - t) + end * t;
137136
138137
const getBlurStyle = (i: number) => {
139-
const properBlurIteration = i + 1; // Adjusting iteration for reverse order
138+
const properBlurIteration = i + 1;
140139
const blur = lerp(0, 2 ** (properBlurIteration - 3), bottomThreshold.value);
141140
const singular = 100 / progressiveBlurIterations.value;
142141
let mask = "linear-gradient(";
@@ -162,9 +161,10 @@ const getBlurStyle = (i: number) => {
162161
backdropFilter: `blur(${blur}px)`,
163162
mask,
164163
position: "absolute" as any,
165-
zIndex: progressiveBlurIterations.value - i, // Adjusting z-index for reverse order
164+
zIndex: progressiveBlurIterations.value - i,
166165
};
167166
};
167+
168168
const getItemOffset = (index: number) => {
169169
return itemHeights.value.slice(0, index).reduce((sum, height) => sum + height, 0);
170170
};
@@ -205,11 +205,16 @@ const handleScroll = () => {
205205
if (scrollContainer.value) {
206206
scrollTop.value = scrollContainer.value.scrollTop;
207207
clientHeight.value = scrollContainer.value.clientHeight;
208+
209+
const scrollHeight = scrollContainer.value.scrollHeight;
210+
isScrolledToBottom.value = scrollTop.value + clientHeight.value >= scrollHeight - 32; // threshold
211+
212+
if (!isScrolledToBottom.value) {
213+
userHasScrolled.value = true;
214+
}
208215
}
209216
210217
const maxBottom = 256;
211-
// when we're at the very bottom of the scroll container, bottomThreshold should be 0
212-
// when we're maxBottom pixels from the bottom of the scroll container, bottomThreshold should be 1
213218
bottomThreshold.value = Math.min(
214219
1,
215220
((scrollContainer.value?.scrollHeight || 1) - scrollTop.value - clientHeight.value) / maxBottom,
@@ -242,6 +247,8 @@ const updateClientHeight = () => {
242247
const scrollToBottom = () => {
243248
if (scrollContainer.value) {
244249
scrollContainer.value.scrollTop = scrollContainer.value.scrollHeight + 99999999;
250+
userHasScrolled.value = false;
251+
isScrolledToBottom.value = true;
245252
}
246253
};
247254
@@ -303,7 +310,9 @@ watch(
303310
304311
nextTick(() => {
305312
updateItemHeights();
306-
scrollToBottom();
313+
if (!userHasScrolled.value || isScrolledToBottom.value) {
314+
scrollToBottom();
315+
}
307316
});
308317
},
309318
{ deep: true, immediate: true },
@@ -329,6 +338,7 @@ watch(isFullScreen, () => {
329338
});
330339
});
331340
</script>
341+
332342
<style scoped>
333343
.terminal-font {
334344
font-family: var(--mono-font);

0 commit comments

Comments
 (0)