import { Disposable } from '@theia/core'; import { Range as EditorRange } from '@theia/monaco-editor-core/esm/vs/editor/common/core/range.js'; import { IEditorDecorationsCollection } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon.js'; import { IModelDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/model.js'; import { SimpleMonacoEditor } from '@theia/monaco/lib/browser/simple-monaco-editor'; import { ChatFindMatch, ChatFindMatcher } from './chat-find-matcher.js'; import { ChatFindTextSegment } from './chat-find-text.js'; /** Minimal abstraction over `CSS.highlights` so the highlighter can be tested and degrades when unsupported. */ export interface ChatFindHighlightRegistry { set(name: string, ranges: Range[]): void; delete(name: string): void; } export declare namespace ChatFindHighlightRegistry { /** The CSS Custom Highlight API registry, or `undefined` when the browser does not support it. */ function fromCssHighlights(): ChatFindHighlightRegistry | undefined; } /** Where the current match is shown: a DOM range, or a range in the editor of a code part. */ type ChatFindCurrentTarget = { kind: 'dom'; range: Range; } | { kind: 'code'; editor: SimpleMonacoEditor; range: EditorRange; }; interface ChatFindCodeDecorations { collection: IEditorDecorationsCollection; /** What the collection currently shows, so unchanged decorations are not set again. */ signature: string; } /** * Highlights find matches in the mounted rows of the chat tree: text with the CSS Custom Highlight API, code parts * with decorations in their editor. * * Only the content the matcher actually searched is highlighted: the elements to scan are derived from the * match list, so content the matcher skips (tool calls, reasoning, delegated sub-chats) is never highlighted * even though it renders inside the same row. While active, DOM mutations under the root (virtuoso mounting * rows, streamed content) re-apply the highlights on the next animation frame. */ export declare class ChatFindHighlighter implements Disposable { static readonly MATCH_HIGHLIGHT = "theia-chat-find-match"; static readonly CURRENT_HIGHLIGHT = "theia-chat-find-current"; /** Monaco's own find decorations, so code parts look the same as a match of the editor find widget. */ protected static readonly CODE_MATCH_DECORATION: IModelDecorationOptions; protected static readonly CODE_CURRENT_DECORATION: IModelDecorationOptions; protected readonly matcher: ChatFindMatcher; protected registry: ChatFindHighlightRegistry | undefined; protected root: HTMLElement | undefined; protected regexp: RegExp | undefined; protected matches: readonly ChatFindMatch[]; protected current: ChatFindMatch | undefined; protected currentTarget: ChatFindCurrentTarget | undefined; protected readonly codeDecorations: Map; protected observer: MutationObserver | undefined; protected scheduled: boolean; protected init(): void; protected createRegistry(): ChatFindHighlightRegistry | undefined; /** Highlights the given matches under `root` and marks `current`; an undefined `regexp` clears. */ update(root: HTMLElement, regexp: RegExp | undefined, matches: readonly ChatFindMatch[], current: ChatFindMatch | undefined): void; /** Re-applies the current highlights, e.g. after a scroll mounted new rows. */ refresh(): void; /** Whether the current match is rendered, so that {@link scrollCurrentIntoView} can reveal it. */ get hasCurrentTarget(): boolean; /** The mounted row rendering the tree node `nodeId`, if any. */ findRow(root: HTMLElement, nodeId: string): HTMLElement | undefined; /** * Scrolls the current match into view within the chat tree's own scroll container. * * Deliberately does not use `Element.scrollIntoView()`: that scrolls every scrollable ancestor up to the * viewport, which shifts the whole application shell. Only the first scroll container between the match * and `root` is moved, and only when the match is not already visible. */ scrollCurrentIntoView(root: HTMLElement): void; clear(): void; dispose(): void; /** The element showing the current match and its vertical extent in viewport coordinates, if it is mounted. */ protected getCurrentBounds(): { element: Element; top: number; height: number; } | undefined; /** The first scroll container between `from` and `root`, inclusive; never anything outside `root`. */ protected findScrollContainer(from: Element, root: HTMLElement): HTMLElement | undefined; protected observe(root: HTMLElement): void; protected scheduleApply(): void; protected apply(): void; protected findCurrentIn(matches: readonly ChatFindMatch[]): ChatFindMatch | undefined; /** Matches grouped by the element that renders them, so each element is scanned once. */ protected groupByContent(): Map; /** The element rendering the text a match was found in, or `undefined` when its row is not mounted. */ protected findContentElement(root: HTMLElement, match: ChatFindMatch): Element | undefined; /** The element holding exactly the text the matcher searched for a part: an error part searches only its message. */ protected findTextRoot(contentElement: Element, match: ChatFindMatch): Element; /** The editor of a code part, once it has been created. */ protected findCodeEditor(contentElement: Element): SimpleMonacoEditor | undefined; /** * Decorates the matches of a code part in its editor; match offsets are offsets into the code the editor shows. * @returns the current match's target when it is one of `matches`. */ protected decorateCode(editor: SimpleMonacoEditor, matches: readonly ChatFindMatch[], current: ChatFindMatch | undefined): ChatFindCurrentTarget | undefined; /** Removes the decorations of editors that no longer show a match, e.g. because their row was unmounted. */ protected clearCodeDecorations(keep: Set): void; /** One `Range` per occurrence of `regexp` in the text of `element`, with its offsets in that text. */ protected collectRanges(element: Element, regexp: RegExp): { start: number; end: number; range: Range; }[]; /** Map an offset in the concatenated text to a text node and offset inside it (end offsets stay in the preceding node). */ protected locate(segments: ChatFindTextSegment[], offset: number): { node: Text; offset: number; }; } export {}; //# sourceMappingURL=chat-find-highlighter.d.ts.map