This commit is contained in:
Erez Shermer 2020-11-11 09:55:12 +02:00
parent c11a4c19ec
commit ec26c32d4e
4 changed files with 15 additions and 4 deletions

View file

@ -37,3 +37,10 @@ Things I'd love to add:
- Implement some standard `vim-markdown` motions for Obsidian, e.g. `[[`, or implement for CodeMirror the 1-2 missing Ex commands required to define these keymaps in the Vimrc.
- Relative line numbers.
## Changelog
### 0.1.1
Fixed [an issue](https://github.com/esm7/obsidian-vimrc-support/issues/2) caused by the plugin injecting the Vimrc on every file load.
The plugin now injects the Vimrc just once for the CodeMirror class (for the class -- not object instance, because that's where CodeMirror keeps the Vim settings.)
This seems to work well, but in theory there could be Vimrc settings that are CodeMirror-object bound and not class-bound, and in that case we'll be in trouble (these settings will be lost when Obsidian replaces CodeMirror objects).

View file

@ -21,14 +21,18 @@ export default class MyPlugin extends Plugin {
if (view.getViewType() == 'markdown') {
var markdownView = view as MarkdownView;
var cmEditor = markdownView.sourceMode.cmEditor;
if (cmEditor) {
if (cmEditor && !CodeMirror.Vim.loadedVimrc) {
vimCommands.split("\n").forEach(
function(line, index, arr) {
if (line.length > 0) {
CodeMirror.Vim.handleEx(cmEditor, line)
CodeMirror.Vim.handleEx(cmEditor, line);
}
}
)
// Make sure that we load it just once per CodeMirror instance.
// This is supposed to work because the Vim state is kept at the keymap level, hopefully
// there will not be bugs caused by operations that are kept at the object level instead
CodeMirror.Vim.loadedVimrc = true;
}
}
}

View file

@ -1,7 +1,7 @@
{
"id": "obsidian-vimrc-support",
"name": "Obsidian Vimrc Support",
"version": "0.1.0",
"version": "0.1.1",
"description": "Auto-load a startup file with Obsidian Vim commands.",
"author": "esm",
"authorUrl": "",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-vimrc-support",
"version": "0.1.0",
"version": "0.1.1",
"description": "Auto-load a startup file with Obsidian Vim commands.",
"main": "main.js",
"scripts": {