Skip to content

Commit

Permalink
release: 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Dec 7, 2023
1 parent fd0afd6 commit ee12615
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -28,4 +31,4 @@
"@lezer/common": "^1.1.0",
"monkey-around": "^2.3.0"
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
16 changes: 12 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuiltInSuggestItem> & { manager: PopoverManager<BuiltInSuggestItem> };
export type Suggester<T> = ISuggestOwner<T> & OpenableComponent & CloseableComponent & { scope: Scope };
Expand Down Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/popoverManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class PopoverManager<T> 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 });
}
};
}
12 changes: 12 additions & 0 deletions src/typings/items.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ee12615

Please sign in to comment.