Skip to content

Commit 978056c

Browse files
committed
Merge remote-tracking branch 'origin/main' into sandcastle-banner-update
2 parents cbb0883 + ecf0050 commit 978056c

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

packages/sandcastle/src/Gallery/GalleryItemStore.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ export function useGalleryItemStore() {
194194
return isGalleryLoaded ? () => loadFromUrl(items, legacyIds) : null;
195195
}, [items, legacyIds]);
196196

197+
const [isFirstSearch, setFirstSearch] = useState(true);
198+
const setSearchTermWrapper = useCallback(
199+
(newSearchTerm: string | null) => {
200+
// the default label filter for Showcases can be confusing when it doesn't
201+
// search everything after page load. Remove the filter on the first search only
202+
// to ensure we search everything
203+
if (isFirstSearch) {
204+
setSearchFilter(null);
205+
setFirstSearch(false);
206+
}
207+
setSearchTerm(newSearchTerm);
208+
},
209+
[setSearchTerm, isFirstSearch, setSearchFilter],
210+
);
211+
197212
return {
198213
items,
199214
galleryLoaded,
@@ -203,7 +218,7 @@ export function useGalleryItemStore() {
203218
searchFilter,
204219
searchTerm,
205220
isSearchPending,
206-
setSearchTerm,
221+
setSearchTerm: setSearchTermWrapper,
207222
setSearchFilter,
208223
searchResults: memoizedSearchResults,
209224

packages/sandcastle/src/SandcastleEditor.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,28 @@ function SandcastleEditor({
8383
const {
8484
settings: { fontFamily, fontSize, fontLigatures },
8585
} = useContext(SettingsContext);
86+
const documentRef = useRef(document);
8687
useEffect(() => {
87-
internalEditorRef.current?.updateOptions({
88-
fontFamily: availableFonts[fontFamily]?.cssValue ?? "Droid Sans Mono",
89-
});
88+
const cssName = availableFonts[fontFamily]?.cssValue ?? "Droid Sans Mono";
89+
const fontFace = [...documentRef.current.fonts.values()].find(
90+
(font) => font.family === cssName && font.weight === "400",
91+
);
92+
if (fontFace?.status !== "loaded") {
93+
// Monaco needs to check the size of the font for things like cursor position
94+
// and variable highlighting. If it does this check before the font has loaded
95+
// it will get the wrong size and may be horribly offset especially with ligatures
96+
// https://github.com/microsoft/monaco-editor/issues/392
97+
documentRef.current.fonts.load(`1rem ${cssName}`).then(() => {
98+
internalEditorRef.current?.updateOptions({
99+
fontFamily: cssName,
100+
});
101+
monaco.editor.remeasureFonts();
102+
});
103+
} else {
104+
internalEditorRef.current?.updateOptions({
105+
fontFamily: cssName,
106+
});
107+
}
90108
}, [fontFamily]);
91109
useEffect(() => {
92110
internalEditorRef.current?.updateOptions({

0 commit comments

Comments
 (0)