diff --git a/src/app/globals.css b/src/app/globals.css index 55cf24d..6a04c30 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -684,4 +684,14 @@ /* 暗黑模式下的加载动画 */ .dark .animate-spin { color: hsl(var(--primary)); +} + +@layer utilities { + .scrollbar-none { + scrollbar-width: none; + -ms-overflow-style: none; + } + .scrollbar-none::-webkit-scrollbar { + display: none; + } } \ No newline at end of file diff --git a/src/components/editor/WechatEditor.tsx b/src/components/editor/WechatEditor.tsx index b798310..96b5be0 100644 --- a/src/components/editor/WechatEditor.tsx +++ b/src/components/editor/WechatEditor.tsx @@ -393,8 +393,10 @@ export default function WechatEditor() { setReadingTime(calculateReadingTime(plainText)) }, [previewContent]) + const isScrolling = useRef(false) + return ( -
+
t.id === selectedTemplate)?.styles )} > @@ -450,9 +452,26 @@ export default function WechatEditor() { value={value} onChange={handleInput} onKeyDown={handleKeyDown} - className="w-full h-full resize-none outline-none p-4 font-mono text-base leading-relaxed" + className="w-full h-full resize-none outline-none p-4 font-mono text-base leading-relaxed overflow-y-scroll scrollbar-none" placeholder="开始写作..." spellCheck={false} + onScroll={(e) => { + if (isScrolling.current) return + isScrolling.current = true + try { + const textarea = e.currentTarget + const previewContainer = document.querySelector('.preview-container .overflow-y-auto') + if (!previewContainer) return + + const scrollPercentage = textarea.scrollTop / (textarea.scrollHeight - textarea.clientHeight) + const previewScrollTop = scrollPercentage * (previewContainer.scrollHeight - previewContainer.clientHeight) + previewContainer.scrollTop = previewScrollTop + } finally { + requestAnimationFrame(() => { + isScrolling.current = false + }) + } + }} />
@@ -476,7 +495,7 @@ export default function WechatEditor() {
-
+