feat: add editor ordered list completion setting

This commit is contained in:
purocean
2021-12-30 13:17:33 +08:00
parent b91f7cdb7d
commit 0ca201b201
5 changed files with 29 additions and 4 deletions
+15 -3
View File
@@ -4,6 +4,7 @@ import type * as Monaco from 'monaco-editor'
import { deleteLine, getEditor, getLineContent, getMonaco, getOneIndent, getValue, insert, replaceLine, whenEditorReady } from '@fe/services/editor'
import type { Plugin } from '@fe/context'
import { t } from '@fe/services/i18n'
import { getSetting } from '@fe/services/setting'
import { isKeydown } from '@fe/core/command'
import emoji from '@fe/others/emoji.json'
@@ -134,6 +135,8 @@ function processCursorChange (source: string, position: Monaco.Position) {
return
}
const orderedListCompletion = getSetting('editor.ordered-list-completion', 'auto')
const content = getLineContent(line)
const prevContent = getLineContent(line - 1)
@@ -142,10 +145,19 @@ function processCursorChange (source: string, position: Monaco.Position) {
const match = prevContent.match(reg)
if (match && reg.test(content)) {
const num = isTab ? 0 : parseInt(match[0] || '0')
let newNum = num
if (orderedListCompletion === 'increase') {
newNum = num + 1
} else if (orderedListCompletion === 'one') {
newNum = 1
} else {
if (num > 1 || isTab) {
newNum = num + 1
}
}
// only increase above 1
if (num > 1 || isTab) {
replaceLine(line, content.replace(/\d+\./, `${num + 1}.`))
if (num !== newNum) {
replaceLine(line, content.replace(/\d+\./, `${newNum}.`))
}
}
}
+11 -1
View File
@@ -117,6 +117,16 @@ const schema: Schema = {
enum: [2, 4],
group: 'editor',
},
'editor.ordered-list-completion': {
defaultValue: 'auto',
title: 'T_setting-panel.schema.editor.ordered-list-completion',
type: 'string',
enum: ['auto', 'increase', 'one'],
options: {
enum_titles: ['Auto', '1. ···, 2. ···, 3. ···', '1. ···, 1. ···, 1. ···'],
},
group: 'editor',
},
'editor.font-size': {
defaultValue: 16,
title: 'T_setting-panel.schema.editor.font-size',
@@ -133,7 +143,7 @@ const schema: Schema = {
group: 'other',
},
} as Partial<Schema['properties']> as any,
required: ['theme', 'language', 'custom-css', 'editor.mouse-wheel-zoom', 'editor.tab-size'],
required: ['theme', 'language', 'custom-css', 'editor.mouse-wheel-zoom', 'editor.tab-size', 'editor.ordered-list-completion'],
}
const settings = {
+1
View File
@@ -104,6 +104,7 @@ export type BuildInSettings = {
'editor.mouse-wheel-zoom': boolean,
'editor.font-size': number,
'editor.tab-size': 2 | 4,
'editor.ordered-list-completion': 'auto' | 'increase' | 'one',
'plugin.image-hosting-picgo.server-url': string,
'plugin.image-hosting-picgo.enable-paste-image': boolean,
'license': string,
+1
View File
@@ -319,6 +319,7 @@ const data = {
'mouse-wheel-zoom': 'Mouse Wheel Zoom',
'font-size': 'Font Size',
'tab-size': 'Tab Size',
'ordered-list-completion': 'Ordered List',
},
'theme': 'Theme',
'language': 'Language',
+1
View File
@@ -314,6 +314,7 @@ const data: BaseLanguage = {
'mouse-wheel-zoom': '鼠标滚动缩放',
'font-size': '字体大小',
'tab-size': 'Tab 宽度',
'ordered-list-completion': '有序列表补全',
},
'theme': '主题',
'language': '语言',