Skip to content

Commit e4c5ed8

Browse files
committed
feat: 支持自动换行
1 parent 4ed4c7a commit e4c5ed8

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

frontend/package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/LikeDialog.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@
2525
<div class="item">
2626
<div class="label">字体大小</div>
2727
<div class="value">
28-
<el-input-number v-model="like.fontSize" :min="8" :max="100" size="small" />
28+
<el-input-number v-model="like.editorOption.fontSize" :min="8" :max="100" size="small" />
29+
</div>
30+
</div>
31+
32+
<div class="item">
33+
<div class="label">自动换行</div>
34+
<div class="value">
35+
<el-switch
36+
v-model="like.editorOption.wordWrap"
37+
inline-prompt
38+
active-value="on"
39+
inactive-value="off"
40+
/>
2941
</div>
3042
</div>
3143
</div>
@@ -36,7 +48,9 @@
3648

3749
<div style="flex: 1"></div>
3850

39-
<div style="font-size: 12px; color: var(--el-text-color-placeholder)">修改实时生效,且进行缓存</div>
51+
<div style="font-size: 12px; color: var(--el-text-color-placeholder)">
52+
修改实时生效,且进行缓存
53+
</div>
4054
</div>
4155
</template>
4256
</el-dialog>

frontend/src/components/MonacoEditor.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
v-model:value="code.value"
66
:language="code.lang"
77
:theme="like.theme"
8-
:options="{ fontSize: 14, automaticLayout: true }"
8+
:options="{ automaticLayout: true, ...editorLike.editorOption }"
99
@editorDidMount="editorDidMount"
1010
/>
1111
</div>
@@ -78,7 +78,7 @@ const { code, save } = useCode({
7878
onSave: () => $emit('diff', false),
7979
})
8080
81-
const { editorDidMount, changeLang, changeTheme, changeSize } = useEditor({ onSave: save })
81+
const { editorDidMount, changeLang, changeTheme, changeOption } = useEditor({ onSave: save })
8282
8383
const changeEncode = async (v: string) => {
8484
const buffer = await code.blob.arrayBuffer()
@@ -99,16 +99,16 @@ watch(
9999
},
100100
)
101101
watch(
102-
() => $props.like.fontSize,
102+
() => code.value,
103103
(v) => {
104-
editorLike.fontSize = v
105-
changeSize(v)
104+
$emit('diff', v !== code.org)
106105
},
107106
)
108107
watch(
109-
() => code.value,
108+
() => $props.like.editorOption,
110109
(v) => {
111-
$emit('diff', v !== code.org)
110+
editorLike.editorOption = v
111+
changeOption(v)
112112
},
113113
)
114114
</script>

frontend/src/hooks/useEditor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export default function useEditor(option: { onSave: () => void }) {
2424
monaco.editor.setModelLanguage(toRaw(editorInstance.value.getModel()), v)
2525
}
2626

27-
const changeSize = (size: number) => {
28-
editorInstance.value.updateOptions({ fontSize: size })
29-
}
30-
3127
const changeTheme = (v: string) => {
3228
monaco.editor.setTheme(v)
3329
}
3430

31+
const changeOption = (opt: any) => {
32+
editorInstance.value.updateOptions(opt)
33+
}
34+
3535
return {
3636
editorDidMount,
3737
changeLang,
38-
changeSize,
3938
changeTheme,
39+
changeOption,
4040
}
4141
}

frontend/src/hooks/useLike.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ import { THEME_OPTIONS } from '@/utils/option'
55

66
export interface LikeModel {
77
theme: string
8-
fontSize: number
98
confirm: boolean
9+
editorOption: {
10+
fontSize: number
11+
wordWrap: 'off' | 'on'
12+
}
1013
}
1114

1215
const defLike: LikeModel = {
1316
theme: 'vs-dark',
14-
fontSize: 14,
1517
confirm: true,
18+
editorOption: {
19+
fontSize: 14,
20+
wordWrap: 'off',
21+
},
1622
}
1723

1824
const key = 'like_v1'

0 commit comments

Comments
 (0)