diff --git a/src/core.js b/src/core.js index dbc5198..b79423e 100644 --- a/src/core.js +++ b/src/core.js @@ -351,11 +351,15 @@ class MarkdownEditor { ta.addEventListener('keyup', onCursorActivity); const onScroll = () => { - // 同步行号滚动 - if (this.gutter) this.gutter.scrollTop = ta.scrollTop; + // 同步行号滚动(始终同步,不限于分屏模式) + if (this.gutter) { + this.gutter.scrollTop = ta.scrollTop; + } + // 同步预览滚动(仅分屏模式) if (!this.config.syncScroll || this._mode !== 'split') return; const max = ta.scrollHeight - ta.clientHeight; - const ratio = max > 0 ? ta.scrollTop / max : 0; + if (max <= 0) return; + const ratio = ta.scrollTop / max; const pmax = this.previewPane.scrollHeight - this.previewPane.clientHeight; this.previewPane.scrollTop = ratio * pmax; }; @@ -870,6 +874,8 @@ class MarkdownEditor { this._render(); this._renderGutter(); this._updateWordCount(); + // 同步行号滚动位置 + if (this.gutter) this.gutter.scrollTop = this.textarea.scrollTop; this._emit('change', this._value); if (typeof this.config.onChange === 'function') { try { this.config.onChange(this._value, this); } catch (e) { console.error(e); } diff --git a/src/styles.js b/src/styles.js index 9c3eac1..bba7b6c 100644 --- a/src/styles.js +++ b/src/styles.js @@ -140,7 +140,7 @@ const generateCSS = () => { border-right: 1px solid var(--md-border); color: var(--md-muted); font-family: var(--md-mono); - font-size: 12px; + font-size: 13.5px; line-height: 1.7; text-align: right; user-select: none;