Skip to content

Commit

Permalink
Merge branch 'master' into vnext
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Aug 13, 2020
2 parents 20fb6ae + 775a8a0 commit 6e02418
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 165 deletions.
1 change: 1 addition & 0 deletions packages/roosterjs-editor-dom/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export { getNextLeafSibling, getPreviousLeafSibling } from './utils/getLeafSibli
export { getFirstLeafNode, getLastLeafNode } from './utils/getLeafNode';
export { default as getTextContent } from './utils/getTextContent';
export { default as splitTextNode } from './utils/splitTextNode';
export { default as normalizeRect } from './utils/normalizeRect';
export { default as toArray } from './utils/toArray';
export { default as safeInstanceOf } from './utils/safeInstanceOf';
export { default as readFile } from './utils/readFile';
Expand Down
15 changes: 1 addition & 14 deletions packages/roosterjs-editor-dom/lib/selection/getPositionRect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import createRange from './createRange';
import normalizeRect from '../utils/normalizeRect';
import { NodePosition, NodeType, Rect } from 'roosterjs-editor-types';

/**
Expand Down Expand Up @@ -52,17 +53,3 @@ export default function getPositionRect(position: NodePosition): Rect {

return null;
}

function normalizeRect(clientRect: ClientRect): Rect {
// A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p
// We validate that and only return a rect when the passed in ClientRect is valid
let { left, right, top, bottom } = clientRect || <ClientRect>{};
return left + right + top + bottom > 0
? {
left: Math.round(left),
right: Math.round(right),
top: Math.round(top),
bottom: Math.round(bottom),
}
: null;
}
18 changes: 18 additions & 0 deletions packages/roosterjs-editor-dom/lib/utils/normalizeRect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Rect } from 'roosterjs-editor-types';

/**
* A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p
* We validate that and only return a rect when the passed in ClientRect is valid
*/
export default function normalizeRect(clientRect: ClientRect): Rect {
let { left, right, top, bottom } =
clientRect || <ClientRect>{ left: 0, right: 0, top: 0, bottom: 0 };
return left + right + top + bottom > 0
? {
left: Math.round(left),
right: Math.round(right),
top: Math.round(top),
bottom: Math.round(bottom),
}
: null;
}
Loading

0 comments on commit 6e02418

Please sign in to comment.