From 5698c60e76fd29abe097b602617decab4c3c47e5 Mon Sep 17 00:00:00 2001 From: ldeluigi <44567586+ldeluigi@users.noreply.github.com> Date: Wed, 31 Jul 2024 00:46:17 +0200 Subject: [PATCH] Fix #494 --- .../admin/js/jquery/linenumbers/jquery.linenumbers.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/spellbook/static/admin/js/jquery/linenumbers/jquery.linenumbers.js b/backend/spellbook/static/admin/js/jquery/linenumbers/jquery.linenumbers.js index fe759929..48483131 100644 --- a/backend/spellbook/static/admin/js/jquery/linenumbers/jquery.linenumbers.js +++ b/backend/spellbook/static/admin/js/jquery/linenumbers/jquery.linenumbers.js @@ -9,6 +9,7 @@ * [textarea] should have an integer line height to avoid rounding errors. * * Source: https://stackoverflow.com/a/45252226/8589004 + * --> then updated and fixed. */ function countLines(textarea, text=null) { if (_buffer == null) { @@ -60,13 +61,13 @@ $editor.prepend('
'); const $lineNumbers = $editor.find('div.line-numbers'); function updateLineNumbers() { - const current = $lineNumbers.children().length; - const lines = countLines($this[0]); - if (lines == current) { + const current = $lineNumbers.children('span.number').length; + const rows = $this.val().split('\n') || []; + if (rows.length == current) { return; } + const lines = countLines($this[0]); $lineNumbers.empty(); - const rows = $this.val().split('\n') || []; for (let i = 0; i < rows.length; i++) { $lineNumbers.append(``); const lines = countLines($this[0], rows[i]);