|
@@ -96,6 +96,7 @@ export const getMarkupWithSelection: GetMarkupWithSelectionFunc = ({
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
// @ts-ignore
|
|
|
const textElements = [...textLayer.childNodes];
|
|
|
+ let inRange = false;
|
|
|
|
|
|
textElements.forEach((ele: HTMLElement) => {
|
|
|
const { offsetTop, offsetLeft, offsetHeight, offsetWidth } = ele;
|
|
@@ -117,36 +118,15 @@ export const getMarkupWithSelection: GetMarkupWithSelectionFunc = ({
|
|
|
// in start element
|
|
|
coords.left = startX;
|
|
|
position.push(coords);
|
|
|
+ inRange = true;
|
|
|
} else if (endElement === ele) {
|
|
|
// in end element
|
|
|
coords.right = endX;
|
|
|
position.push(coords);
|
|
|
- } else if (
|
|
|
- offsetTop >= startY + offsetHeight &&
|
|
|
- offsetBottom <= endY - offsetHeight
|
|
|
- ) {
|
|
|
- // in row
|
|
|
- position.push(coords);
|
|
|
- } else if (
|
|
|
- offsetLeft > startX &&
|
|
|
- offsetRight < endX &&
|
|
|
- offsetTop >= startY &&
|
|
|
- offsetBottom <= endY
|
|
|
- ) {
|
|
|
- // in line
|
|
|
+ inRange = false;
|
|
|
+ } else if (inRange) {
|
|
|
+ // middle element
|
|
|
position.push(coords);
|
|
|
- } else if (offsetTop >= startY - 3 && offsetBottom <= endY + 3) {
|
|
|
- if (
|
|
|
- (offsetLeft > startX &&
|
|
|
- offsetTop >= startY - 3 &&
|
|
|
- offsetBottom < endY - offsetHeight) ||
|
|
|
- (offsetRight < endX &&
|
|
|
- offsetBottom <= endY + 3 &&
|
|
|
- offsetTop > startY + offsetHeight)
|
|
|
- ) {
|
|
|
- // in first line and end line
|
|
|
- position.push(coords);
|
|
|
- }
|
|
|
}
|
|
|
});
|
|
|
|