From 9e2a833b97e9e1b6b45beafa909e1c7559c35c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= Date: Thu, 12 Dec 2024 12:10:49 +0100 Subject: [PATCH] Add range sortiing in web parser --- src/__tests__/parseExpensiMark.test.ts | 2 +- src/__tests__/webParser.test.tsx | 2 +- src/index.tsx | 2 +- src/parseExpensiMark.ts | 2 +- src/web/utils/parserUtils.ts | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/__tests__/parseExpensiMark.test.ts b/src/__tests__/parseExpensiMark.test.ts index b49f46fa3..260ae422f 100644 --- a/src/__tests__/parseExpensiMark.test.ts +++ b/src/__tests__/parseExpensiMark.test.ts @@ -1,6 +1,6 @@ import {expect} from '@jest/globals'; import type {MarkdownRange} from '../commonTypes'; -import parseExpensiMark from '../parseExpensiMark'; +import {parseExpensiMark} from '../parseExpensiMark'; declare module 'expect' { interface Matchers { diff --git a/src/__tests__/webParser.test.tsx b/src/__tests__/webParser.test.tsx index 8fcd31400..4a9a94994 100644 --- a/src/__tests__/webParser.test.tsx +++ b/src/__tests__/webParser.test.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import {expect} from '@jest/globals'; import {parseRangesToHTMLNodes} from '../web/utils/parserUtils'; -import parseExpensiMark from '../parseExpensiMark'; +import {parseExpensiMark} from '../parseExpensiMark'; declare module 'expect' { interface Matchers { diff --git a/src/index.tsx b/src/index.tsx index 4f3b1d607..b57e2b975 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,4 @@ export {default as MarkdownTextInput} from './MarkdownTextInput'; export type {MarkdownTextInputProps, MarkdownStyle} from './MarkdownTextInput'; export type {MarkdownType, MarkdownRange} from './commonTypes'; -export {default as parseExpensiMark} from './parseExpensiMark'; +export {parseExpensiMark} from './parseExpensiMark'; diff --git a/src/parseExpensiMark.ts b/src/parseExpensiMark.ts index 673734af7..1d8e64f0e 100644 --- a/src/parseExpensiMark.ts +++ b/src/parseExpensiMark.ts @@ -292,4 +292,4 @@ function parseExpensiMark(markdown: string): MarkdownRange[] { return groupedRanges; } -export default parseExpensiMark; +export {parseExpensiMark, sortRanges}; diff --git a/src/web/utils/parserUtils.ts b/src/web/utils/parserUtils.ts index 419ed780e..36a73f146 100644 --- a/src/web/utils/parserUtils.ts +++ b/src/web/utils/parserUtils.ts @@ -6,6 +6,7 @@ import {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition} from './cu import {addStyleToBlock, extendBlockStructure, getFirstBlockMarkdownRange, isBlockMarkdownType} from './blockUtils'; import type {InlineImagesInputProps, MarkdownRange} from '../../commonTypes'; import {getAnimationCurrentTimes, updateAnimationsTime} from './animationUtils'; +import {sortRanges} from '../../parseExpensiMark'; type Paragraph = { text: string; @@ -167,7 +168,8 @@ function parseRangesToHTMLNodes( return {dom: rootElement, tree: rootNode}; } - const markdownRanges = ungroupRanges(ranges); + const sortedRanges = sortRanges(ranges); + const markdownRanges = ungroupRanges(sortedRanges); lines = mergeLinesWithMultilineTags(lines, markdownRanges); let lastRangeEndIndex = 0;