diff --git a/README.md b/README.md index fdbcb61..703c15a 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ I couldn't find a formal list anywhere but you can look for `defaultExCommandMap In addition to that: - The plugin skips blank lines and lines starting with Vimscript comments (`" ...`). - Special support for yanking to system clipboard can be activated by `set clipboard=unnamed` (`unnamedplus` will do the same thing). +- Support for the `tabstop` Vim option (e.g. `set tabstop=4`). Commands that fail don't generate any visible error for now. @@ -54,6 +55,11 @@ Things I'd love to add: ## Changelog +### 0.2.1 + +- Fixed [this issue](https://github.com/esm7/obsidian-vimrc-support/issues/7): setting `clipboard=unnamed` also works for pasting now (it monitors the system clipboard and updates the yank buffer if a change is detected). +- Support for the `tabstop` Vim option as asked [here](https://github.com/esm7/obsidian-vimrc-support/issues/3). + ### 0.2.0 Added support for yanking to system clipboard (see above), comments and blank lines. diff --git a/main.ts b/main.ts index 2f718c6..26e9826 100644 --- a/main.ts +++ b/main.ts @@ -2,6 +2,7 @@ import { App, Plugin, TFile, MarkdownView } from 'obsidian'; export default class VimrcPlugin extends Plugin { private lastYankBuffer = new Array(0); + private lastSystemClipboard = ""; private yankToSystemClipboard: boolean = false; onload() { @@ -17,10 +18,12 @@ export default class VimrcPlugin extends Plugin { this.registerDomEvent(document, 'click', () => { this.captureYankBuffer(); }); - this.registerDomEvent(document, 'keyup', () => { this.captureYankBuffer(); }); + this.registerDomEvent(document, 'focusin', () => { + this.captureYankBuffer(); + }) } onunload() { @@ -45,6 +48,11 @@ export default class VimrcPlugin extends Plugin { } } }); + CodeMirror.Vim.defineOption('tabstop', 4, 'number', [], (value, cm) => { + if (value) { + cmEditor.setOption('tabSize', value); + } + }); vimCommands.split("\n").forEach( function(line, index, arr) { @@ -67,9 +75,19 @@ export default class VimrcPlugin extends Plugin { if (currentBuffer != this.lastYankBuffer) { if (this.lastYankBuffer.length > 0 && currentBuffer.length > 0 && currentBuffer[0]) { navigator.clipboard.writeText(currentBuffer[0]); + this.lastSystemClipboard = currentBuffer[0]; } this.lastYankBuffer = currentBuffer; + return; } + let currentClipboard = navigator.clipboard.readText().then((value) => { + if (value != this.lastSystemClipboard) { + let yankRegister = CodeMirror.Vim.getRegisterController().getRegister('yank') + yankRegister.setText(value); + this.lastYankBuffer = yankRegister.keyBuffer; + this.lastSystemClipboard = value; + } + }) } } } diff --git a/manifest.json b/manifest.json index ad3d25d..1d29d34 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-vimrc-support", "name": "Obsidian Vimrc Support", - "version": "0.2.0", + "version": "0.2.1", "description": "Auto-load a startup file with Obsidian Vim commands.", "author": "esm", "authorUrl": "", diff --git a/package.json b/package.json index ce982e8..b645e2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-vimrc-support", - "version": "0.2.0", + "version": "0.2.1", "description": "Auto-load a startup file with Obsidian Vim commands.", "main": "main.js", "scripts": {