diff --git a/manifest.json b/manifest.json index c028acb..2b7143c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "enhanced-link-suggestions", "name": "Enhanced Link Suggestions", - "version": "0.3.0", + "version": "0.3.1", "minAppVersion": "1.3.5", "description": "Upgrade Obsidian's built-in link suggestions with quick preview & block markdown rendering.", "author": "Ryota Ushio", diff --git a/package-lock.json b/package-lock.json index d8e1d0a..1ae3b66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-enhanced-link-suggestions", - "version": "0.3.0", + "version": "0.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-enhanced-link-suggestions", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "dependencies": { "@codemirror/language": "^6.9.1", diff --git a/package.json b/package.json index 113713e..3139540 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,12 @@ { "name": "obsidian-enhanced-link-suggestions", - "version": "0.3.0", + "version": "0.3.1", "description": "Upgrade Obsidian's built-in link suggestions with quick preview & block markdown rendering.", "main": "lib/index.js", - "types": "lib/index.d.ts", + "types": "lib/index.d.ts", + "files": [ + "lib/**/*" + ], "scripts": { "dev": "node esbuild.config.mjs", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", @@ -28,4 +31,4 @@ "@lezer/common": "^1.1.0", "monkey-around": "^2.3.0" } -} +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f510048..d3bc2b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export { type Suggester, type SuggestItem } from "main"; +export { type FileInfo, type HeadingInfo, type BlockInfo } from 'typings/items'; import EnhancedLinkSuggestionsPlugin, { SuggestItem, Suggester } from "main"; import { App, Component } from "obsidian"; diff --git a/src/main.ts b/src/main.ts index 0898132..d7f4a1c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,11 +4,11 @@ import { around } from 'monkey-around'; import { DEFAULT_SETTINGS, EnhancedLinkSuggestionsSettings, EnhancedLinkSuggestionsSettingTab } from 'settings'; import { PopoverManager } from 'popoverManager'; import { extractFirstNLines, getSelectedItem, render } from 'utils'; -import { BlockLinkInfo, FileInfo, FileLinkInfo, HeadingLinkInfo } from 'typings/items'; +import { BlockInfo, BlockLinkInfo, FileInfo, FileLinkInfo, HeadingInfo, HeadingLinkInfo, QuickSwitcherItem } from 'typings/items'; import { OpenableComponent } from 'typings/openable'; -export type SuggestItem = FileInfo | HeadingLinkInfo | BlockLinkInfo; +export type SuggestItem = FileInfo | HeadingInfo | BlockInfo; export type BuiltInSuggestItem = FileLinkInfo | HeadingLinkInfo | BlockLinkInfo; export type BuiltInSuggest = EditorSuggest & { manager: PopoverManager }; export type Suggester = ISuggestOwner & OpenableComponent & CloseableComponent & { scope: Scope }; @@ -39,9 +39,17 @@ export default class EnhancedLinkSuggestionsPlugin extends Plugin { this.app.workspace.onLayoutReady(() => { this.patchRenderSuggestion(); this.patchSetSelectedItem(); + const itemNormalizer = (item: BuiltInSuggestItem | QuickSwitcherItem): SuggestItem => { + if (item.type !== "block") return item as SuggestItem; + return { + type: "block", + file: item.file, + line: item.node.position.start.line, + }; + } // @ts-ignore - this.patch(this.getSuggest().constructor); - this.patch(this.app.internalPlugins.getPluginById('switcher').instance.QuickSwitcherModal); + this.patch(this.getSuggest().constructor, itemNormalizer); + this.patch(this.app.internalPlugins.getPluginById('switcher').instance.QuickSwitcherModal, itemNormalizer); }); } diff --git a/src/popoverManager.ts b/src/popoverManager.ts index b23dbb6..1d0ed78 100644 --- a/src/popoverManager.ts +++ b/src/popoverManager.ts @@ -65,7 +65,7 @@ export class PopoverManager extends Component { } else if (item.type === 'heading') { this.plugin.onLinkHover(this.currentHoverParent, null, item.file.path + '#' + stripHeadingForLink(item.heading), ""); } else if (item.type === 'block') { - this.plugin.onLinkHover(this.currentHoverParent, null, item.file.path, "", { scroll: item.node.position.start.line }); + this.plugin.onLinkHover(this.currentHoverParent, null, item.file.path, "", { scroll: item.line }); } }; } \ No newline at end of file diff --git a/src/typings/items.d.ts b/src/typings/items.d.ts index 356cf24..91cb7e2 100644 --- a/src/typings/items.d.ts +++ b/src/typings/items.d.ts @@ -5,6 +5,18 @@ export interface FileInfo { file: TFile; } +export interface HeadingInfo { + type: "heading"; + file: TFile; + heading: string; +} + +export interface BlockInfo { + type: "block"; + file: TFile; + line: number; +} + export interface QuickSwitcherItem extends FileInfo { match: any; downranked?: boolean;