diff --git a/src/renderer/plugins/editor-markdown.ts b/src/renderer/plugins/editor-markdown.ts index 28a7bd53..1ea467d5 100644 --- a/src/renderer/plugins/editor-markdown.ts +++ b/src/renderer/plugins/editor-markdown.ts @@ -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}.`)) } } } diff --git a/src/renderer/services/setting.ts b/src/renderer/services/setting.ts index 5c789414..c2676415 100644 --- a/src/renderer/services/setting.ts +++ b/src/renderer/services/setting.ts @@ -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 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 = { diff --git a/src/renderer/types.ts b/src/renderer/types.ts index abc0cb1d..aaf190ea 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -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, diff --git a/src/share/i18n/languages/en.ts b/src/share/i18n/languages/en.ts index 7edd8b3f..07bfecf3 100644 --- a/src/share/i18n/languages/en.ts +++ b/src/share/i18n/languages/en.ts @@ -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', diff --git a/src/share/i18n/languages/zh-CN.ts b/src/share/i18n/languages/zh-CN.ts index 3bdbb01c..ce4b0883 100644 --- a/src/share/i18n/languages/zh-CN.ts +++ b/src/share/i18n/languages/zh-CN.ts @@ -314,6 +314,7 @@ const data: BaseLanguage = { 'mouse-wheel-zoom': '鼠标滚动缩放', 'font-size': '字体大小', 'tab-size': 'Tab 宽度', + 'ordered-list-completion': '有序列表补全', }, 'theme': '主题', 'language': '语言',