Skip to content

Build your personal knowledge base with Trilium Notes

feat(code): filter the code language pickers as the user types

Elian Doran901cea393083
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 4a6885d421..b8dc1c0933 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -24,7 +24,7 @@ import { useActiveNoteContext, useLegacyImperativeHandlers, useNoteLabel, useNot
import Icon from "../react/Icon";
import LinkButton from "../react/LinkButton";
import { ParentComponent } from "../react/react_utils";
-import { ContentLanguagesModal, NoteTypeCodeNoteList, NoteTypeOptionsModal, useLanguageSwitcher, useMimeTypes } from "../ribbon/BasicPropertiesTab";
+import { codeLanguageItems, ContentLanguagesModal, NoteTypeOptionsModal, useLanguageSwitcher, useMimeTypes } from "../ribbon/BasicPropertiesTab";
import AttributeEditor, { AttributeEditorImperativeHandlers } from "../ribbon/components/AttributeEditor";
import AttributeHelp from "../ribbon/components/AttributeHelp";
import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";
@@ -610,14 +610,14 @@ function CodeNoteSwitcher({ note }: StatusBarContext) {
text={correspondingMimeType?.title}
title={t("status_bar.code_note_switcher")}
dropdownContainerClassName="dropdown-code-note-switcher"
- >
- <NoteTypeCodeNoteList
- currentMimeType={currentNoteMime}
- mimeTypes={enabledMimeTypes}
- changeNoteType={(type, mime) => server.put(`notes/${note.noteId}/type`, { type, mime })}
- setModalShown={() => setModalShown(true)}
- />
- </StatusBarDropdown>
+ filterable
+ items={codeLanguageItems({
+ currentMimeType: currentNoteMime,
+ mimeTypes: enabledMimeTypes,
+ changeNoteType: (type, mime) => void server.put(`notes/${note.noteId}/type`, { type, mime }),
+ onConfigure: () => setModalShown(true)
+ })}
+ />
{createPortal(
<NoteTypeOptionsModal modalShown={modalShown} setModalShown={setModalShown} />,
document.body
diff --git a/apps/client/src/widgets/react/Dropdown.spec.tsx b/apps/client/src/widgets/react/Dropdown.spec.tsx
index de8d83bc7a..8ea88c8115 100644
--- a/apps/client/src/widgets/react/Dropdown.spec.tsx
+++ b/apps/client/src/widgets/react/Dropdown.spec.tsx
@@ -74,6 +74,47 @@ describe("Dropdown", () => {
element.click();
};
+ it("draws its rows from data, filters them from an input at its top, and runs the one chosen", async () => {
+ const picked: string[] = [];
+ const row = (title: string) => ({ title, handler: () => picked.push(title) });
+ const { toggle } = renderDropdown({
+ filterable: true,
+ items: [ row("Python"), row("JavaScript"), row("Plain text"), { kind: "separator" }, { ...row("Configure"), uiIcon: "bx bx-cog" } ]
+ }, null);
+ const key = (name: string) => {
+ const event = new KeyboardEvent("keydown", { key: name, bubbles: true, cancelable: true });
+ (document.activeElement ?? document.body).dispatchEvent(event);
+ };
+ const input = () => popup()?.querySelector<HTMLInputElement>("input.tn-menu-filter-input") ?? null;
+ const titles = () => [ ...popup()?.querySelectorAll("li.dropdown-item") ?? [] ]
+ .map((item) => item.querySelector(".tn-menu-filter-title")?.textContent ?? item.textContent);
+
+ click(toggle);
+ await vi.waitFor(() => expect(document.activeElement).toBe(popup()));
+ expect(input()?.value).toBe("");
+ expect(titles()).toEqual([ "Python", "JavaScript", "Plain text", "Configure" ]);
+
+ // Typing in the menu goes on in the input, and Enter runs the first match.
+ key("j");
+ await vi.waitFor(() => expect(document.activeElement).toBe(input()));
+ expect(titles()).toEqual([ "JavaScript" ]);
+ key("Enter");
+ expect(picked).toEqual([ "JavaScript" ]);
+ await vi.waitFor(() => expect(popup()).toBeNull());
+
+ // Escape empties the input, then, with nothing to go back to, closes the menu.
+ click(toggle);
+ await vi.waitFor(() => expect(document.activeElement).toBe(popup()));
+ key("x");
+ await vi.waitFor(() => expect(input()?.value).toBe("x"));
+ key("Escape");
+ await vi.waitFor(() => expect(input()?.value).toBe(""));
+ expect(popup()).not.toBeNull();
+ key("Escape");
+ await vi.waitFor(() => expect(popup()).toBeNull());
+ expect(picked).toEqual([ "JavaScript" ]);
+ });
+
it("opens a popup below its toggle on a click, and closes it on another", async () => {
const onShown = vi.fn();
const onHidden = vi.fn();
diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsx
index 74bb855bcc..fa51950394 100644
--- a/apps/client/src/widgets/react/Dropdown.tsx
+++ b/apps/client/src/widgets/react/Dropdown.tsx
@@ -6,6 +6,7 @@ import {
} from "preact";
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
+import type { MenuItem } from "../../menus/context_menu";
import { isMobile, isNarrowLayout, onNarrowLayoutChange } from "../../services/utils";
import { focusListItem } from "./FormList";
import { useTooltip, useUniqueName } from "./hooks";
@@ -20,7 +21,14 @@ type DataAttributes = {
export interface DropdownProps extends Pick<HTMLAttributes<HTMLDivElement>, "id" | "className"> {
buttonClassName?: string;
buttonProps?: Partial<ButtonHTMLAttributes<HTMLButtonElement> & DataAttributes>;
- children: ComponentChildren;
+ children?: ComponentChildren;
+ /**
+ * For a {@link Dropdown}, its rows as data instead of {@link children}: a row runs its
+ * `handler`, then closes the menu.
+ */
+ items?: MenuItem<unknown>[];
+ /** For a {@link Dropdown} of {@link items}, offers an input at its top that filters them. */
+ filterable?: boolean;
title?: string;
dropdownContainerStyle?: CSSProperties;
dropdownContainerClassName?: string;
@@ -95,6 +103,12 @@ export default function Dropdown(props: DropdownProps) {
bottomSheet={bottomSheet}
startAt={startAt}
isWanted={isWanted}
+ items={props.items}
+ filterable={props.filterable}
+ onSelect={(item, e) => {
+ item.handler?.(item, e);
+ if (!item.items) close();
+ }}
onDismiss={() => dismiss("outside")}
onClose={close}
>
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index 9e280cf329..0cd4127344 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -41,6 +41,11 @@ export interface MenuProps<T> extends Pick<PopupProps, "anchor" | "offset" | "co
*/
isWanted?(): boolean;
items?: MenuItem<T>[];
+ /**
+ * For a menu of {@link items}: offers an input at its top that filters every item, at any depth,
+ * as `MenuCommandItem.filterable` does for a submenu.
+ */
+ filterable?: boolean;
/** Called when one of {@link items} is pressed with the primary button, or run from the keyboard. */
onSelect?(item: MenuCommandItem<T>, e: MouseEvent | KeyboardEvent): void;
children?: ComponentChildren;
@@ -54,11 +59,13 @@ const KEYS_LEAVING_CUSTOM_ROW = new Set([ "ArrowUp", "ArrowDown", "Escape", "Tab
/** The keys the menu always keeps while focus is in a submenu's filter input. See `isFilterKey()`. */
const KEYS_OF_FILTER = new Set([ "ArrowUp", "ArrowDown", "Enter", "Escape", "Tab" ]);
const FILTER_INPUT = "input.tn-menu-filter-input";
+/** The filter of a menu's own top level, which no row opened. */
+const TOP_LEVEL = { rowId: "", level: -1 };
/** How long typed letters keep adding to the text a row is looked up by. */
const TYPEAHEAD_TIMEOUT = 500;
-export default function Menu<T>({ id, className, anchor, placement, bottomSheet, startAt, items, onSelect, children, onClose, onDismiss, isWanted, elementRef, ...popupProps }: MenuProps<T>) {
+export default function Menu<T>({ id, className, anchor, placement, bottomSheet, startAt, items, filterable, onSelect, children, onClose, onDismiss, isWanted, elementRef, ...popupProps }: MenuProps<T>) {
const menuRef = useRef<HTMLDivElement | null>(null);
// The submenus' layers render into the menu element, which rows reach through the context.
const [ layerHost, setLayerHost ] = useState<HTMLElement | null>(null);
@@ -172,7 +179,7 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,
// A filter ends with the submenu it filters, as the pointer or the keys close it.
useLayoutEffect(() => {
const current = filterRef.current;
- if (current && open[current.level]?.id !== current.rowId) setFilter(undefined);
+ if (current && current.level >= 0 && open[current.level]?.id !== current.rowId) setFilter(undefined);
}, [ open, setFilter ]);
// The first match, or the first row once the input is emptied, is the one Enter runs. Typing
@@ -261,6 +268,8 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,
// Emptied first; empty, it closes the submenu and gives the menu its keys back.
if (filterInput.value) {
setFilter(undefined);
+ } else if (level === 0) {
+ close();
} else {
closeLevel(level);
menuRef.current?.focus({ preventScroll: true });
@@ -338,6 +347,7 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,
const rowId = open[parent]?.id;
if (rowId && rows.get(rowId)?.filterable) target = { rowId, level: parent };
}
+ if (!target && filterable && items) target = TOP_LEVEL;
if (!target) return false;
// The submenus open inside it give way to the list of matches.
openSubmenu(target.level + 1);
@@ -393,7 +403,13 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,
menu's `::before` stays behind them. A `<menu>`, as rows are its list items, out of
the accessibility tree so they read as the menu's own. */}
<menu className="tn-menu-scroll" role="none">
- {items ? <MenuItems items={items} onSelect={onSelect} /> : children}
+ {items && filterable && (
+ <MenuFilterContext.Provider value={{ ...TOP_LEVEL, text: filter?.level === TOP_LEVEL.level ? filter.text : "" }}>
+ <MenuItems items={items} onSelect={onSelect} />
+ </MenuFilterContext.Provider>
+ )}
+ {items && !filterable && <MenuItems items={items} onSelect={onSelect} />}
+ {!items && children}
</menu>
{/* The submenus' layers follow the scroller in here, portaled by their rows. */}
</Popup>
@@ -402,6 +418,20 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,
}
/** `items` drawn as the rows that stand for them, with a run of separators reduced to one. */
+/**
+ * {@link items} drawn as the rows a menu of items draws, for a menu of components or a list
+ * outside any menu. A row runs its `handler`, then closes the menu it stands in, if any.
+ */
+export function MenuItemRows<T>({ items }: { items: MenuItem<T>[] }) {
+ const menu = useContext(MenuContext);
+ return (
+ <MenuItems items={items} onSelect={(item, e) => {
+ item.handler?.(item, e);
+ if (!item.items) menu?.close();
+ }} />
+ );
+}
+
function MenuItems<T>({ items, onSelect }: {
items: MenuItem<T>[],
onSelect: MenuProps<T>["onSelect"]
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.spec.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.spec.tsx
new file mode 100644
index 0000000000..2e24ad5bd2
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/BasicPropertiesTab.spec.tsx
@@ -0,0 +1,41 @@
+import type { MimeType } from "@triliumnext/commons";
+import { describe, expect, it, vi } from "vitest";
+
+// i18next is not initialized in the test env; echo the key so titles are what the spec reads.
+vi.mock("../../services/i18n", () => ({
+ t: (key: string) => key,
+ getAvailableLocales: () => [],
+ getLocaleById: () => undefined
+}));
+
+import { codeLanguageItems } from "./BasicPropertiesTab";
+
+describe("codeLanguageItems", () => {
+ const mimeTypes = [
+ { title: "Plain text", mime: "text/plain" },
+ { title: "C++ <templates>", mime: "text/x-c++src" }
+ ] as MimeType[];
+
+ it("lists the languages, ticks the note's own, and ends with the options when asked", () => {
+ const changeNoteType = vi.fn();
+ const onConfigure = vi.fn();
+ const items = codeLanguageItems({ currentMimeType: "text/x-c++src", mimeTypes, changeNoteType, onConfigure });
+
+ // Titles are HTML in a menu, so a language's name is escaped.
+ expect(items.map((item) => ("kind" in item ? item.kind : item.title))).toEqual([
+ "Plain text", "C++ &lt;templates&gt;", "separator", "basic_properties.configure_code_notes"
+ ]);
+ expect(items.map((item) => "checked" in item && item.checked)).toEqual([ false, true, false, false ]);
+
+ const [ plain, , , configure ] = items;
+ if ("kind" in plain || "kind" in configure) throw new Error("expected rows");
+ plain.handler?.(plain, new MouseEvent("click"));
+ expect(changeNoteType).toHaveBeenCalledWith("code", "text/plain");
+ configure.handler?.(configure, new MouseEvent("click"));
+ expect(onConfigure).toHaveBeenCalledTimes(1);
+ expect(configure.uiIcon).toBe("bx bx-cog");
+
+ // Without a way to open the options, there is no row for them.
+ expect(codeLanguageItems({ mimeTypes, changeNoteType })).toHaveLength(2);
+ });
+});
diff --git a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
index a73c2c74fa..777b297143 100644
--- a/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
+++ b/apps/client/src/widgets/ribbon/BasicPropertiesTab.tsx
@@ -5,6 +5,7 @@ import { createPortal } from "preact";
import { Dispatch, StateUpdater, useCallback, useEffect, useMemo, useState } from "preact/hooks";
import FNote from "../../entities/fnote";
+import type { MenuItem } from "../../menus/context_menu";
import branches from "../../services/branches";
import dialog from "../../services/dialog";
import { isExperimentalFeatureEnabled } from "../../services/experimental_features";
@@ -16,11 +17,13 @@ import protected_session from "../../services/protected_session";
import server from "../../services/server";
import sync from "../../services/sync";
import toast from "../../services/toast";
+import { escapeHtml } from "../../services/utils";
import Dropdown from "../react/Dropdown";
import FormDropdownList from "../react/FormDropdownList";
-import { FormDropdownDivider, FormListBadge, FormListItem } from "../react/FormList";
+import { FormListItem } from "../react/FormList";
import FormToggle from "../react/FormToggle";
import HelpButton from "../react/HelpButton";
+import { MenuItemRows } from "../react/Menu";
import { useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEvent, useTriliumOption } from "../react/hooks";
import Modal from "../react/Modal";
import { CodeMimeTypesList } from "../type_widgets/options/code_mime_types_list";
@@ -48,6 +51,7 @@ function NoteTypeWidget({ note }: { note?: FNote | null }) {
const currentNoteType = useNoteProperty(note, "type") ?? undefined;
const currentNoteMime = useNoteProperty(note, "mime");
const [ modalShown, setModalShown ] = useState(false);
+ const items = useNoteTypeItems({ currentNoteType, currentNoteMime, note, setModalShown });
return (
<div className="note-type-container">
@@ -56,9 +60,8 @@ function NoteTypeWidget({ note }: { note?: FNote | null }) {
dropdownContainerClassName="note-type-dropdown"
text={<span className="note-type-desc">{findTypeTitle(currentNoteType, currentNoteMime)}</span>}
disabled={notSelectableNoteTypes.includes(currentNoteType ?? "text")}
- >
- <NoteTypeDropdownContent currentNoteType={currentNoteType} currentNoteMime={currentNoteMime} note={note} setModalShown={setModalShown} />
- </Dropdown>
+ items={items} filterable
+ />
{createPortal(
<NoteTypeOptionsModal modalShown={modalShown} setModalShown={setModalShown} />,
@@ -68,13 +71,25 @@ function NoteTypeWidget({ note }: { note?: FNote | null }) {
);
}
-export function NoteTypeDropdownContent({ currentNoteType, currentNoteMime, note, setModalShown, noCodeNotes }: {
+interface NoteTypeListProps {
currentNoteType?: NoteType;
currentNoteMime?: string | null;
note?: FNote | null;
setModalShown: Dispatch<StateUpdater<boolean>>;
noCodeNotes?: boolean;
-}) {
+}
+
+/** The note types to switch `note` to, as rows of a menu or a list. See {@link useNoteTypeItems}. */
+export function NoteTypeDropdownContent(props: NoteTypeListProps) {
+ return <MenuItemRows items={useNoteTypeItems(props)} />;
+}
+
+/**
+ * The note types to switch `note` to, the current one ticked, as menu items: the note types, then,
+ * unless {@link NoteTypeListProps.noCodeNotes}, the enabled code languages under a "Code" heading
+ * and a row opening their options.
+ */
+export function useNoteTypeItems({ currentNoteType, currentNoteMime, note, setModalShown, noCodeNotes }: NoteTypeListProps) {
const { enabledMimeTypes } = useMimeTypes();
const noteTypes = useMemo(() => selectableNoteTypes(!noCodeNotes), [ noCodeNotes ]);
const changeNoteType = useCallback(async (type: NoteType, mime?: string) => {
@@ -95,70 +110,60 @@ export function NoteTypeDropdownContent({ currentNoteType, currentNoteMime, note
await server.put(`notes/${note.noteId}/type`, { type, mime });
}, [ note, currentNoteType, currentNoteMime ]);
- return (
- <>
- {noteTypes.map(({ isNew, isBeta, type, mime, title }) => {
- const badges: FormListBadge[] = [];
- if (isNew) {
- badges.push({
- className: "new-note-type-badge",
- text: t("note_types.new-feature")
- });
- }
- if (isBeta) {
- badges.push({
- text: t("note_types.beta-feature")
- });
- }
-
- if (noCodeNotes || type !== "code") {
- return (
- <FormListItem
- checked={isCurrentNoteType({ type, mime }, note)}
- badges={badges}
- onClick={() => changeNoteType(type, mime)}
- >{title}</FormListItem>
- );
- }
- return (
- <>
- <FormDropdownDivider />
- <FormListItem disabled>
- <strong>{title}</strong>
- </FormListItem>
- </>
- );
- })}
-
- {!noCodeNotes && <NoteTypeCodeNoteList currentMimeType={currentNoteMime ?? undefined} mimeTypes={enabledMimeTypes} changeNoteType={changeNoteType} setModalShown={setModalShown} />}
- </>
- );
+ const items: MenuItem<unknown>[] = [];
+ for (const { isNew, isBeta, type, mime, title } of noteTypes) {
+ if (noCodeNotes || type !== "code") {
+ items.push({
+ title: escapeHtml(title),
+ checked: isCurrentNoteType({ type, mime }, note),
+ badges: [
+ ...isNew ? [ { className: "new-note-type-badge", title: t("note_types.new-feature") } ] : [],
+ ...isBeta ? [ { title: t("note_types.beta-feature") } ] : []
+ ],
+ handler: () => void changeNoteType(type, mime)
+ });
+ } else {
+ // The code entries head the list of languages that follows.
+ items.push({ kind: "separator" }, { title: `<strong>${escapeHtml(title)}</strong>`, uiIcon: undefined, enabled: false });
+ }
+ }
+ if (!noCodeNotes) {
+ items.push(...codeLanguageItems({
+ currentMimeType: currentNoteMime ?? undefined,
+ mimeTypes: enabledMimeTypes,
+ changeNoteType: (type, mime) => void changeNoteType(type, mime),
+ onConfigure: () => setModalShown(true)
+ }));
+ }
+ return items;
}
-export function NoteTypeCodeNoteList({ currentMimeType, mimeTypes, changeNoteType, setModalShown }: {
+interface CodeLanguageListProps {
currentMimeType?: string;
mimeTypes: MimeType[];
changeNoteType(type: NoteType, mime: string): void;
+ /** Opens the options of the code languages, from a row at the end; without it, there is none. */
+ onConfigure?(): void;
+}
+
+/** The code languages to switch a note to, as rows of a menu or a list. See {@link codeLanguageItems}. */
+export function NoteTypeCodeNoteList({ setModalShown, ...props }: Omit<CodeLanguageListProps, "onConfigure"> & {
setModalShown?(shown: boolean): void;
}) {
- return (
- <>
- {mimeTypes.map(({ title, mime }) => (
- <FormListItem
- key={mime}
- checked={mime === currentMimeType}
- onClick={() => changeNoteType("code", mime)}
- >
- {title}
- </FormListItem>
- ))}
-
- {setModalShown && <>
- <FormDropdownDivider />
- <FormListItem icon="bx bx-cog" onClick={() => setModalShown(true)}>{t("basic_properties.configure_code_notes")}</FormListItem>
- </>}
- </>
- );
+ return <MenuItemRows items={codeLanguageItems({ ...props, onConfigure: setModalShown && (() => setModalShown(true)) })} />;
+}
+
+/** The code languages to switch a note to, the current one ticked, as menu items. */
+export function codeLanguageItems({ currentMimeType, mimeTypes, changeNoteType, onConfigure }: CodeLanguageListProps) {
+ const items: MenuItem<unknown>[] = mimeTypes.map(({ title, mime }) => ({
+ title: escapeHtml(title),
+ checked: mime === currentMimeType,
+ handler: () => changeNoteType("code", mime)
+ }));
+ if (onConfigure) {
+ items.push({ kind: "separator" }, { title: t("basic_properties.configure_code_notes"), uiIcon: "bx bx-cog", handler: onConfigure });
+ }
+ return items;
}
export function useMimeTypes() {
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html
index 46c74ac1e5..8348134c1a 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Code.html
@@ -32,7 +32,9 @@
<h2>Adjusting the language of a code note</h2>
<p>In the&nbsp;<a href="#root/_help_BlN9DFI679QC">Ribbon</a>, look for the <em>Note type</em> selector
and click it to reveal the possible note types. Inside of it there will
- be a section called <em>Code</em>, select any one of the languages.</p>
+ be a section called <em>Code</em>, select any one of the languages. To find
+ a language quickly, type its name: the list narrows to the matching entries,
+ and <kbd>Enter</kbd> picks the first one.</p>
<p>
<img src="1_Code_image.png">
</p>
@@ -86,7 +88,8 @@
or from spaces to tabs. This rewrites the leading whitespace on every line
while preserving alignment remainders.</li>
</ol>
-<p>Clicking the language indicator lets you change the note's MIME type.</p>
+<p>Clicking the language indicator lets you change the note's MIME type.
+ As in the <em>Note type</em> selector, typing narrows the list of languages.</p>
<h3>Re-indentation</h3>
<p>When you re-indent content, the editor:</p>
<ul>
diff --git a/docs/User Guide/User Guide/Note Types/Code.md b/docs/User Guide/User Guide/Note Types/Code.md
index 4fb53d90bd..a08995acef 100644
--- a/docs/User Guide/User Guide/Note Types/Code.md
+++ b/docs/User Guide/User Guide/Note Types/Code.md
@@ -21,7 +21,7 @@ In the [Note Tree](../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20Tre
## Adjusting the language of a code note
-In the [Ribbon](../Basic%20Concepts%20and%20Features/UI%20Elements/Ribbon.md), look for the _Note type_ selector and click it to reveal the possible note types. Inside of it there will be a section called _Code_, select any one of the languages.
+In the [Ribbon](../Basic%20Concepts%20and%20Features/UI%20Elements/Ribbon.md), look for the _Note type_ selector and click it to reveal the possible note types. Inside of it there will be a section called _Code_, select any one of the languages. To find a language quickly, type its name: the list narrows to the matching entries, and <kbd>Enter</kbd> picks the first one.
![](1_Code_image.png)
@@ -56,7 +56,7 @@ The status bar at the bottom of the editor shows the current indentation setting
2. **Display Width** — choose from preset widths (1, 2, 3, 4, 6, 8). Changes are saved as a per-note `#tabWidth` label.
3. **Re-indent Content To** — convert existing indentation to a different style. For example, re-indent a file from 4 spaces to 2 spaces, or from spaces to tabs. This rewrites the leading whitespace on every line while preserving alignment remainders.
-Clicking the language indicator lets you change the note's MIME type.
+Clicking the language indicator lets you change the note's MIME type. As in the _Note type_ selector, typing narrows the list of languages.
### Re-indentation