From 58343218319bed2d0cbd9eeb0ce12527139a6235 Mon Sep 17 00:00:00 2001 From: Jiuqing Song Date: Thu, 30 May 2019 14:38:54 -0700 Subject: [PATCH] Fix cursor stuck at list issue (#303) * Fix cursor stuck at list issue * fix build --- .../lib/selection/isPositionAtBeginningOf.ts | 3 ++- .../lib/test/selections/isPositionAtBeginningOfTest.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/roosterjs-editor-dom/lib/selection/isPositionAtBeginningOf.ts b/packages/roosterjs-editor-dom/lib/selection/isPositionAtBeginningOf.ts index 79760e652f8..b3fdc880cfe 100644 --- a/packages/roosterjs-editor-dom/lib/selection/isPositionAtBeginningOf.ts +++ b/packages/roosterjs-editor-dom/lib/selection/isPositionAtBeginningOf.ts @@ -1,4 +1,5 @@ import contains from '../utils/contains'; +import getTagOfNode from '../utils/getTagOfNode'; import isNodeEmpty from '../utils/isNodeEmpty'; import { NodePosition } from 'roosterjs-editor-types'; @@ -27,7 +28,7 @@ export default function isPositionAtBeginningOf(position: NodePosition, targetNo function areAllPrevousNodesEmpty(node: Node): boolean { while (node.previousSibling) { node = node.previousSibling; - if (!isNodeEmpty(node)) { + if (getTagOfNode(node) == 'BR' || !isNodeEmpty(node)) { return false; } } diff --git a/packages/roosterjs-editor-dom/lib/test/selections/isPositionAtBeginningOfTest.ts b/packages/roosterjs-editor-dom/lib/test/selections/isPositionAtBeginningOfTest.ts index cd032a8effa..43c6f4b9c94 100644 --- a/packages/roosterjs-editor-dom/lib/test/selections/isPositionAtBeginningOfTest.ts +++ b/packages/roosterjs-editor-dom/lib/test/selections/isPositionAtBeginningOfTest.ts @@ -111,6 +111,16 @@ describe('isPositionAtBeginningOf()', () => { true ); }); + + it('There is a BR before the position', () => { + runTest( + '

', + () => $('span1'), + 0, + () => $('id1'), + false + ); + }); }); function $(id: string) {