mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
Added escape character backslash to surround command (#54)
* Added indicators for vim mode and current vim command chord * Added settings page. Fixed custom keybind problems. Desktop only. Added the settings page toggles for the chord and vim mode display. Fixed the custom keybinds not resetting when completing. The "vim-command-done" event seems to be not registering them. Maybe a problem with initialization of the keys? Changed the plugin to be desktop only. It's unlikely that someone could use this on mobile, and cmEditor is deprecated and will only work on desktop for now. * Added command for surrounding current selection with strings * Hotfix: cleanup forgotten code * Added surround command and cleaned up * Added surround action * Cleaned up, changed var to let, added pasteinto ex command * Attempt to fix surround bug * Fixed bad merge * Attempt fix for surround desync * Fixed pasteinto * Fixed README Moved `Mapping Obsidian Commands Within Vim` back to where it belongs. * Actually fixed README this time. * Added escape character '\' to surround
This commit is contained in:
parent
6c493b804b
commit
5b908f54aa
1 changed files with 9 additions and 3 deletions
12
main.ts
12
main.ts
|
|
@ -300,11 +300,17 @@ export default class VimrcPlugin extends Plugin {
|
|||
defineSurround(vimObject: any) {
|
||||
// Function to surround selected text or highlighted word.
|
||||
var surroundFunc = (cm: CodeMirror.Editor, params: any) => {
|
||||
if (!params?.args?.length || params.args.length != 2) {
|
||||
if (!params?.args?.length) {
|
||||
throw new Error("surround requires exactly 2 parameters: prefix and postfix text.")
|
||||
}
|
||||
let beginning = params.args[0] // Get the beginning surround text
|
||||
let ending = params.args[1] // Get the ending surround text
|
||||
let newArgs = params.args.join(" ").match(/(\\.|[^\s\\\\]+)+/g)
|
||||
if (newArgs.length != 2) {
|
||||
throw new Error("surround requires exactly 2 parameters: prefix and postfix text.")
|
||||
}
|
||||
|
||||
let beginning = newArgs[0].replace("\\\\", "\\").replace("\\ ", " ") // Get the beginning surround text
|
||||
let ending = newArgs[1].replace("\\\\", "\\").replace("\\ ", " ") // Get the ending surround text
|
||||
|
||||
let currentSelection: CodeMirror.Range = this.currentSelection[0]
|
||||
if (this.currentSelection.length > 1) {
|
||||
console.log("WARNING: Multiple selections in surround. Attempt to select matching cursor. (obsidian-vimrc-support)")
|
||||
|
|
|
|||
Loading…
Reference in a new issue