rusackas commented on code in PR #41697:
URL: https://github.com/apache/superset/pull/41697#discussion_r3530376467


##########
superset-frontend/packages/superset-ui-core/src/components/AsyncAceEditor/index.tsx:
##########
@@ -281,6 +282,30 @@ export function AsyncAceEditor(
           };
         }, [ref]);
 
+        // Ace caches the measured glyph width in its internal FontMetrics and
+        // only re-measures when its hidden measure node's own size changes. If
+        // the editor font finishes loading after construction, the cached 
width
+        // can stop matching the rendered glyphs and the caret drifts further
+        // from the text the longer the line, the residual misalignment in 
issue
+        // #41664 that the font-family CSS from #38928 does not address. Force 
a
+        // re-measure once the document's fonts have settled (and immediately,
+        // for the already-loaded case) so the caret stays aligned.
+        // `updateFontSize` runs Ace's `checkForSizeChanges`, which on a 
metrics
+        // change emits `changeCharacterSize`; Ace's renderer reacts with a
+        // forced resize and full re-render, so no explicit resize call is
+        // needed here.
+        const handleLoad = useCallback(
+          (editor: Ace.Editor) => {
+            const remeasure = () => {
+              editor.renderer.updateFontSize();
+            };
+            remeasure();
+            document.fonts?.ready?.then(remeasure).catch(() => {});

Review Comment:
   Good catch, this one's real... `?.` short-circuits to `undefined` and the 
bare `.catch` would then throw. Fixed in 959aca7e9b with full optional 
chaining, plus a test covering the no-Font-Loading-API case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to