fix: typewriter shake after press enter (#1852)

This commit is contained in:
He Linming 2020-11-29 23:33:38 +08:00 committed by GitHub
parent dd672d75f1
commit 63642d3921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -618,10 +618,13 @@ class Selection {
if (range.getClientRects) { if (range.getClientRects) {
// range.collapse(true) // range.collapse(true)
let rects = range.getClientRects() let rects = range.getClientRects()
if (rects.length === 0) { if (rects.length === 0 && range.startContainer && (range.startContainer.nodeType === Node.ELEMENT_NODE || range.startContainer.nodeType === Node.TEXT_NODE)) {
rects = range.startContainer && range.startContainer.nodeType === Node.ELEMENT_NODE rects = range.startContainer.parentElement.getClientRects()
? range.startContainer.getClientRects() // prevent tiny vibrations
: [] if (rects.length) {
const rect = rects[0]
rect.y = rect.y + 1
}
} }
if (rects.length) { if (rects.length) {
const { left, top, x: rectX, y: rectY, width: rWidth } = rects[0] const { left, top, x: rectX, y: rectY, width: rWidth } = rects[0]