obsidian APIs
- Plugin
- PluginSettingTab
- Setting
- App
- TFile
- Notice
- MarkdownView
- Modal
- Editor
- Vault
- addIcon
- WorkspaceLeaf
- TFolder
- TAbstractFile
- MarkdownPostProcessorContext
- Platform
- Menu
- normalizePath
- FuzzySuggestModal
- ButtonComponent
- FuzzyMatch
- MarkdownRenderer
- debounce
- TextComponent
- EditorPosition
- ItemView
- moment
- request
- DropdownComponent
- TextAreaComponent
- FileSystemAdapter
- CachedMetadata
- Scope
- MetadataCache
- ToggleComponent
- MarkdownRenderChild
- SuggestModal
- setIcon
- HeadingCache
- getAllTags
- EditorSuggest
- EditorSuggestContext
- EditorSuggestTriggerInfo
- FrontMatterCache
- FileView
- Component
- parseYaml
- Workspace
- LinkCache
- editorViewField
- EventRef
- View
- PluginManifest
- Pos
- Debouncer
- requestUrl
- ExtraButtonComponent
- MarkdownPostProcessor
- DataAdapter
- ListedFiles
- parseLinktext
- MenuItem
- ISuggestOwner
- OpenViewState
- FileManager
- ObsidianProtocolData
- Events
- SearchComponent
- ViewState
- renderResults
- Command
- Keymap
- Loc
- TagCache
- SearchMatches
- EmbedCache
- parseFrontMatterTags
- AbstractTextComponent
- Point
- MarkdownPreviewRenderer
- getLinkpath
- requireApiVersion
- resolveSubpath
- EditorRangeOrCaret
- EditorTransaction
- FolderItem
- ClipboardManager
- DragManager
- FileExplorerView
- AFItem
- Modifier
- EditorRange
- FileStats
- finishRenderMath
- loadMathJax
- renderMath
- fuzzySearch
- InstalledPlugin
- InternalPlugins
- prepareQuery
- CommandPalettePluginInstance
- PreparedQuery
- WorkspaceItem
- WorkspaceSplit
- ViewRegistry
- SearchResult
- StarredPluginInstance
- FileStarredItem
- StarredPluginItem
- ReferenceCache
- WorkspacesPluginInstance
- sortSearchResults
- SearchStarredItem
- Plugin_2
- QuickSwitcherOptions
- QuickSwitcherPluginInstance
- Chooser
- Hotkey
- KeymapContext
- KeymapEventListener
- RequestUrlResponse
- MarkdownPreviewView
- PopoverSuggest
- BlockCache
- stringifyYaml
- UserEvent
- renderMatches
- SearchMatchPart
- TextFileView
- ViewStateResult
- htmlToMarkdown
- MomentFormatComponent
- RequestUrlParam
- EditorSelection
- EditorSelectionOrCaret
- editorLivePreviewField
Other Related APIs
obsidian#renderMatches TypeScript Examples
The following examples show how to use
obsidian#renderMatches.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: modals.ts From obsidian-citation-plugin with MIT License | 5 votes |
renderSuggestion(match: FuzzyMatch<Entry>, el: HTMLElement): void {
el.empty();
const entry = match.item;
const entryTitle = entry.title || '';
const container = el.createEl('div', { cls: 'zoteroResult' });
const titleEl = container.createEl('span', {
cls: 'zoteroTitle',
});
container.createEl('span', { cls: 'zoteroCitekey', text: entry.id });
const authorsCls = entry.authorString
? 'zoteroAuthors'
: 'zoteroAuthors zoteroAuthorsEmpty';
const authorsEl = container.createEl('span', {
cls: authorsCls,
});
// Prepare to highlight string matches for each part of the search item.
// Compute offsets of each rendered element's content within the string
// returned by `getItemText`.
const allMatches = match.match.matches;
const authorStringOffset = 1 + entryTitle.length;
// Filter a match list to contain only the relevant matches for a given
// substring, and with match indices shifted relative to the start of that
// substring
const shiftMatches = (
matches: SearchMatches,
start: number,
end: number,
) => {
return matches
.map((match: SearchMatchPart) => {
const [matchStart, matchEnd] = match;
return [
matchStart - start,
Math.min(matchEnd - start, end),
] as SearchMatchPart;
})
.filter((match: SearchMatchPart) => {
const [matchStart, matchEnd] = match;
return matchStart >= 0;
});
};
// Now highlight matched strings within each element
renderMatches(
titleEl,
entryTitle,
shiftMatches(allMatches, 0, entryTitle.length),
);
if (entry.authorString) {
renderMatches(
authorsEl,
entry.authorString,
shiftMatches(
allMatches,
authorStringOffset,
authorStringOffset + entry.authorString.length,
),
);
}
}