-
-
Save NightGlowww/27fa1feade5b9ec6cc218541cee17d1b to your computer and use it in GitHub Desktop.
A small Anki add-on that enables indentation with the Tab key and outdentation with Shift+Tab in the editor.
This file contains hidden or 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
from aqt import gui_hooks, mw | |
from aqt.editor import Editor | |
from aqt.webview import WebContent | |
def on_webview_will_set_content(web_content: WebContent, context: object) -> None: | |
if isinstance(context, Editor): | |
web_content.js.append(f"/_addons/{__name__.split('.')[0]}/indent_with_tab.js") | |
assert mw | |
mw.addonManager.setWebExports(__name__, r".+\.js") | |
gui_hooks.webview_will_set_content.append(on_webview_will_set_content) |
This file contains hidden or 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
document.addEventListener("keydown", (event) => { | |
if (!event.target?.closest(".editor-field")) { | |
return; | |
} | |
if (event.key === "Tab") { | |
if (event.ctrlKey) { | |
return; | |
} | |
event.preventDefault(); | |
if (event.shiftKey) { | |
document.execCommand("outdent"); | |
} else { | |
document.execCommand("indent"); | |
} | |
} | |
}); |
This file contains hidden or 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
{ | |
"name": "Indent with Tab", | |
"package": "indent_with_tab" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment