fix(editor): unify Ace editor padding

This commit is contained in:
jxxghp
2026-07-29 13:48:12 +08:00
parent 9ef45918b8
commit 01e7dcee56
7 changed files with 44 additions and 16 deletions
+17
View File
@@ -0,0 +1,17 @@
import { configureAceEditorPadding } from '@/utils/aceEditor'
import { describe, expect, it, vi } from 'vitest'
describe('Ace editor configuration', () => {
it('applies the shared content padding and scroll margin', () => {
const setPadding = vi.fn()
const setScrollMargin = vi.fn()
const editor = {
renderer: { setPadding, setScrollMargin },
} as unknown as Parameters<typeof configureAceEditorPadding>[0]
configureAceEditorPadding(editor)
expect(setPadding).toHaveBeenCalledWith(12)
expect(setScrollMargin).toHaveBeenCalledWith(8, 8, 0, 0)
})
})
+15
View File
@@ -0,0 +1,15 @@
import type { Ace } from 'ace-builds'
const ACE_EDITOR_PADDING = 12
const ACE_EDITOR_SCROLL_MARGIN = { bottom: 8, left: 0, right: 0, top: 8 }
/** 让所有 Ace 编辑器的文本内容与普通输入框保持一致的内边距和滚动留白。 */
export function configureAceEditorPadding(editor: Ace.Editor) {
editor.renderer.setPadding(ACE_EDITOR_PADDING)
editor.renderer.setScrollMargin(
ACE_EDITOR_SCROLL_MARGIN.top,
ACE_EDITOR_SCROLL_MARGIN.bottom,
ACE_EDITOR_SCROLL_MARGIN.left,
ACE_EDITOR_SCROLL_MARGIN.right,
)
}