@knime/kds-code-editor 6.8.0 → 6.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @knime/kds-code-editor
2
2
 
3
+ ## 6.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f98f6e3: `KdsCodeEditor` / `KdsCodeDiffEditor`: fixed cursor placement and selection
8
+ width being offset from the rendered text. Monaco measured the character width
9
+ before the code font was loaded and kept the fallback font's metrics for the
10
+ whole page; the code font is now loaded explicitly and the fonts are
11
+ re-measured once it arrived.
12
+ - Updated dependencies [2d8e635]
13
+ - @knime/kds-components@6.8.1
14
+ - @knime/kds-styles@6.8.1
15
+
3
16
  ## 6.8.0
4
17
 
5
18
  ### Minor Changes
package/dist/index.js CHANGED
@@ -5695,11 +5695,30 @@ var registerTomlLanguage = () => {
5695
5695
  };
5696
5696
  //#endregion
5697
5697
  //#region src/CodeEditor/monacoEnvironment.ts
5698
- document.fonts?.ready.then(() => {
5699
- editor.remeasureFonts();
5700
- });
5698
+ var MEASURED_CHARACTERS = "n 0123456789|/-_ilm%·";
5699
+ var fontRemeasureScheduled = false;
5700
+ /**
5701
+ * Monaco measures character widths when an editor is created, caches them for
5702
+ * the whole page, and derives cursor placement and selection width from them.
5703
+ * That measurement is also the first use of the code font, so it happens
5704
+ * before the font is loaded and keeps the fallback font's metrics — cursor and
5705
+ * selection then drift away from the glyphs (KDS-1002).
5706
+ *
5707
+ * `document.fonts.ready` does not help: it resolves while nothing is pending,
5708
+ * which is the case before any editor exists. So load the code font explicitly
5709
+ * and re-measure once it is there — also when loading failed, in which case
5710
+ * the fallback metrics are at least measured consistently.
5711
+ */
5712
+ var remeasureFontsWhenCodeFontLoaded = () => {
5713
+ if (fontRemeasureScheduled || !document.fonts) return;
5714
+ fontRemeasureScheduled = true;
5715
+ document.fonts.load(codeFont.css.value, MEASURED_CHARACTERS).catch(() => []).then(() => {
5716
+ editor.remeasureFonts();
5717
+ });
5718
+ };
5701
5719
  var setupMonacoEnvironment = () => {
5702
5720
  registerTomlLanguage();
5721
+ remeasureFontsWhenCodeFontLoaded();
5703
5722
  if (self.MonacoEnvironment) return;
5704
5723
  self.MonacoEnvironment = { getWorker: async (_workerId, label) => {
5705
5724
  if (label === "json") {