From 0cc21739a8c463a538c755c224bd0546c7797f77 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 9 Sep 2022 21:03:13 +0200 Subject: [PATCH] optimised caret code added dynamic width closes #3518 --- frontend/src/ts/test/caret.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/ts/test/caret.ts b/frontend/src/ts/test/caret.ts index 97857b6c2..34396cf72 100644 --- a/frontend/src/ts/test/caret.ts +++ b/frontend/src/ts/test/caret.ts @@ -105,28 +105,32 @@ export async function updatePosition(): Promise { (fullWidthCaret ? 0 : caretWidth / 2); } } + const newWidth = fullWidthCaret + ? ((currentLetter + ? currentLetter.offsetWidth + : previousLetter.offsetWidth) ?? 0) + "px" + : ""; let smoothlinescroll = $("#words .smoothScroller").height(); if (smoothlinescroll === undefined) smoothlinescroll = 0; - if (Config.smoothCaret) { - caret.stop(true, false).animate( - { - top: newTop - smoothlinescroll, - left: newLeft, - }, - SlowTimer.get() ? 0 : 100 - ); + caret.css("display", "block"); //for some goddamn reason adding width animation sets the display to none ???????? + + const animation: { top: number; left: number; width?: string } = { + top: newTop - smoothlinescroll, + left: newLeft, + }; + + if (newWidth !== "") { + animation["width"] = newWidth; } else { - caret.stop(true, true).animate( - { - top: newTop - smoothlinescroll, - left: newLeft, - }, - 0 - ); + caret.css("width", ""); } + caret + .stop(true, false) + .animate(animation, Config.smoothCaret && !SlowTimer.get() ? 100 : 0); + if (Config.showAllLines) { const browserHeight = window.innerHeight; const middlePos =