Created
June 28, 2023 10:57
-
-
Save danihodovic/7a8c55cc53c3d4c4790a08959a96998c to your computer and use it in GitHub Desktop.
Obsidian command palette remap Ctrl+P / Ctrl+J
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; | |
// Remember to rename these classes and interfaces! | |
interface MyPluginSettings { | |
mySetting: string; | |
} | |
const DEFAULT_SETTINGS: MyPluginSettings = { | |
mySetting: 'default' | |
} | |
function isKeyRelevant(document, event) { | |
return document.activeElement && document.activeElement.hasClass('prompt-input') && event.ctrlKey | |
} | |
export default class MyPlugin extends Plugin { | |
settings: MyPluginSettings; | |
async onload() { | |
await this.loadSettings(); | |
document.addEventListener('keydown',(e) =>{ | |
if (isKeyRelevant(document, e) && e.code == "KeyJ"){ | |
e.preventDefault(); | |
document.dispatchEvent(new KeyboardEvent("keydown",{"key":"ArrowDown","code":"ArrowDown"})) | |
} | |
}); | |
document.addEventListener('keydown',(e) =>{ | |
if (isKeyRelevant(document, e) && e.code == "KeyK"){ | |
e.preventDefault(); | |
document.dispatchEvent(new KeyboardEvent("keydown",{"key":"ArrowUp","code":"ArrowUp"})) | |
} | |
}); | |
} | |
onunload() { | |
} | |
async loadSettings() { | |
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); | |
} | |
async saveSettings() { | |
await this.saveData(this.settings); | |
} | |
} | |
class SampleModal extends Modal { | |
constructor(app: App) { | |
super(app); | |
} | |
onOpen() { | |
const {contentEl} = this; | |
contentEl.setText('Woah!'); | |
} | |
onClose() { | |
const {contentEl} = this; | |
contentEl.empty(); | |
} | |
} | |
class SampleSettingTab extends PluginSettingTab { | |
plugin: MyPlugin; | |
constructor(app: App, plugin: MyPlugin) { | |
super(app, plugin); | |
this.plugin = plugin; | |
} | |
display(): void { | |
const {containerEl} = this; | |
containerEl.empty(); | |
containerEl.createEl('h2', {text: 'Settings for my awesome plugin.'}); | |
new Setting(containerEl) | |
.setName('Setting #1') | |
.setDesc('It\'s a secret') | |
.addText(text => text | |
.setPlaceholder('Enter your secret') | |
.setValue(this.plugin.settings.mySetting) | |
.onChange(async (value) => { | |
console.log('Secret: ' + value); | |
this.plugin.settings.mySetting = value; | |
await this.plugin.saveSettings(); | |
})); | |
} | |
} |
Ctrl K does not work, seems. .... it just keep inputting bracket [[(())]]
https://github.com/danihodovic/obsidian-command-palette-keys.git
Use script in this repo, this one works
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ctrl K does not work, seems. .... it just keep inputting bracket [[(())]]