Appearance
The editor's chrome (the desk around the pages, the rulers, handles, guides and readouts) has a light and a dark theme, an accent colour, and a high-contrast theme for the platform's high contrast mode. The page itself has its own setting, dark mode. None of it reaches the document: saving, PDF export and printing always use the document's colours.
export async function appearance(editor: Editor) {
// Dark chrome with the application's accent; the dark scheme lightens the accent so it holds on dark surfaces.
await editor.view.setTheme('dark', '#7A3EE0');
// A dark page, the document's colours adjusted to it. 'darkWithLightPage' keeps the page in its own colours.
await editor.view.setAppearance('dark');
// Everything measured while dragging: the change from the start, table sizes and status lines.
await editor.view.setDetail('full');
// The same settings in one command, with the object grid shown always.
await editor.commands.setViewOptions({ theme: 'light', appearance: 'light', detail: 'standard', objectGrid: 'always' });
// The application's own colours for the rulers, desk and handles, per scheme; the ones left out keep the scheme's.
await editor.view.setThemeColors({
light: { desk: '#F3F4F6', surface: '#FFFFFF', text: '#111827' },
dark: { desk: '#0D1117', surface: '#161B22', text: '#E6EDF3', secondaryText: '#8B949E' },
});
// The state reports the accent as drawn and the text colour on it, for chrome that matches the editor's.
const { theme, accent, accentOn } = editor.getState().view;
document.documentElement.style.setProperty('--accent', accent);
document.documentElement.style.setProperty('--on-accent', accentOn);
console.log(typeof theme === 'object' ? 'high contrast' : theme);
}
// Following the platform's dark mode. Under forced colours the mounted editor sets the high-contrast theme itself.
export function followDarkMode(editor: Editor): () => void {
const dark = matchMedia('(prefers-color-scheme: dark)');
const follow = () => {
const theme: ChromeTheme = dark.matches ? 'dark' : 'light';
void editor.view.setTheme(theme);
void editor.view.setAppearance(dark.matches ? 'dark' : 'light');
};
follow();
dark.addEventListener('change', follow);
return () => dark.removeEventListener('change', follow);
}
// The popovers: the application draws them, and answers them with commands.
export function ownPopovers(editor: Editor, show: (p: Popover, pick: (choice: string) => Promise<void>) => void, hide: () => void) {
editor.on('popoverRequested', (p) => {
switch (p.kind) {
case 'tabType':
// A choice's value; setRulerTabType closes the engine's popover.
show(p, (value) => editor.commands.setRulerTabType(p.choices.find((c) => c.value === value)?.value ?? p.current));
break;
case 'tabStop':
// addTabStop at its position changes the alignment; deleteTabStop clears it.
show(p, (choice) =>
choice === 'clear' ? editor.commands.deleteTabStop(p.position) : editor.commands.addTabStop({ position: p.position, alignment: p.alignment, leader: choice === 'dots' ? 'dots' : 'none' }),
);
break;
case 'autoCorrect':
show(p, (choice) => (choice === 'never' ? editor.commands.neverAutoCorrect() : editor.commands.revertAutoCorrect()));
break;
}
});
// The engine dismissed it: Esc, a press elsewhere, its answer, or its target gone.
editor.on('popoverClosed', hide);
}
// Yours closed on its own (Esc, a click elsewhere): the engine's closes too.
export const popoverDismissed = (editor: Editor) => editor.commands.closePopover();
// The chrome's scheme and accent. Any colour works as the accent: the dark scheme lightens it.
await session.SetThemeAsync(ChromeTheme.Dark, ColorValue.FromRgb(0x7A, 0x3E, 0xC8));
// Dark mode for the page. DarkWithLightPage keeps the page in its own colours with dark chrome.
// Saving, PDF export and printing always use the document's colours.
await session.SetAppearanceAsync(DocumentAppearance.Dark);
// How much the editor measures while you drag and hover.
await session.SetDetailAsync(MeasureDetail.Quiet);
// The application's own colours for the rulers, desk and handles, per scheme; the ones left null keep the scheme's.
await session.SetThemeColorsAsync(new ThemeColors(
Light: new ChromeColors(Desk: ColorValue.FromRgb(0xF3, 0xF4, 0xF6), Text: ColorValue.FromRgb(0x11, 0x18, 0x27)),
Dark: new ChromeColors(Desk: ColorValue.FromRgb(0x0D, 0x11, 0x17), Surface: ColorValue.FromRgb(0x16, 0x1B, 0x22))));
// The state reports the accent as drawn, and the text colour on it, for chrome of your own.
var view = session.State.View;
Console.WriteLine($"{view.Theme.Kind} {view.Accent} on {view.AccentOn}, page {view.Appearance}");
// The control has the same settings as properties. While Windows' high contrast is on, it uses the
// system colours and a light page instead, and follows Windows when the setting changes.
editor.Theme = ChromeTheme.Dark;
editor.Accent = Color.FromArgb(0x7A, 0x3E, 0xC8);
editor.Appearance = DocumentAppearance.DarkWithLightPage;
editor.MeasureDetail = MeasureDetail.Full;
Theme and accent
setViewOptions({ theme, accent }) sets the chrome's scheme, light (the default) or dark, and its accent. The
accent is any colour; the default is azure, #0A74E4. It colours the selection, handles, guides and active markers.
The dark theme draws a lighter, less saturated variant of it so it holds against dark
surfaces, and the state reports what's drawn: view.accent, and view.accentOn for text on it. Use those two for
chrome of your own that should match the editor's.
On the web, editor.view.setTheme(theme, accent?) is the same command. In .NET it's EditorSession.SetThemeAsync, or
the Theme and Accent properties of DocumentEditor.
Theme colours
To match the chrome to your own UI, setViewOptions({ themeColors: { light, dark } }) gives your colours for either
scheme: desk (around the pages and the rulers' strips), surface (the rulers' strips and the readouts'
backgrounds), text (text, ruler numbers and markers), secondaryText (unit ticks), faintText (fine ticks
and the object grid) and line (the rulers' outlines and the margins' hatching). Each colour left out keeps the
scheme's. A scheme given replaces the last one set for it, so { dark: {} } puts back the dark scheme's own colours;
a scheme left out keeps what it had. The colours apply whenever that scheme is on, so set both once and switch with
theme. The high-contrast theme always takes the platform's colours. view.themeColors in the state reports them.
On the web, editor.view.setThemeColors(colors) is the same command. In .NET it's EditorSession.SetThemeColorsAsync
with ThemeColors and ChromeColors.
The theme also gives the overlay colours (selection, object outline, drop caret, formatting marks and leader lines)
and the desk colour. setBackground and setOverlayColors still override them. A background set that way stays when
the theme changes, and so do overlay colours: set all five for a dark theme. The caret is always black or white,
whichever stands out more on the page, so neither the theme nor any colour you set changes it. Until the application sets a
theme, a dark background also gives the dark theme, as it gave dark rulers before.
To follow the theme again, setBackground(null) and setOverlayColors(null) put back its colours. In .NET they're
EditorHost.ResetBackground and ResetOverlayColors, or DocumentEditor.ResetBackColor and ResetOverlayColors.
Dark mode
appearance is how the page is drawn on screen:
| Value | The page |
|---|---|
light | in the document's colours (the default) |
dark | dark, with the document's colours adjusted to it: white becomes near black and black near white, and the other text, highlight, shading and border colours move with them. Shapes and pictures keep their colours |
darkWithLightPage | the chrome stays dark and the page shows in its own colours, as Word's Switch Modes does |
setAppearance(appearance) on the web view and SetAppearanceAsync in .NET wrap the same command. Dark mode moves
nothing: line breaks, page breaks and object positions are the same in every appearance.
Measuring detail and the object grid
detail is how much the editor measures while you drag and hover. quiet shows a chip with the value; standard
(the default) adds dimension lines, and everything while Alt is held; full always shows everything, with the change
from the start, table sizes and status lines. objectGrid is when the dot grid objects snap to shows: off,
whileDragging (the default) or always. It isn't the gridlines option, which stays the table gridlines. See
Editing.
High contrast
The engine never reads platform settings. The ready-made editors do it for you:
- Web. Under
forced-colors: activethe mounted editor sets thehighContrasttheme from the CSS system colours (Canvas,CanvasText,Highlight,HighlightText,GrayText) and a light page. It follows the mode as it changes. A theme or appearance set throughview.setThemeorview.setAppearancemeanwhile applies once the mode ends. - WinForms. With
SystemInformation.HighContraston,DocumentEditorsets thehighContrasttheme fromSystemColors(Window, WindowText, Highlight, HighlightText, GrayText) and a light page, and checks again when the system's preferences change.
An application drawing its own surface sets theme: { highContrast: { canvas, canvasText, highlight, highlightText, grayText } } itself (ChromeTheme.HighContrast(new HighContrastColors(...)) in .NET). The accent is then highlight,
and text on it highlightText.
Popovers
The tab type picker, a tab stop's options and the AutoCorrect menu are popovers the engine asks for with
popoverRequested: a kind, the anchor rectangle (client px on the web), and what the popover offers. Your
application draws them, as it does the context menu: the editor draws none. Make them keyboard-reachable (arrows,
Enter, Esc) and announce them as menus, in view.accent and view.accentOn to match the chrome. Answer with commands:
| Popover | Offers | Answered with |
|---|---|---|
tabType | current, and choices with a name and a one-line description | setRulerTabType(value) |
tabStop | the stop's position, alignment and leader | addTabStop at its position (changes the alignment or leader; the popover stays open), deleteTabStop |
autoCorrect | from (what was typed) and to (what it became) | revertAutoCorrect, neverAutoCorrect, or your AutoCorrect dialog (see AutoCorrect) |
popoverClosed says the engine dismissed the open one: Esc, a press elsewhere, its target gone, or its answer
(except a tabStop change). Opening one closes the one open. When your popover closes on its own, run closePopover
so the engine's closes too; with none open it does nothing. From the keyboard, showTabTypes, showTabStop (the stop nearest the caret) and
showAutoCorrectOptions (Alt+Shift+F10) ask for them.