Skip to content

Commit

Permalink
fix: 清歌输入法占位导致的定位出错 (#94)
Browse files Browse the repository at this point in the history
* fix: 清歌占位导致定位出错
  • Loading branch information
colmugx authored May 15, 2020
1 parent c0ea46a commit 2deab6d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/defaultEditorOptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials'
import Autosave from '@ckeditor/ckeditor5-autosave/src/autosave'
import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat'
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder'

import Heading from '@ckeditor/ckeditor5-heading/src/heading'
Expand Down Expand Up @@ -30,6 +29,7 @@ import Table from '@ckeditor/ckeditor5-table/src/table'
import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar'

// 本地插件
import Autoformat from './plugin/Autoformat'
import FullScreen from './plugin/FullScreen'
import ExtraFormat from './plugin/ExtraFormat'
import RemoveFormat from './plugin/RemoveFormat'
Expand Down
56 changes: 56 additions & 0 deletions src/plugin/Autoformat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat'
import BlockAutoformatEditing from '@ckeditor/ckeditor5-autoformat/src/blockautoformatediting'

export default class TheAutoformat extends Autoformat {
_addListAutoformats() {
const commands = this.editor.commands

if (commands.get('bulletedList')) {
// eslint-disable-next-line no-new
new BlockAutoformatEditing(
this.editor,
/^[*-]\s/,
this._composeListener('bulletedList')
)
}

if (commands.get('numberedList')) {
// eslint-disable-next-line no-new
new BlockAutoformatEditing(
this.editor,
/^1\.\s/,
this._composeListener('numberedList')
)
}
}

_addHeadingAutoformats() {
const command = this.editor.commands.get('heading')

if (command) {
command.modelElements
.filter(name => name.match(/^heading[1-6]$/))
.forEach(commandValue => {
const level = commandValue[7]
const pattern = new RegExp(`^(#{${level}})\\s`)

// eslint-disable-next-line no-new
new BlockAutoformatEditing(this.editor, pattern, () => {
if (!command.isEnabled) {
return false
}

this.editor.execute('heading', {value: commandValue})
})
})
}
}

_composeListener(command) {
return () => {
const isComposing = this.editor.editing.view.document.isComposing
if (isComposing) return false
return this.editor.execute(command)
}
}
}
14 changes: 13 additions & 1 deletion src/plugin/ExtraFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export default class ExtraFormat extends Plugin {
const commands = this.editor.commands

if (commands.get('todoList')) {
new BlockAutoformatEditing(this.editor, /^\[\]\s$/, 'todoList')
new BlockAutoformatEditing(
this.editor,
/^\[\]\s/,
this._composeListener('todolist')
)
}
}

Expand Down Expand Up @@ -70,4 +74,12 @@ export default class ExtraFormat extends Plugin {
})
})
}

_composeListener(command) {
return () => {
const isComposing = this.editor.editing.view.document.isComposing
if (isComposing) return false
return this.editor.execute(command)
}
}
}
2 changes: 1 addition & 1 deletion src/v-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default {
ol,
ul {
padding-left: 1em;
padding-left: 1.5em;
}
// 不要影响 ul 的列表项
Expand Down

0 comments on commit 2deab6d

Please sign in to comment.