Skip to content

Commit 2508bcb

Browse files
committed
fix: Blinking in editor
1 parent cf90f8a commit 2508bcb

File tree

7 files changed

+15
-27
lines changed

7 files changed

+15
-27
lines changed

packages/markdown-editor/css/styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ input[type='search'] {
164164
font-family: initial;
165165
}
166166

167+
.markdown-editor-codemirror {
168+
transition: none;
169+
will-change: auto;
170+
}
171+
167172
@keyframes nextra-fadein {
168173
0% {
169174
opacity: 0;

packages/markdown-editor/src/components/markdown-editor/hooks/useCodemirror.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getDefaultExtensions } from './../lib/getDefaultExtensions'
2-
import { Annotation, EditorState, Extension, StateEffect } from '@codemirror/state'
2+
import { Annotation, EditorState, Extension } from '@codemirror/state'
33
import { EditorView, ViewUpdate } from '@codemirror/view'
44
import { useTheme } from 'next-themes'
55
import { RefObject, useEffect, useState } from 'react'
@@ -150,7 +150,7 @@ export const useCodemirror = (container: RefObject<HTMLDivElement>, config: Conf
150150

151151
useEffect(() => {
152152
if (!view) return
153-
view.dispatch({ effects: StateEffect.reconfigure.of(extenstions) })
153+
// view.dispatch({ effects: StateEffect.reconfigure.of(extenstions) })
154154
}, [container, config, extenstions])
155155

156156
useEffect(() => {

packages/markdown-editor/src/components/markdown-editor/lib/getDefaultExtensions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export const getDefaultExtensions = (options: ExtensionOptions) => {
9191
{ tag: tags.heading4, class: 'cm-heading4' },
9292
{ tag: tags.heading5, class: 'cm-heading5' },
9393
])
94-
9594
getExtensions.push(syntaxHighlighting(headHighlightStyle))
9695
}
9796

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import cn from 'clsx'
22

3-
const ToolbarSeparator = () => {
3+
export const ToolbarSeparator = () => {
44
return <div className={cn('nx-w- items-center nx-flex nx-w-1.5 nx-justify-center')}>|</div>
55
}
6-
7-
export default ToolbarSeparator

packages/markdown-editor/src/components/markdown-editor/toolbar/toolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import cn from 'clsx'
2-
import { isValidElement, RefObject, useEffect, useState } from 'react'
2+
import { isValidElement, useEffect, useState } from 'react'
33
import { titles, bold, italic, strike, quote, link, image, code, save } from './commands'
44
import { ToolbarCommand } from './commands/type'
55
import { EditorSelection, EditorState } from '@codemirror/state'
66
import { EditorView } from '@codemirror/view'
7-
import ToolbarSeparator from './toolbar-separator'
7+
import { ToolbarSeparator } from './toolbar-separator'
88
import useClickImage from '@/hooks/use-click-img'
99
import { useUpload } from '@/hooks/use-upload'
1010

packages/markdown-editor/src/layouts/main.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,10 @@ import { ActiveAnchorProvider } from '@/contexts'
44
import { useFSRoute } from '@/nextra/hooks'
55
import { normalizePages } from '@/nextra/normalize-pages'
66
import type { PageOpts } from '@/nextra/types'
7-
import {
8-
useCallback,
9-
useEffect,
10-
useMemo,
11-
useRef,
12-
useState,
13-
type ReactElement,
14-
type ReactNode,
15-
} from 'react'
7+
import { useCallback, useEffect, useMemo, useRef, type ReactElement, type ReactNode } from 'react'
168
import { Banner, Head, Header, Sidebar } from '@/components'
179
import { MarkdownPreview } from '@/components/markdown-preview'
1810
import { MarkdownEditor } from '@/components/markdown-editor'
19-
import { useMarkdownEditor } from '@/contexts/markdown-editor'
2011
import { ReactCodeMirrorRef } from '@/types'
2112
import * as events from '@uiw/codemirror-extensions-events'
2213

@@ -26,7 +17,6 @@ type MainProps = PageOpts & {
2617

2718
export const Main = ({ frontMatter, headings, pageMap }: MainProps): ReactElement => {
2819
const fsPath = useFSRoute()
29-
const { mdxSource } = useMarkdownEditor()
3020
const editorRef = useRef<ReactCodeMirrorRef>(null)
3121
const previewRef = useRef<HTMLDivElement>(null)
3222
const active = useRef<'editor' | 'preview'>('editor')
@@ -47,13 +37,9 @@ export const Main = ({ frontMatter, headings, pageMap }: MainProps): ReactElemen
4737
const direction = 'ltr'
4838
const mainHeight = 'calc(100vh - (var(--nextra-navbar-height)))'
4939

50-
const previewScrollHandle = useCallback((event: Event) => {
51-
const target = event.target as HTMLDivElement
52-
53-
const percent = target.scrollTop / target.scrollHeight
54-
55-
console.log('percent', percent)
56-
console.log('active.current', active.current)
40+
const previewScrollHandle = useCallback(() => {
41+
// const target = event.target as HTMLDivElement
42+
// const percent = target.scrollTop / target.scrollHeight
5743

5844
if (active.current === 'editor' && previewRef.current) {
5945
const previewHeight = previewRef.current?.scrollHeight || 0

packages/markdown-editor/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)