fix(grid): remeasure headers after configured font loads
This commit is contained in:
1 parent
2ea5e8e9b9
commit
8bf4485a75
2 files changed
+28
-2
No files matched your search
@@ -2097,9 +2097,30 @@ const columnWidthDensity = computed(() => settingsStore.editorSettings.columnWid
|
||||
const tableFontFamily = computed(() => settingsStore.editorSettings.tableFontFamily);
|
||||
const columnWidthCacheKey = computed(() => props.cacheKey?.trim() || undefined);
|
||||
const columnStructureSignature = computed(() => createDataGridColumnStructureSignature(props.result.columns, props.result.column_types));
|
||||
const columnHeaderMeasurementKey = computed(() => [tableFontSize.value, tableFontFamily.value]);
|
||||
// Bumped once the configured header font is ready, so widths measured against a temporary fallback
|
||||
// font get re-measured without reacting to unrelated fonts loaded elsewhere in the application.
|
||||
const dataGridFontReadyTick = ref(0);
|
||||
const columnHeaderMeasurementKey = computed(() => [tableFontSize.value, tableFontFamily.value, dataGridFontReadyTick.value]);
|
||||
let columnHeaderMeasureContext: CanvasRenderingContext2D | null | undefined;
|
||||
|
||||
if (typeof document !== "undefined" && document.fonts) {
|
||||
let fontLoadRequestId = 0;
|
||||
watch(
|
||||
[tableFontSize, tableFontFamily],
|
||||
async ([fontSize, fontFamily]) => {
|
||||
const requestId = ++fontLoadRequestId;
|
||||
try {
|
||||
await document.fonts.load(`600 ${fontSize}px ${fontFamily}`);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (requestId === fontLoadRequestId) dataGridFontReadyTick.value++;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
onUnmounted(() => fontLoadRequestId++);
|
||||
}
|
||||
|
||||
function measureColumnHeaderText(text: string): number | undefined {
|
||||
if (typeof document === "undefined") return undefined;
|
||||
if (columnHeaderMeasureContext === undefined) columnHeaderMeasureContext = document.createElement("canvas").getContext("2d");
|
||||
|
||||
Reference in new issue
Block a user