mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 18:55:19 -04:00
Fix smooth scroll and other bugs (#1861)
This PR fixes: - The wrong clean up of window post message communicators - The smooth scroll bug in chrome (Fixes Anchor navigation in render view not working #1770) - Scroll by using touch devices in renderer - Lazy loading of the editor (code mirror doesn't need to be lazy loaded any more)
This commit is contained in:
parent
0f3f7a82b5
commit
8b4e9191e5
15 changed files with 260 additions and 213 deletions
|
@ -5,12 +5,12 @@
|
|||
*/
|
||||
|
||||
import type { RefObject } from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { useMemo, useRef } from 'react'
|
||||
import { updateCursorPositions } from '../../../../redux/note-details/methods'
|
||||
import type { ViewUpdate } from '@codemirror/view'
|
||||
import { EditorView } from '@codemirror/view'
|
||||
import { Logger } from '../../../../utils/logger'
|
||||
import type { Extension } from '@codemirror/state'
|
||||
import type { Extension, SelectionRange } from '@codemirror/state'
|
||||
|
||||
const logger = new Logger('useCursorActivityCallback')
|
||||
|
||||
|
@ -20,14 +20,20 @@ const logger = new Logger('useCursorActivityCallback')
|
|||
* @return the generated callback
|
||||
*/
|
||||
export const useCursorActivityCallback = (editorFocused: RefObject<boolean>): Extension => {
|
||||
const lastMainSelection = useRef<SelectionRange>()
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
EditorView.updateListener.of((viewUpdate: ViewUpdate): void => {
|
||||
const firstSelection = viewUpdate.state.selection.main
|
||||
if (lastMainSelection.current === firstSelection) {
|
||||
return
|
||||
}
|
||||
lastMainSelection.current = firstSelection
|
||||
if (!editorFocused.current) {
|
||||
logger.debug("Don't post updated cursor because editor isn't focused")
|
||||
return
|
||||
}
|
||||
const firstSelection = viewUpdate.state.selection.main
|
||||
const newCursorPos = {
|
||||
from: firstSelection.from,
|
||||
to: firstSelection.to === firstSelection.from ? undefined : firstSelection.to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue