mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-07 16:56:40 +08:00
fix(editor): unify Ace editor padding
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { configureAceEditorPadding } from '@/utils/aceEditor'
|
||||||
|
|
||||||
// 国际化
|
// 国际化
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -84,6 +85,7 @@ function submitCustomCSS() {
|
|||||||
:options="editorOptions"
|
:options="editorOptions"
|
||||||
wrap
|
wrap
|
||||||
class="custom-css-editor"
|
class="custom-css-editor"
|
||||||
|
@init="configureAceEditorPadding"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<VCardActions class="app-dialog-actions custom-css-actions">
|
<VCardActions class="app-dialog-actions custom-css-actions">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { configureAceEditorPadding } from '@/utils/aceEditor'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const display = useDisplay()
|
const display = useDisplay()
|
||||||
@@ -90,6 +91,7 @@ function submitTemplate() {
|
|||||||
:options="editorOptions"
|
:options="editorOptions"
|
||||||
wrap
|
wrap
|
||||||
class="template-ace-editor"
|
class="template-ace-editor"
|
||||||
|
@init="configureAceEditorPadding"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<VCardActions class="app-dialog-actions template-editor-actions">
|
<VCardActions class="app-dialog-actions template-editor-actions">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
|
import { configureAceEditorPadding } from '@/utils/aceEditor'
|
||||||
|
|
||||||
// 显示器宽度
|
// 显示器宽度
|
||||||
const display = useDisplay()
|
const display = useDisplay()
|
||||||
@@ -84,6 +85,7 @@ async function handleReset() {
|
|||||||
lang="ini"
|
lang="ini"
|
||||||
theme="monokai"
|
theme="monokai"
|
||||||
class="rounded h-full min-h-[30rem]"
|
class="rounded h-full min-h-[30rem]"
|
||||||
|
@init="configureAceEditorPadding"
|
||||||
>
|
>
|
||||||
</VAceEditor>
|
</VAceEditor>
|
||||||
</VCol>
|
</VCol>
|
||||||
|
|||||||
@@ -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)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import { useTheme } from 'vuetify'
|
|||||||
import { storageAttributes } from '@/api/constants'
|
import { storageAttributes } from '@/api/constants'
|
||||||
import { useSilentSettingRefresh } from '@/composables/useSilentSettingRefresh'
|
import { useSilentSettingRefresh } from '@/composables/useSilentSettingRefresh'
|
||||||
import { openSharedDialog } from '@/composables/useSharedDialog'
|
import { openSharedDialog } from '@/composables/useSharedDialog'
|
||||||
import type { Ace } from 'ace-builds'
|
import { configureAceEditorPadding } from '@/utils/aceEditor'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { global: globalTheme } = useTheme()
|
const { global: globalTheme } = useTheme()
|
||||||
@@ -77,12 +77,6 @@ const renameEditorOptions = {
|
|||||||
showGutter: true,
|
showGutter: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ace 的文本层为绝对定位,容器 padding 不会作用于内容,这里通过 renderer 补齐内边距。
|
|
||||||
function handleRenameEditorInit(editor: Ace.Editor) {
|
|
||||||
editor.renderer.setPadding(12)
|
|
||||||
editor.renderer.setScrollMargin(8, 8, 0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打开共享分类编辑弹窗,保存后刷新本页分类配置。
|
// 打开共享分类编辑弹窗,保存后刷新本页分类配置。
|
||||||
function openCategoryDialog() {
|
function openCategoryDialog() {
|
||||||
openSharedDialog(
|
openSharedDialog(
|
||||||
@@ -417,7 +411,7 @@ useSilentSettingRefresh(loadPageData, {
|
|||||||
:max-lines="12"
|
:max-lines="12"
|
||||||
wrap
|
wrap
|
||||||
class="rename-format-editor__ace"
|
class="rename-format-editor__ace"
|
||||||
@init="handleRenameEditorInit"
|
@init="configureAceEditorPadding"
|
||||||
/>
|
/>
|
||||||
<div class="rename-format-editor__hint">
|
<div class="rename-format-editor__hint">
|
||||||
{{ t('setting.directory.movieRenameFormatHint') }}
|
{{ t('setting.directory.movieRenameFormatHint') }}
|
||||||
@@ -440,7 +434,7 @@ useSilentSettingRefresh(loadPageData, {
|
|||||||
:max-lines="12"
|
:max-lines="12"
|
||||||
wrap
|
wrap
|
||||||
class="rename-format-editor__ace"
|
class="rename-format-editor__ace"
|
||||||
@init="handleRenameEditorInit"
|
@init="configureAceEditorPadding"
|
||||||
/>
|
/>
|
||||||
<div class="rename-format-editor__hint">
|
<div class="rename-format-editor__hint">
|
||||||
{{ t('setting.directory.tvRenameFormatHint') }}
|
{{ t('setting.directory.tvRenameFormatHint') }}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useToast } from 'vue-toastification'
|
|||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useTheme } from 'vuetify'
|
import { useTheme } from 'vuetify'
|
||||||
|
import { configureAceEditorPadding } from '@/utils/aceEditor'
|
||||||
|
|
||||||
const Draggable = defineAsyncComponent(() => import('vuedraggable').then(module => module.default))
|
const Draggable = defineAsyncComponent(() => import('vuedraggable').then(module => module.default))
|
||||||
|
|
||||||
@@ -534,6 +535,7 @@ onMounted(() => {
|
|||||||
:print-margin="false"
|
:print-margin="false"
|
||||||
wrap
|
wrap
|
||||||
class="words-text-editor"
|
class="words-text-editor"
|
||||||
|
@init="configureAceEditorPadding"
|
||||||
/>
|
/>
|
||||||
<VTextarea
|
<VTextarea
|
||||||
v-else
|
v-else
|
||||||
@@ -671,12 +673,7 @@ onMounted(() => {
|
|||||||
>
|
>
|
||||||
{{ t('common.reset') }}
|
{{ t('common.reset') }}
|
||||||
</VBtn>
|
</VBtn>
|
||||||
<VBtn
|
<VBtn color="primary" :loading="saving" prepend-icon="mdi-content-save" @click="saveActiveSection">
|
||||||
color="primary"
|
|
||||||
:loading="saving"
|
|
||||||
prepend-icon="mdi-content-save"
|
|
||||||
@click="saveActiveSection"
|
|
||||||
>
|
|
||||||
{{ t('setting.words.saveChanges') }}
|
{{ t('setting.words.saveChanges') }}
|
||||||
</VBtn>
|
</VBtn>
|
||||||
</div>
|
</div>
|
||||||
@@ -1329,6 +1326,5 @@ onMounted(() => {
|
|||||||
.words-editor-footer {
|
.words-editor-footer {
|
||||||
padding-inline: 1rem;
|
padding-inline: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user