-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable visual snippets for vim #359
base: main
Are you sure you want to change the base?
Conversation
Tested this, and can confirm basic functionality is working. I can't speak for code quality, but I'd love to see something added to Also, for what it's worth, I personally think this fits in perfectly fine into this plugin, and doesn't need to be put into something else. |
looked a bit more into unmap and map and changed descriptions accordingly. Also added ? for the undocumented objects, since im just copying that from the vimrc plugin and I have no idea what their behavior is. Also removed setting keyword from settings tab to comply with obsidian guidelines. But behavior is the same so amended it. Okay after checking edit: edit2: will add an explanation to the visual snippets in the |
also would like to add #352. Would do it in a seperate PR, but I wouldn't be able to reuse my current code for that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small wording changes to new documentation. Newline logic working perfectly - I'll spend some time using this PR on my main vault to see if I encounter any bugs.
Now if (!runMatrixShortcuts(view, ctx, "Enter", false)) {
cm.getInputField().dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
} but that changes the behaviour of I would expect it to keep the current indentation regardless if the line is empty, but The code below does work instead of pressing the enter key. import {insertNewlineAndIndent} from "@codemirror/commands"
newlineAndIndent: function (cm: CodeMirror) {
insertNewlineAndIndent({
state: cm.cm6.state,
dispatch: (tr) => {
return dispatchChange(cm, tr);
}
})
function dispatchChange(cm: CodeMirror, transaction: any) {
var view = cm.cm6;
if (view.state.readOnly)
return;
var type = "input.type.compose";
if (cm.curOp) {
if (!cm.curOp.lastChange) type = "input.type.compose.start";
}
if (transaction.annotations) {
try {
transaction.annotations.some(function (note: any) {
if (note.value == "input") note.value = type;
});
} catch (e) {
console.error(e);
}
} else {
transaction.userEvent = type;
}
return view.dispatch(transaction)
} |
I couldn't find out the reason for this code from the documentation of both codemirror and the vim plugin. There is a slight change from the code a both. insertmode is entered after a newline has been added since otherwise macros would behave weird and the annotations are only changed if its an array. I don't know why there is a try catch but im guessing it has a reason. |
f88e921
to
be91eb6
Compare
forgot to unmap the old keymappings when vim keybindings are turned off. Everything should be good now. Edit: I don't think it should work in inline math, since no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline behavior working perfectly for me, thank you!
For the type safety it would probably be better to use https://github.com/Fevol/obsidian-typings for the untyped objects. But the methods of the |
edit: ignore that. |
Use the vimapi from codemirror to define 2 actions: "from visual mode to insert mode" and "from insert mode to visual mode" while selecting something. This exposes the visual snippets to vim users who want to use vim visual mode to select something. Its only enabled if vim itself is enabled and maps these "actions" to the vim extension itself and not to hotkeys of obsidian. This enables more complex Also implemented better wording for the vim docs suggested by Co-authored-by: Eman Resu <78693624+llakala@users.noreply.github.com>
give the option to redefine the `insert new line below` to also append a \\ at end of the current line in a matrix environment. The enter is handled by simulating a enter press call. The cursor is moved to the current line and collum = line.length + 1. This may have unwanted consequences, other option would be to handle the key with vim but that relies on the vim keymap.
This PR tries to somewhat implement #44 by adding a keybinding to swap between
keymap
vim-insert
andvim-visual
without losing the current selection.It's implemented as a setting instead of an hotkey such that more complex commands like
<C-g><C-g>
are possible.The setting is turned off by default and can only be turned on if obsidians vim mode is on.
Its referred to as SelectMode in the settings, because vim's selectmode is something similair to selecting in
vim-insert
in codemirror, but not the same. For example visualblock and visualline are not retained after switching only the selection and maybe more things, but just tries to expose thevim-insert
keymap while invim-visual
, not emulating vim's actual selectmode.The vim object is behind untyped objects from obsidian so I copied the types from the original codemirror vim project (https://github.com/replit/codemirror-vim), but these have a lot of any in them so its not that great.
Also this may not be the right plugin for this PR, I understand if its better suited for https://github.com/esm7/obsidian-vimrc-support/tree/master or the vim extension itself.
at last, first time using ts/js, sorry for potential bad code quality