use-codemirror-content-height.ts 588 B

123456789101112
  1. import { EditorView } from '@codemirror/view'
  2. import useCodeMirrorMeasurement from './use-codemirror-measurement'
  3. // view.contentHeight, which is measured for us by CodeMirror and is what the
  4. // gutters use, is sometimes a pixel or so short of the full height of the
  5. // editor content, which leaves a small gap at the bottom, so use the DOM
  6. // scrollHeight property instead.
  7. const measureContentHeight = (view: EditorView) => view.contentDOM.scrollHeight
  8. export default function useCodeMirrorContentHeight() {
  9. return useCodeMirrorMeasurement('content-height', measureContentHeight)
  10. }