Use the Find interface
The editor ships with a built-in Find bar for searching the current document, ready to use once the Document Authoring library is installed and running — refer to the getting started guide if it isn’t set up yet. This guide covers its keyboard controls, the editor.find programmatic API that drives it, and what the bar searches. The editor.find namespace is available from 1.19.0.
The example code omits error handling. Add it before using this code in production.
Find behavior and keyboard controls
The Find bar is part of the editor and needs no configuration:
- Control/Command-F opens the bar and focuses its input.
- Opening the bar with Control/Command-F while text is selected presets the query with the first line of the selection.
- Enter moves to the next match, and Shift-Enter moves to the previous match. Both wrap around the end of the document.
- Escape, while the input is focused, closes the bar and returns focus to the document.
- The bar also carries previous-match, next-match, and close buttons. The two navigation buttons are disabled while the query has no matches.
The bar reports the current position and the total, such as 3 of 12. Every match is highlighted, and the current match carries a stronger highlight. Moving to a match selects it in the document and scrolls it into view.
Matching runs asynchronously, so highlights appear shortly after the query changes. While the bar stays open, edits to the document update the matches. Closing the bar clears the highlights.
Open and close the Find bar with the programmatic API
Use editor.find.open() to open the bar and focus its input:
editor.find.open();Pass query to preset the search text. The query replaces whatever the bar currently holds:
editor.find.open({ query: 'hello' });Use editor.find.close() to close the bar and clear the match highlights:
editor.find.close();Both methods do nothing when there’s nothing to change. Calling open() while the bar is already open with the same query is a no-op, and it doesn’t refocus the input. Calling close() while the bar is already closed is also a no-op.
The bar keeps its query after closing, so open() without a query reopens with the previous search text. That query lives in memory for the lifetime of the editor instance and isn’t restored after a page reload. Calling editor.setCurrentDocument() closes the bar and clears the query, while the editor.find handle itself stays valid.
Connect Find to custom application chrome
Applications that replace the editor chrome drive the Find bar from their own button. Read editor.find.getState() on each click and branch on open:
const editor = await docAuthSystem.createEditor( document.getElementById('editor'),);
const findButton = document.getElementById('find-toggle');
findButton.addEventListener('click', () => { if (editor.find.getState().open) { editor.find.close(); return; }
editor.find.open();});The corresponding HTML for the button could look like this:
<button id="find-toggle" type="button">Find</button>Read the state at the moment of the click instead of tracking a Boolean in the host application. The bar also opens with Control/Command-F and closes with Escape or its close button, and neither route passes through host code. The editor emits no event for Find state changes, so a host-tracked flag drifts out of sync with the bar.
What the Find bar searches
The bar searches the whole document, not only the visible page. It covers:
- Body text, including text in tables and nested tables
- Text inside shapes and text boxes
- Footnote and endnote text
- Headers and footers, including the tables and shapes they contain
Header and footer variants are searched only when the current layout renders them. A first-page or even-page variant that the document defines but never renders produces no matches.
The bar matches literal text — case-insensitively — within a single paragraph, and it doesn’t search comment text. To match case-sensitively, match a pattern, or replace matches, search with the programmatic API using searchText() and replaceText() as described in the find and replace guide.