From da000e919ae41eab83ab94e3f7a34dcd8d7d91dd Mon Sep 17 00:00:00 2001 From: Cyril Gromoff Date: Wed, 28 Aug 2024 13:43:08 +0200 Subject: [PATCH] fix issue when a line is selected one by one the numbering was always one --- webapp/channels/src/utils/markdown/apply_markdown.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/webapp/channels/src/utils/markdown/apply_markdown.ts b/webapp/channels/src/utils/markdown/apply_markdown.ts index fa09056dd03..43e7d8f58f8 100644 --- a/webapp/channels/src/utils/markdown/apply_markdown.ts +++ b/webapp/channels/src/utils/markdown/apply_markdown.ts @@ -155,6 +155,16 @@ const applyOlMarkdown = ({selectionEnd, selectionStart, message}: ApplySpecificM newEnd = Math.max(selectionEnd - (delimiterLength * count), 0); } else { let count = 0; + + const getLastNumberedLine = (text: string): number => { + const match = text.match(/(\d+)\.\s/g); + if (match) { + return parseInt(match[match.length - 1], 10); + } + return 0; + }; + getDelimiter.counter = getLastNumberedLine(newPrefix) + 1; + if (isFirstLineSelected) { multilineSelection = getDelimiter() + multilineSelection; count++;