ArianaKhit / text-snippets-obsidian

Snippets plugin for obsidian
177 stars 21 forks source link

Fix tab and space not working in WYSIWYG #53

Open SekoiaTree opened 1 year ago

SekoiaTree commented 1 year ago

Disclaimer: I translated this code back and forth from typescript.

I have tested this on Legacy mode and it works, but these edits fix it for latest version. The code for legacy is essentially copied from current.

Fixes #19, fixes #25 (maybe?), fixes #37 (maybe?), fixes #47 and fixes #52

The way this works is by using this.registerDomEvent instead of CodeMirror edits. The key down event now also checks whether the current window is a markdown view, so you can't have accidental replaces in any other areas. If that's actually wanted, feel free to remove it (or make it a setting, although I haven't seen a place where the distinction would actually be relevant)

Arax20 commented 1 year ago

Tested and works for me, although I wonder if registerDomEvent is the cleanest way of capturing keypresses.

I've seen advanced tables use registerEditorExtension for CM6 which might keep the behaviour localized to the editor.

SekoiaTree commented 1 year ago

Oh yeah that'd definitely work too. I might try and do that but I'm quite busy atm so yeah