Skip to content

Commit

Permalink
Use Obsidian search controls (w/"x" to cancel)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby committed May 15, 2021
1 parent c9daeb5 commit 226740f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
40 changes: 27 additions & 13 deletions main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "hotkey-helper",
"name": "Hotkey Helper",
"version": "0.3.3",
"version": "0.3.4",
"minAppVersion": "0.12.3",
"description": "Easily see and access any plugin's settings or hotkey assignments (and conflicts) from the Community Plugins tab",
"author": "PJ Eby",
Expand Down
38 changes: 26 additions & 12 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,22 @@ function onElement(el, event, selector, callback, options=false) {
export default class HotkeyHelper extends Plugin {

onload() {
const workspace = this.app.workspace;
const workspace = this.app.workspace, plugin = this;

this.registerEvent( workspace.on("plugin-settings:before-display", (settingsTab, tabId) => {
this.hotkeyButtons = {};
this.configButtons = {};
this.globalsAdded = false;
this.searchInput = null;
const remove = around(Setting.prototype, {
addSearch(old) { return function(f) {
remove();
return old.call(this, i => {
plugin.searchInput = i; f?.(i);
})
}}
});
setImmediate(remove);
}) );
this.registerEvent( workspace.on("plugin-settings:after-display", () => this.refreshButtons(true)) );

Expand Down Expand Up @@ -162,16 +172,20 @@ export default class HotkeyHelper extends Plugin {
let inputEl;
if (tabId !== "plugins") {
// Replace the built-in search handler
const original = inputEl = containerEl.parentElement?.find(".search-input-container input")
if (original) {
inputEl = original.cloneNode();
original.parentElement.replaceChild(inputEl, original);
}
this.searchInput?.onChange(changeHandler);
inputEl = this.searchInput?.inputEl;
} else {
let search;
const tmp = new Setting(containerEl).addSearch(s => {
search = s;
s.setPlaceholder("Filter plugins...").onChange(changeHandler);
});
inputEl = search.inputEl;
search.containerEl.style.margin = 0;
containerEl.createDiv("hotkey-search-container").append(search.containerEl);
tmp.settingEl.detach();
}
inputEl = inputEl ?? containerEl.createDiv("hotkey-search-container").createEl(
"input", {type: "text", attr: {placeholder:"Filter plugins...", spellcheck: "false"}}
);
inputEl.addEventListener("input", function(){
function changeHandler(){
const find = inputEl.value.toLowerCase();
function matchAndHighlight(el) {
const text = el.textContent = el.textContent; // clear previous highlighting, if any
Expand All @@ -190,8 +204,8 @@ export default class HotkeyHelper extends Plugin {
);
e.toggle(nameMatches || descMatches);
});
});
setImmediate(() => {inputEl.focus()});
}
setImmediate(() => {inputEl?.focus()});
containerEl.append(settingEl);

if (tabId === "plugins") {
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"0.3.3": "0.12.3",
"0.3.4": "0.12.3",
"0.3.0": "0.12.1",
"0.2.1": "0.11.13",
"0.1.1": "0.11.3"
Expand Down

0 comments on commit 226740f

Please sign in to comment.