Browse Source

fix: 在输入法时屏蔽回车事件

ChenYangfan 6 years ago
parent
commit
5ee8d716be
2 changed files with 16 additions and 17 deletions
  1. 12 9
      src/components/editor/EditableItem.vue
  2. 4 8
      src/store/modules/editor.js

+ 12 - 9
src/components/editor/EditableItem.vue

@@ -48,15 +48,18 @@ export default {
     handleKeyDown(e) {
       switch (e.key) {
         case 'Enter':
-          e.preventDefault()
-          this.$store.commit(ADD_ITEM_AFTER, {
-            pageId: this.pageId,
-            itemId: this.item.id
-          })
-          this.$nextTick(() => {
-            const focusNode = document.getElementById(this.item.id).nextSibling
-            focusNode.focus()
-          })
+          if (!this.isCompositionStarted) {
+            e.preventDefault()
+            this.$store.commit(ADD_ITEM_AFTER, {
+              pageId: this.pageId,
+              itemId: this.item.id
+            })
+            this.$nextTick(() => {
+              const focusNode = document.getElementById(this.item.id)
+                .nextSibling
+              focusNode.focus()
+            })
+          }
           break
 
         case 'Backspace':

+ 4 - 8
src/store/modules/editor.js

@@ -27,11 +27,6 @@ export default {
           type: 'h1',
           placeholder: '未命名文档标题',
           content: ''
-        }, {
-          id: uuid.v4(),
-          type: 'div',
-          placeholder: '未命名小标题',
-          content: ''
         }]
       }]
     },
@@ -49,7 +44,7 @@ export default {
           items: [{
             id: uuid.v4(),
             type: 'h3',
-            placeholder: '未命名副标题',
+            placeholder: '未命名小标题',
             content: ''
           }, ...state.pages.slice(index + 1)]
         }
@@ -69,7 +64,8 @@ export default {
                 ...page.items.slice(0, index + 1), {
                   id: uuid.v4(),
                   type: 'div',
-                  content: ''
+                  content: '',
+                  placeholder: '未编辑正文项'
                 },
                 ...page.items.slice(index + 1)
               ]
@@ -106,7 +102,7 @@ export default {
           if (page.id === payload.pageId) {
             return {
               ...page,
-              items: page.items.filter(item => item.id !== payload.itemId)
+              items: page.items.filter((item, index) => index === 0 || item.id !== payload.itemId)
             }
           } else {
             return page