Skip to content

Commit

Permalink
feat: #743 增加联想、全角符号提示的配置能力
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Apr 14, 2024
1 parent 92987ab commit 5f43a52
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/scripts/index-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var basicConfig = {
syntax: {
codeBlock: {
theme: 'twilight',
lineNumber: true, // 默认显示行号
},
table: {
enableChart: false,
Expand Down Expand Up @@ -218,6 +219,8 @@ var basicConfig = {
name: 'cherry-text',
autoSave2Textarea: true,
defaultModel: 'edit&preview',
showFullWidthMark: true, // 是否高亮全角符号 ·|¥|、|:|“|”|【|】|(|)|《|》
showSuggestList: true, // 是否显示联想框
},
// cherry初始化后是否检查 location.hash 尝试滚动到对应位置
autoScrollByHashAfterInit: true,
Expand Down
2 changes: 2 additions & 0 deletions src/Cherry.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ const defaultConfig = {
},
writingStyle: 'normal', // 书写风格,normal 普通 | typewriter 打字机 | focus 专注,默认normal
keepDocumentScrollAfterInit: false, // 在初始化后是否保持网页的滚动,true:保持滚动;false:网页自动滚动到cherry初始化的位置
showFullWidthMark: true, // 是否高亮全角符号 ·|¥|、|:|“|”|【|】|(|)|《|》
showSuggestList: true, // 是否显示联想框
},
toolbars: {
theme: 'dark', // light or dark
Expand Down
5 changes: 5 additions & 0 deletions src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export default class Editor {
wrapperDom: null,
autoScrollByCursor: true,
convertWhenPaste: true,
showFullWidthMark: true,
showSuggestList: true,
codemirror: {
lineNumbers: false, // 显示行数
cursorHeight: 0.85, // 光标高度,0.85好看一些
Expand Down Expand Up @@ -163,6 +165,9 @@ export default class Editor {
* full width翻译为全角
*/
formatFullWidthMark() {
if (!this.options.showFullWidthMark) {
return;
}
const { editor } = this;
const regex = /[·¥、:“”【】()《》]/; // 此处以仅匹配单个全角符号
const searcher = editor.getSearchCursor(regex);
Expand Down
3 changes: 3 additions & 0 deletions src/core/hooks/Suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ class SuggesterPanel {
}

bindEvent() {
if (!this.editor.options.showSuggestList) {
return;
}
let keyAction = false;
this.editor.editor.on('change', (codemirror, evt) => {
keyAction = true;
Expand Down
4 changes: 4 additions & 0 deletions types/cherry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export interface CherryEditorOptions {
editor?: CodeMirror.Editor;
/** 在初始化后是否保持网页的滚动,true:保持滚动;false:网页自动滚动到cherry初始化的位置 */
keepDocumentScrollAfterInit?: boolean;
/** 是否高亮全角符号 ·|¥|、|:|“|”|【|】|(|)|《|》 */
showFullWidthMark?: boolean;
/** 是否显示联想框 */
showSuggestList?: boolean;
}

export type CherryLifecycle = (text: string, html: string) => void;
Expand Down
4 changes: 4 additions & 0 deletions types/editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export type EditorConfiguration = {
value?: string;
convertWhenPaste?: boolean;
keepDocumentScrollAfterInit?: boolean;
/** 是否高亮全角符号 ·|¥|、|:|“|”|【|】|(|)|《|》 */
showFullWidthMark?: boolean;
/** 是否显示联想框 */
showSuggestList?: boolean;
codemirror: CodeMirror.EditorConfiguration;
onKeydown: EditorEventCallback<EditorEventMap['onKeydown']>;
onFocus: EditorEventCallback<EditorEventMap['onFocus']>;
Expand Down

0 comments on commit 5f43a52

Please sign in to comment.