From f1a9c5ae939e8c56c7c8745a3ceb730bb88fabbd Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Thu, 25 Mar 2021 17:38:34 -0400 Subject: [PATCH] Fix line numbers when missing trailing newline _addLineNumbers expected code blocks to contain a trailing newline, but this is not always the case. Signed-off-by: Robin Townsend --- src/components/views/messages/TextualBody.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index b0eb6f2f35..353f40b6a9 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -216,12 +216,12 @@ export default class TextualBody extends React.Component { } _addLineNumbers(pre) { + // Calculate number of lines in pre + const number = pre.innerHTML.replace(/\n(<\/code>)?$/, "").split(/\n/).length; pre.innerHTML = '' + pre.innerHTML + ''; const lineNumbers = pre.getElementsByClassName("mx_EventTile_lineNumbers")[0]; - // Calculate number of lines in pre - const number = pre.innerHTML.split(/\n/).length; // Iterate through lines starting with 1 (number of the first line is 1) - for (let i = 1; i < number; i++) { + for (let i = 1; i <= number; i++) { lineNumbers.innerHTML += '' + i + ''; } }