mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Replace unload handlers with visibilitychange (#36387)
Co-authored-by: Mathias Jakobsen <mathias.jakobsen@overleaf.com> GitOrigin-RevId: 3b52b09445597d93eb5fdfa5a343fbc2fac14d6c
This commit is contained in:
committed by
Copybot
co-authored by
Mathias Jakobsen
parent
aac9e669a3
commit
8c869db734
@@ -24,16 +24,21 @@ export const cursorPosition = ({
|
||||
return [
|
||||
// store cursor position
|
||||
ViewPlugin.define(view => {
|
||||
const unloadListener = () => {
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.visibilityState === 'hidden') {
|
||||
storeCursorPosition(view, docId)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('unload', unloadListener)
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange)
|
||||
|
||||
return {
|
||||
destroy: () => {
|
||||
window.removeEventListener('unload', unloadListener)
|
||||
unloadListener()
|
||||
document.removeEventListener(
|
||||
'visibilitychange',
|
||||
handleVisibilityChange
|
||||
)
|
||||
storeCursorPosition(view, docId)
|
||||
},
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -51,13 +51,15 @@ export const scrollPosition = (
|
||||
// store/dispatch scroll position
|
||||
ViewPlugin.define(
|
||||
view => {
|
||||
const unloadListener = () => {
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.visibilityState === 'hidden') {
|
||||
if (lineInfo) {
|
||||
storeScrollPosition(lineInfo, view, docId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('unload', unloadListener)
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange)
|
||||
|
||||
return {
|
||||
update: (update: ViewUpdate) => {
|
||||
@@ -82,8 +84,13 @@ export const scrollPosition = (
|
||||
},
|
||||
destroy: () => {
|
||||
scrollHandler.cancel()
|
||||
window.removeEventListener('unload', unloadListener)
|
||||
unloadListener()
|
||||
document.removeEventListener(
|
||||
'visibilitychange',
|
||||
handleVisibilityChange
|
||||
)
|
||||
if (lineInfo) {
|
||||
storeScrollPosition(lineInfo, view, docId)
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user