Skip to content

Commit

Permalink
release: 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Feb 18, 2024
1 parent 1fb1153 commit 1746cba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "command-blacklist",
"name": "Command Blacklist",
"version": "0.1.1",
"version": "0.1.2",
"minAppVersion": "1.3.5",
"description": "Hide unwanted commands from the command palette.",
"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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-command-blacklist",
"version": "0.1.1",
"version": "0.1.2",
"description": "An Obsidian.md plugin to hide unwanted commands from the command palette.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export default class MyPlugin extends Plugin {
await this.saveSettings();
this.addSettingTab(new SampleSettingTab(this));

const plugin = this;
const blacklist = this.settings.blacklist;

this.register(around(this.app.commands.constructor.prototype, {
listCommands(old) {
return function (...args: any[]) {
const commands: Command[] = old.call(this, ...args);
return commands.filter((command) => !plugin.settings.blacklist.includes(command.id));
return commands.filter((command) => !blacklist.includes(command.id));
}
}
}));
Expand Down
37 changes: 19 additions & 18 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbstractInputSuggest, Command, IconName, PluginSettingTab, SearchResultContainer, Setting, prepareFuzzySearch, setIcon, sortSearchResults, setTooltip } from 'obsidian';

import MyPlugin from 'main';


Expand Down Expand Up @@ -26,7 +27,8 @@ class CommandSuggest extends AbstractInputSuggest<Command> {

getSuggestions(query: string) {
const search = prepareFuzzySearch(query);
const commands = Object.values(this.plugin.app.commands.commands);
const commands = Object.values(this.plugin.app.commands.commands)
.filter((command) => !this.plugin.settings.blacklist.includes(command.id));

const results: (SearchResultContainer & { command: Command })[] = [];

Expand Down Expand Up @@ -96,15 +98,6 @@ export class SampleSettingTab extends PluginSettingTab {
display(): void {
this.containerEl.empty();

this.settings.blacklist.sort((a, b) => {
const cmdA = this.app.commands.findCommand(a);
const cmdB = this.app.commands.findCommand(b);
if (cmdA === undefined) return cmdB === undefined ? 0 : 1;
else if (cmdB === undefined) return -1;

return cmdA.name.localeCompare(cmdB.name);
});

this.addSetting()
.setDesc('List the commands you want to blacklist. These commands will not be shown in the command palette.')
.addExtraButton((button) => {
Expand All @@ -126,10 +119,10 @@ export class SampleSettingTab extends PluginSettingTab {

text.inputEl.size = 40;
new CommandSuggest(this, text.inputEl)
.then((cmd) => {
this.settings.blacklist[i] = cmd.id;
this.redisplay();
});
.then((cmd) => {
this.settings.blacklist[i] = cmd.id;
this.redisplay();
});
})
.addExtraButton((button) => {
button
Expand All @@ -144,10 +137,18 @@ export class SampleSettingTab extends PluginSettingTab {
}

hide() {
this.settings.blacklist = this.settings.blacklist.filter((id) => {
const command = this.app.commands.findCommand(id);
return command !== undefined;
});
this.settings.blacklist = this.settings.blacklist
.filter((id) => {
const command = this.app.commands.findCommand(id);
return command !== undefined;
})
.sort((a, b) => {
const cmdA = this.app.commands.findCommand(a)!;
const cmdB = this.app.commands.findCommand(b)!;

return cmdA.name.localeCompare(cmdB.name);
});

this.plugin.saveSettings();
}
}

0 comments on commit 1746cba

Please sign in to comment.