mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #28760 from overleaf/dp-hackathon-knip
Add Knip and remove a bunch of unused code GitOrigin-RevId: 42ab99fc65973c883d2361e0027e7181767e714e
This commit is contained in:
-12
@@ -1,12 +0,0 @@
|
||||
import { EditorView } from '@codemirror/view'
|
||||
import useCodeMirrorMeasurement from './use-codemirror-measurement'
|
||||
|
||||
// view.contentHeight, which is measured for us by CodeMirror and is what the
|
||||
// gutters use, is sometimes a pixel or so short of the full height of the
|
||||
// editor content, which leaves a small gap at the bottom, so use the DOM
|
||||
// scrollHeight property instead.
|
||||
const measureContentHeight = (view: EditorView) => view.contentDOM.scrollHeight
|
||||
|
||||
export default function useCodeMirrorContentHeight() {
|
||||
return useCodeMirrorMeasurement('content-height', measureContentHeight)
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useCodeMirrorViewContext } from '../components/codemirror-context'
|
||||
import { EditorView } from '@codemirror/view'
|
||||
import useEventListener from '../../../shared/hooks/use-event-listener'
|
||||
|
||||
export default function useCodeMirrorMeasurement(
|
||||
key: string,
|
||||
measure: (view: EditorView) => number
|
||||
) {
|
||||
const view = useCodeMirrorViewContext()
|
||||
const [measurement, setMeasurement] = useState(() => measure(view))
|
||||
|
||||
useEventListener(
|
||||
'editor:geometry-change',
|
||||
useCallback(() => {
|
||||
view.requestMeasure({
|
||||
key,
|
||||
read: () => measure(view),
|
||||
write(value) {
|
||||
// wrap the React state setter in a timeout so it doesn't run inside the CodeMirror update cycle
|
||||
window.setTimeout(() => {
|
||||
setMeasurement(value)
|
||||
})
|
||||
},
|
||||
})
|
||||
}, [view, measure, key])
|
||||
)
|
||||
|
||||
return measurement
|
||||
}
|
||||
Reference in New Issue
Block a user