Skip to content

Commit

Permalink
fix: save window scroll position
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming committed Oct 25, 2024
1 parent 7daeab4 commit 9f6e97c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/fluent-editor/src/fullscreen/handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { FluentEditorToolbar } from '../config/types'
import { namespace } from '../config'
import { lockScroll } from '../utils/scroll-lock'

let exitEscHandlerBindToolbar: (e: KeyboardEvent) => void
let resizeHandlerBindToolbar: () => void
let cleanLock: ReturnType<typeof lockScroll>
let originScrollTop = 0
function exitEscHandler(toolbar: FluentEditorToolbar, e: KeyboardEvent) {
if (e.code === 'Escape') {
exitFullscreen(toolbar)
Expand All @@ -14,9 +17,10 @@ function updateToolbarHeight(toolbar: FluentEditorToolbar) {
}
function intoFullscreen(toolbar: FluentEditorToolbar) {
toolbar.quill.isFullscreen = true
originScrollTop = document.documentElement.scrollTop
toolbar.container.classList.add('fullscreen')
toolbar.quill.container.classList.add('fullscreen')
document.documentElement.classList.add('scroll--lock')
cleanLock = lockScroll()
resizeHandlerBindToolbar()
window.addEventListener('resize', resizeHandlerBindToolbar)
document.addEventListener('keydown', exitEscHandlerBindToolbar)
Expand All @@ -25,7 +29,8 @@ function exitFullscreen(toolbar: FluentEditorToolbar) {
toolbar.quill.isFullscreen = false
toolbar.container.classList.remove('fullscreen')
toolbar.quill.container.classList.remove('fullscreen')
document.documentElement.classList.remove('scroll--lock')
cleanLock()
document.documentElement.scrollTop = originScrollTop
window.removeEventListener('resize', resizeHandlerBindToolbar)
document.removeEventListener('keydown', exitEscHandlerBindToolbar)
}
Expand Down

0 comments on commit 9f6e97c

Please sign in to comment.