From 5f0ef2c8e6423f8a35277a407bf7d40d63bb941f Mon Sep 17 00:00:00 2001 From: Ran Luo Date: Wed, 23 Oct 2019 03:01:40 +0800 Subject: [PATCH] Fix: enter error in code block (#1506) --- src/muya/lib/contentState/enterCtrl.js | 3 ++- src/muya/lib/selection/index.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/muya/lib/contentState/enterCtrl.js b/src/muya/lib/contentState/enterCtrl.js index 2c707aaf..db084aa1 100644 --- a/src/muya/lib/contentState/enterCtrl.js +++ b/src/muya/lib/contentState/enterCtrl.js @@ -242,7 +242,8 @@ const enterCtrl = ContentState => { } return this.partialRender() } else if ( - block.type === 'span' && block.functionType === 'codeContent' + block.type === 'span' && + block.functionType === 'codeContent' ) { const { text, key } = block const autoIndent = checkAutoIndent(text, start.offset) diff --git a/src/muya/lib/selection/index.js b/src/muya/lib/selection/index.js index 0acaf8da..0e0ef218 100644 --- a/src/muya/lib/selection/index.js +++ b/src/muya/lib/selection/index.js @@ -431,8 +431,9 @@ class Selection { if (child.classList && child.classList.contains(CLASS_OR_ID.AG_FRONT_ICON)) { continue } + // Fix #1460 - put the cursor at the next text node or element if it can be put at the last of /^\n$/ or the next text node/element. - if (/^\n$/.test(textContent) ? count + textLength > offset : count + textLength >= offset) { + if (/^\n$/.test(textContent) && i !== len - 1 ? count + textLength > offset : count + textLength >= offset) { if ( child.classList && child.classList.contains('ag-inline-image') ) {