From 63642d3921fa3ac12af7f97e7f92da3e11a2ee54 Mon Sep 17 00:00:00 2001 From: He Linming Date: Sun, 29 Nov 2020 23:33:38 +0800 Subject: [PATCH] fix: typewriter shake after press enter (#1852) --- src/muya/lib/selection/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/muya/lib/selection/index.js b/src/muya/lib/selection/index.js index 0e0ef218..cb8fcb43 100644 --- a/src/muya/lib/selection/index.js +++ b/src/muya/lib/selection/index.js @@ -618,10 +618,13 @@ class Selection { if (range.getClientRects) { // range.collapse(true) let rects = range.getClientRects() - if (rects.length === 0) { - rects = range.startContainer && range.startContainer.nodeType === Node.ELEMENT_NODE - ? range.startContainer.getClientRects() - : [] + if (rects.length === 0 && range.startContainer && (range.startContainer.nodeType === Node.ELEMENT_NODE || range.startContainer.nodeType === Node.TEXT_NODE)) { + rects = range.startContainer.parentElement.getClientRects() + // prevent tiny vibrations + if (rects.length) { + const rect = rects[0] + rect.y = rect.y + 1 + } } if (rects.length) { const { left, top, x: rectX, y: rectY, width: rWidth } = rects[0]