mirror of
https://github.com/quorafind/Obsidian-Float-Search.git
synced 2026-07-22 07:30:25 +00:00
chore: update readme
This commit is contained in:
commit
f44be02007
5 changed files with 143 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "float-search",
|
||||
"name": "Floating Search",
|
||||
"version": "3.4.10",
|
||||
"version": "3.5.1",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "You can use search view in modal/leaf/popout window now.",
|
||||
"author": "Boninall",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "float-search",
|
||||
"version": "3.4.10",
|
||||
"version": "3.5.1",
|
||||
"description": "You can use search view in modal/leaf/popout window now.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
addIcon,
|
||||
App,
|
||||
debounce,
|
||||
Editor,
|
||||
ExtraButtonComponent, Keymap,
|
||||
Menu,
|
||||
|
|
@ -11,7 +10,7 @@ import {
|
|||
PaneType,
|
||||
Plugin,
|
||||
Scope,
|
||||
SearchView,
|
||||
SearchView, setIcon, Setting,
|
||||
TAbstractFile,
|
||||
TFile,
|
||||
Workspace,
|
||||
|
|
@ -21,6 +20,7 @@ import {
|
|||
} from 'obsidian';
|
||||
import { EmbeddedView, isEmebeddedLeaf, spawnLeafView } from "./leafView";
|
||||
import { around } from "monkey-around";
|
||||
import { debounce } from "obsidian";
|
||||
|
||||
type sortOrder =
|
||||
"alphabetical"
|
||||
|
|
@ -49,6 +49,7 @@ interface searchState {
|
|||
|
||||
interface FloatSearchSettings {
|
||||
searchViewState: searchState;
|
||||
showFilePath: boolean;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -60,7 +61,8 @@ const DEFAULT_SETTINGS: FloatSearchSettings = {
|
|||
matchingCase: false,
|
||||
query: "",
|
||||
sortOrder: "alphabetical",
|
||||
}
|
||||
},
|
||||
showFilePath: false,
|
||||
};
|
||||
|
||||
const allViews: viewType[] = [{
|
||||
|
|
@ -82,15 +84,15 @@ const allViews: viewType[] = [{
|
|||
|
||||
const initSearchViewWithLeaf = async (app: App, type: PaneType | 'sidebar', state?: searchState) => {
|
||||
const leaf = type === 'sidebar' ? app.workspace.getLeftLeaf(false) : app.workspace.getLeaf(type);
|
||||
leaf.setPinned(type !== 'sidebar');
|
||||
await leaf.setViewState({
|
||||
leaf?.setPinned(type !== 'sidebar');
|
||||
await leaf?.setViewState({
|
||||
type: "search",
|
||||
active: true,
|
||||
state: state
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
const inputEl = leaf.containerEl.getElementsByTagName("input")[0];
|
||||
const inputEl = leaf?.containerEl.getElementsByTagName("input")?.[0];
|
||||
inputEl.focus();
|
||||
}, 0);
|
||||
};
|
||||
|
|
@ -100,6 +102,8 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
private state: any;
|
||||
private modal: FloatSearchModal;
|
||||
|
||||
patchedDomChildren = false;
|
||||
|
||||
public applySettingsUpdate = debounce(async () => {
|
||||
await this.saveSettings();
|
||||
}, 1000);
|
||||
|
|
@ -120,6 +124,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
this.patchWorkspace();
|
||||
this.patchWorkspaceLeaf();
|
||||
this.patchSearchView();
|
||||
this.patchVchildren();
|
||||
});
|
||||
|
||||
this.registerObsidianURIHandler();
|
||||
|
|
@ -128,6 +133,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
this.registerContextMenuHandler();
|
||||
|
||||
this.addRibbonIcon('search', 'Search Obsidian In Modal', () => this.initModal(this.state, true, true));
|
||||
this.updateFilePathVisibility();
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
@ -135,6 +141,18 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
this.modal?.close();
|
||||
}
|
||||
|
||||
updateFilePathVisibility() {
|
||||
const {showFilePath} = this.settings;
|
||||
console.log(showFilePath);
|
||||
document.body.toggleClass("show-file-path", showFilePath);
|
||||
}
|
||||
|
||||
changeFilePathVisibility() {
|
||||
this.settings.showFilePath = !this.settings.showFilePath;
|
||||
this.updateFilePathVisibility();
|
||||
this.applySettingsUpdate();
|
||||
}
|
||||
|
||||
registerIcons() {
|
||||
addIcon('panel-left-inactive', `<path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 4.999687 3 L 19.000312 3 C 20.104688 3 21 3.895312 21 4.999687 L 21 19.000312 C 21 20.104688 20.104688 21 19.000312 21 L 4.999687 21 C 3.895312 21 3 20.104688 3 19.000312 L 3 4.999687 C 3 3.895312 3.895312 3 4.999687 3 Z M 4.999687 3 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 9 13.999688 L 9 15 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 9 19.000312 L 9 21 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 9 3 L 9 4.999687 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 9 9 L 9 10.000312 " transform="matrix(4.166667,0,0,4.166667,0,0)"/>`);
|
||||
addIcon('app-window', `<path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 4.000312 4.000312 L 19.999688 4.000312 C 21.105 4.000312 22.000312 4.895625 22.000312 6 L 22.000312 18 C 22.000312 19.104375 21.105 19.999688 19.999688 19.999688 L 4.000312 19.999688 C 2.895 19.999688 1.999687 19.104375 1.999687 18 L 1.999687 6 C 1.999687 4.895625 2.895 4.000312 4.000312 4.000312 Z M 4.000312 4.000312 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 10.000312 4.000312 L 10.000312 7.999687 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 1.999687 7.999687 L 22.000312 7.999687 " transform="matrix(4.166667,0,0,4.166667,0,0)"/><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:currentColor;stroke-opacity:1;stroke-miterlimit:4;" d="M 6 4.000312 L 6 7.999687 " transform="matrix(4.166667,0,0,4.166667,0,0)"/>`);
|
||||
|
|
@ -172,6 +190,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
}
|
||||
|
||||
const newLeaf = self.app.workspace.getMostRecentLeaf();
|
||||
|
||||
if (newLeaf) {
|
||||
this.setActiveLeaf(newLeaf);
|
||||
}
|
||||
|
|
@ -205,10 +224,12 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
if (layoutChanging) return false; // Don't let HEs close during workspace change
|
||||
|
||||
// 0.14.x doesn't have WorkspaceContainer; this can just be an instanceof check once 15.x is mandatory:
|
||||
|
||||
if (parent === self.app.workspace.rootSplit || (WorkspaceContainer && parent instanceof WorkspaceContainer)) {
|
||||
for (const popover of EmbeddedView.popoversForWindow((parent as WorkspaceContainer).win)) {
|
||||
// Use old API here for compat w/0.14.x
|
||||
if (old.call(this, cb, popover.rootSplit)) return false;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -384,6 +405,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
onOpen(old) {
|
||||
return function () {
|
||||
old.call(this);
|
||||
|
||||
(this.scope as Scope).register(['Mod'], 'w', () => {
|
||||
this.leaf?.detach();
|
||||
});
|
||||
|
|
@ -399,6 +421,16 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
layoutMenu.showAtPosition({x: viewSwitchButtonPos.x, y: viewSwitchButtonPos.y + 30});
|
||||
});
|
||||
targetEl.parentElement.insertBefore(viewSwitchEl, targetEl);
|
||||
if (!this.hidePathToggle) {
|
||||
this.hidePathToggle = new Setting(this.searchParamsContainerEl).setName('Show file path').addToggle((toggle) => {
|
||||
toggle.toggleEl.toggleClass('mod-small', true);
|
||||
toggle.setValue(self.settings.showFilePath).onChange(async (value) => {
|
||||
self.settings.showFilePath = !value;
|
||||
self.changeFilePathVisibility();
|
||||
self.applySettingsUpdate();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
setState(old) {
|
||||
|
|
@ -427,6 +459,52 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
});
|
||||
}
|
||||
|
||||
patchVchildren() {
|
||||
const patchSearchDom = () => {
|
||||
const searchView = this.app.workspace.getLeavesOfType("search")[0]?.view as any;
|
||||
if (!searchView) return false;
|
||||
|
||||
const dom = searchView.dom.constructor;
|
||||
const self = this;
|
||||
|
||||
this.register(
|
||||
around(dom.prototype, {
|
||||
stopLoader(old) {
|
||||
return function () {
|
||||
old.call(this);
|
||||
// console.log(this?.vChildren?.children);
|
||||
this?.vChildren?.children?.forEach((child: any) => {
|
||||
if (child?.file && !child?.pathEl) {
|
||||
const path = (child?.file.parent?.path) || '/';
|
||||
const pathEl = createDiv({cls: "search-result-file-path"});
|
||||
const pathIconEl = pathEl.createDiv({cls: "search-result-file-path-icon"});
|
||||
setIcon(pathIconEl, "folder");
|
||||
const pathTextEl = pathEl.createDiv({
|
||||
cls: "search-result-file-path-text",
|
||||
text: path
|
||||
});
|
||||
child.pathEl = pathEl;
|
||||
const titleEl = child.containerEl.find('.search-result-file-title');
|
||||
titleEl.prepend(pathEl);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
return true;
|
||||
};
|
||||
this.app.workspace.onLayoutReady(() => {
|
||||
if (!patchSearchDom()) {
|
||||
const evt = this.app.workspace.on("layout-change", () => {
|
||||
patchSearchDom() && this.app.workspace.offref(evt);
|
||||
});
|
||||
this.registerEvent(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
registerObsidianURIHandler() {
|
||||
this.registerObsidianProtocolHandler("fs", (path) => this.initModal({
|
||||
...this.state,
|
||||
|
|
@ -461,9 +539,18 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
}
|
||||
|
||||
registerObsidianCommands() {
|
||||
this.addCommand({
|
||||
id: 'show-or-hide-file-path',
|
||||
name: 'Show/hide file path',
|
||||
callback: () => {
|
||||
this.changeFilePathVisibility();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.addCommand({
|
||||
id: 'search-obsidian-globally',
|
||||
name: 'Search Obsidian Globally',
|
||||
name: 'Search obsidian globally',
|
||||
callback: () => this.initModal({...this.state, query: "", current: false}, false, true)
|
||||
});
|
||||
|
||||
|
|
@ -477,7 +564,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
|
||||
this.createCommand({
|
||||
id: 'search-in-backlink',
|
||||
name: 'Search In Backlink Of Current File',
|
||||
name: 'Search in backlink Of current file',
|
||||
queryBuilder: (file) => {
|
||||
return " /\\[\\[" + (file.extension === "canvas" ? file.name : file.basename) + "(\\|[^\\]]*)?\\]\\]/";
|
||||
}
|
||||
|
|
@ -485,7 +572,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
|
||||
this.createCommand({
|
||||
id: 'search-in-current-file',
|
||||
name: 'Search In Current File',
|
||||
name: 'Search in current file',
|
||||
queryBuilder: (file) => {
|
||||
return " path:" + `"${file.path}"`;
|
||||
}
|
||||
|
|
@ -494,7 +581,7 @@ export default class FloatSearchPlugin extends Plugin {
|
|||
for (const type of ['split', 'tab', 'window'] as PaneType[]) {
|
||||
this.addCommand({
|
||||
id: `open-search-view-${type}`,
|
||||
name: `Open Search View (${type})`,
|
||||
name: `Open search view (${type})`,
|
||||
callback: async () => {
|
||||
const existingLeaf = this.app.workspace.getLeavesOfType("search");
|
||||
switch (type) {
|
||||
|
|
@ -706,12 +793,16 @@ class FloatSearchModal extends Modal {
|
|||
if (currentView.dom.focusedItem.collapsible) {
|
||||
currentView.dom.focusedItem.setCollapse(false);
|
||||
}
|
||||
|
||||
this.focusdItem = currentView.dom.focusedItem;
|
||||
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
currentView.onKeyArrowDownInFocus(e);
|
||||
|
||||
this.focusdItem = currentView.dom.focusedItem;
|
||||
|
||||
break;
|
||||
}
|
||||
case "ArrowUp":
|
||||
|
|
@ -721,15 +812,19 @@ class FloatSearchModal extends Modal {
|
|||
if (currentView.dom.focusedItem.collapseEl) {
|
||||
currentView.dom.focusedItem.setCollapse(true);
|
||||
}
|
||||
|
||||
this.focusdItem = currentView.dom.focusedItem;
|
||||
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
currentView.onKeyArrowUpInFocus(e);
|
||||
|
||||
this.focusdItem = currentView.dom.focusedItem;
|
||||
if (!currentView.dom.focusedItem.content) {
|
||||
this.focusdItem = undefined;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "ArrowLeft":
|
||||
|
|
@ -808,6 +903,7 @@ class FloatSearchModal extends Modal {
|
|||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -834,7 +930,6 @@ class FloatSearchModal extends Modal {
|
|||
this.close();
|
||||
break;
|
||||
}
|
||||
|
||||
targetElement = targetElement.parentElement;
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
33
styles.css
33
styles.css
|
|
@ -8,7 +8,6 @@ If your plugin does not need CSS, delete this file.
|
|||
*/
|
||||
.float-search-modal {
|
||||
width: 700px;
|
||||
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
|
|
@ -111,3 +110,35 @@ If your plugin does not need CSS, delete this file.
|
|||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
|
||||
body:not(.show-file-path) .search-result-file-title .search-result-file-path {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.show-file-path .search-result-file-title .search-result-file-path {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: var(--text-muted);
|
||||
font-size: var(--font-ui-smaller);
|
||||
font-weight: var(--font-bolder);
|
||||
margin-right: var(--size-2-2);
|
||||
padding: 1px;
|
||||
padding-left: var(--size-4-2);
|
||||
background-color: var(--background-secondary-alt);
|
||||
padding-right: var(--size-4-2);
|
||||
border-radius: var(--radius-s);
|
||||
|
||||
--icon-size: 12px;
|
||||
}
|
||||
|
||||
.show-file-path .search-result-file-title .search-result-file-path-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: var(--size-2-2);
|
||||
}
|
||||
|
||||
.show-file-path .search-result-file-title .search-result-file-path:hover {
|
||||
background-color: var(--background-secondary);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,5 +27,7 @@
|
|||
"3.4.7": "0.15.0",
|
||||
"3.4.8": "0.15.0",
|
||||
"3.4.9": "0.15.0",
|
||||
"3.4.10": "0.15.0"
|
||||
"3.4.10": "0.15.0",
|
||||
"3.5.0": "0.15.0",
|
||||
"3.5.1": "0.15.0"
|
||||
}
|
||||
Loading…
Reference in a new issue