vscode: reduced how often symbol width gets measured;
authorThomas Lindae <thomas.lindae@in.tum.de>
Mon, 27 May 2024 13:21:15 +0200
changeset 81046 95f650a8ce08
parent 81045 07d25a1830df
child 81047 befb2b4bffb3
vscode: reduced how often symbol width gets measured;
src/Tools/VSCode/extension/media/main.js
--- a/src/Tools/VSCode/extension/media/main.js	Mon May 27 13:20:31 2024 +0200
+++ b/src/Tools/VSCode/extension/media/main.js	Mon May 27 13:21:15 2024 +0200
@@ -25,14 +25,14 @@
             vscode.postMessage({'command': 'locate'});
         });
 
+    const test_string = "mix";
+    const test_span = document.createElement("span");
+    test_span.textContent = test_string;
+    document.body.appendChild(test_span);
+    const symbol_width = test_span.getBoundingClientRect().width / test_string.length;
+    document.body.removeChild(test_span);
+
     const get_window_margin = () => {
-        const test_string = "mix";
-        const test_span = document.createElement("span");
-        test_span.textContent = test_string;
-        document.body.appendChild(test_span);
-        const symbol_width = test_span.getBoundingClientRect().width / test_string.length;
-        document.body.removeChild(test_span);
-
         const width = window.innerWidth / symbol_width;
         const result = Math.max(width - 16, 1); // extra headroom
         return result;