Skip to content

Conversation

@superle3
Copy link
Collaborator

@superle3 superle3 commented Aug 28, 2025

Resolves #439.
Resolves #400.
Resolves #409.

Rely on @codemirror/view for handling keymaps instead rolling our own. This allows for more customization later on.

I looked at the implementation of https://github.com/codemirror/view/blob/main/src/keymap.ts to see if it was worth it to roll our own keymap handling, but it was a bit too complex to include it, thus this relies on their implementation and adds the scope latex-suite such this extension only triggers it.

Implements [[artisticat1#400](https://github.com/superle3/obsidian-latex-suite/issues/400)](https://github.com/artisticat1/obsidian-latex-suite/issue/400).

This adds an easy framework to add keymaps.
Looking at the implementation of [keymap.ts](https://github.com/codemirror/view/blob/main/src/keymap.ts),
it was clear rolling our own keymap would be more trouble than its
worth,
as a lot of "magic" things were happening there.

Using the default keymap also doesn't work as that has the default
priority and we need the highest priority.
As such we use their api `runScopeHandeler` instead and attach our own
custom scope (the name of this plugin).

This way we only have to standardize the formatting of the `key` instead
of dealing with the complicated `KeyBoardEvent`.

This currently only adds customization for the snippet Trigger key and
the tabout trigger key,
as I haven't seen any feature requests for the other keys  and that
would needlessly add configuration.
}));
new Setting(containerEl)
.setName("Key trigger for tabout")
.setDesc("What key to press to trigger tabout. Key names may be strings like \"Shift-Ctrl-Enter\" a key prefixed with zero or more modifiers. Modifiers can be given in any order. Shift- (or s-), Alt- (or a-), Ctrl- (or c- or Control-), Cmd- (or m- or Meta-) or Mod- (Cmd- on Mac, Ctrl- on Windows/Linux) are recognized. Chords are seperated by a space.")
Copy link
Collaborator Author

@superle3 superle3 Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also not satisfied with this explanation

.addDropdown((dropdown) => dropdown
.addOption("Tab", "Tab")
.addOption(" ", "Space")
.setDesc("What key to press to expand non-auto snippets. Key names may be strings like \"Shift-Ctrl-Enter\" a key prefixed with zero or more modifiers. Modifiers can be given in any order. Shift- (or s-), Alt- (or a-), Ctrl- (or c- or Control-), Cmd- (or m- or Meta-) or Mod- (Cmd- on Mac, Ctrl- on Windows/Linux) are recognized. Chords are seperated by a space.")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not satisfied with this explanation. Am inclined to just point them to the official docs of https://codemirror.net/docs/ref/#view.KeyBinding, but that might be a bit much. Maybe like no explanation here or a small example and mention it in the DOCS.md? since we have to explain the triggerKey there arleady.

flags: optional(string_()),
priority: optional(number()),
description: optional(string_()),
triggerKey: optional(string_()),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the same style here, but defaultvalue and validator could also be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant