Skip to content
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
22 changes: 14 additions & 8 deletions src/components/VueCommand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ import {
onMounted,
nextTick,
getCurrentInstance,
useSlots
useSlots,
onBeforeUnmount
} from 'vue'
import {
createCommandNotFound,
Expand Down Expand Up @@ -298,6 +299,12 @@ const vueCommandHistoryEntryComponentRefs = ref(null)
const vueCommandHistoryRef = ref(null)
const vueCommandRef = ref(null)

// Keep a global resizeObserver instance to disconnect it at onBeforeUnmount
const resizeObserver = new ResizeObserver(() => {
// TODO: Only scroll to bottom if user scrolled to bottom before
vueCommandHistoryRef.value.scrollTop = vueCommandHistoryRef.value.scrollHeight
})

// A local copy to allow the absence of properties
const local = reactive({
cursorPosition: props.cursorPosition,
Expand Down Expand Up @@ -511,6 +518,9 @@ watch(() => props.query, query => {
// Cursor position gets updated in query component
})

onBeforeUnmount(() => {
resizeObserver.disconnect()
})
onMounted(() => {
// Binds given event listeners and calls them with the terminals references
// and exposed properties
Expand All @@ -520,20 +530,16 @@ onMounted(() => {
}

// Scroll to bottom if history changes
const resizeObsever = new ResizeObserver(() => {
// TODO: Only scroll to bottom if user scrolled to bottom before
vueCommandHistoryRef.value.scrollTop = vueCommandHistoryRef.value.scrollHeight
})
for (const vueCommandHistoryEntry of vueCommandHistoryRef.value.children) {
resizeObsever.observe(vueCommandHistoryEntry)
resizeObserver.observe(vueCommandHistoryEntry)
}
// If history changes, unobserve all history entries and observe again
watch(local.history, async () => {
await nextTick()

resizeObsever.disconnect()
resizeObserver.disconnect()
for (const vueCommandHistoryEntry of vueCommandHistoryRef.value.children) {
resizeObsever.observe(vueCommandHistoryEntry)
resizeObserver.observe(vueCommandHistoryEntry)
}
})
})
Expand Down