Custom editor keymap

AnkiWeb addon 617159433

Customizes editor keyboard shortcuts to insert characters, HTML, JavaScript, or file contents based on configured key-and-modifier mappings, including Arrow+Alt symbols.
AI-generated summary; may contain mistakes.

shortcutsobsolete

Open on AnkiWeb Forum topic Find alternatives

AnkiWeb

Votes
1 (πŸ‘ 1 Β· πŸ‘Ž 0)
Updated
2021-10-13
Anki versions
2.1.46~
License
Not found (this does not mean that the addon has no license)
Virus scan
No ClamAV match A match does not prove malware. No match does not prove that the code is safe.
Languages
Python, JSON
Description language
en

Maintenance

abandoned

  • Last update or commit: 2021-10-13 (1845 days before the snapshot).

GitHub

No GitHub repository linked.

Will it work on my Anki?

Version branches
Min AnkiMax AnkiUpdated
2.1.46+2021-10-13
History across monthly snapshots

Loading…

Similar addons

Add Table has 1 fork β†’

Inserts customizable HTML tables through a dialog or keyboard shortcut, or converts selected pipe-delimited markdown-like text into a table; it does not edit existing tables.

formattingshortcutsfork-or-reupload

144 votes 93% approval πŸ‘ 140 Β· πŸ‘Ž 4 ⭐ 7 Anki 2.1.65~ Updated 2023-06-18

Description

*** NOTICE *** This addon has been superseded by Editor Scripts & Symbols It has been pointed out to me that equivalent functionality is already available through https://ankiweb.net/shared/info/1899278645 and https://ankiweb.net/shared/info/396502676 so this addon is superfluous. Oh well, it is here now and functioning as far as I can tell, Use at your own peril. Allows customizing the editor keymap, i.e. what character(s) are inserted on the press of a specific key and modifiers. Example: configure ArrowRight+Alt to insert "β†’" symbol.
  • Configuration in Toolsβ†’Add-onsβ†’Custom editor keymapβ†’Config.
  • The key is the javascript KeyboardEvent.key. The easiest way is to use https://keycode.info or similar to find key name (use event.key). <nop> as key will result in key-value pair being ignored.
  • The value is any string (including HTML) that will be inserted. Empty string ("") will result in nothing being inserted and no further processing of the event in the javascript.
  • The key to map must be first, then any modifiers (Shift, Ctrl, Alt, AltGraph, Meta) joined with "+", ex. ArrowLeft+Shift+Alt.
  • Additional modifier HTML will insert the character(s) as HTML (default is text), i.e. <b>FAT</b> inserted as HTML will be rendered as FAT while inserted as text will rendered as <b>FAT</b>.
  • Additional modifier is CMD will do a javascript eval() of the value
  • .
  • Additional modifier FILE, which will interpret the value as a file name (path based in add-on directory) and use the file contents as value.
  • Removing the key-value pair entirely will leave the "default"/normal mapping intact.
  • There is minimal error checking of the config.
  • Replacement is done in javascript in the editor fields (the addon injects javascript on editor_will_load_note). The key event will be processed by Anki before reaching the js (for instance mapping "b+Ctrl": "sample" will result in bold state being toggled before insertion of sample).
Sample config content { "<nop>": "", "ArrowRight+Alt": "β†’", "ArrowRight+Alt+Shift": "β‡’", "ArrowLeft+Alt": "←", "ArrowLeft+Alt+Shift": "⇐", "ArrowUp+Alt": "↑", "ArrowUp+Alt+Shift": "⇑", "ArrowDown+Alt": "↓", "ArrowDown+Alt+Shift": "⇓", "ArrowLeft+Ctrl+Alt+Shift": "↔", "ArrowRight+Ctrl+Alt+Shift": "⇔", "F7+CMD": "var t = document.activeElement.shadowRoot.innerHTML.match(/(?<={{c)\\\\d+(?=::)/g) || [\"0\"]; wrap(\"{{c\" + (Math.max.apply(null, t.map(i=>Number(i))) + 1) + \"::\", \"}}\");", "X+Ctrl+Shift+Alt+CMD": "var els = document.activeElement.shadowRoot.querySelectorAll(\"div, p, span\"); els.forEach(el => { if(!el.hasAttributes()) { var par = el.parentNode; while (el.firstChild) par.insertBefore(el.firstChild, el); par.removeChild(el); } });" } CHANGELOG
  • 2021-10-30 Added modifier FILE. Primary use case is combining with CMD to easier create more complex JS stored in a file with sensible formatting (the JSON of the config file doesn't allow line breaks). Note that the quoting of the file is not 100% robust (the file contents are stored in a variable using JS backtick string so using backticks in the file might mess things up). This is effectively the equivalent of "JS snippets", suggested way to write these are:
    • Install AnkiWebView Inspector (https://ankiweb.net/shared/info/31746032)
    • Develop and test the script in the inspector console (no need to restart Anki, try parts etc.)
    • Copy-paste into file in CEK add-on directory
    • Insert shortcut with FILE and CMD modifiers and the filename as value
  • 2021-10-13 Added sample js not because it changes the addon but I thought it may be useful for others that want to strip unnecessary/blank div, p and span tags that gets inserted sometimes (only strips those tags that have no attributes set and inserts the content in the parent) - use at your own risk.
  • 2021-10-08 Added modifier CMD.