Add option for vim keymap in codemirror (#2475)

This commit is contained in:
DHMike57
2021-12-26 12:24:18 +00:00
committed by GitHub
parent 265401775b
commit ae951bfe23
6 changed files with 5756 additions and 3 deletions

View File

@@ -1,7 +1,15 @@
import mimeTypesService from "../../services/mime_types.js";
import options from "../../services/options.js";
import server from "../../services/server.js";
import toastService from "../../services/toast.js";
import utils from "../../services/utils.js";
const TPL = `
<h4>Use vim keybindings in CodeNotes (no ex mode)</h4>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="vim-keymap-enabled">
<label class="custom-control-label" for="vim-keymap-enabled">Enable Vim Keybindings</label>
</div>
<h4>Available MIME types in the dropdown</h4>
<ul id="options-mime-types" style="max-height: 500px; overflow: auto; list-style-type: none;"></ul>`;
@@ -10,12 +18,18 @@ export default class CodeNotesOptions {
constructor() {
$("#options-code-notes").html(TPL);
this.$vimKeymapEnabled = $("#vim-keymap-enabled");
this.$vimKeymapEnabled.on('change', () => {
const opts = { 'vimKeymapEnabled': this.$vimKeymapEnabled.is(":checked") ? "true" : "false" };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
});
this.$mimeTypes = $("#options-mime-types");
}
async optionsLoaded() {
async optionsLoaded(options) {
this.$mimeTypes.empty();
this.$vimKeymapEnabled.prop("checked", options['vimKeymapEnabled'] === 'true');
let idCtr = 1;
for (const mimeType of await mimeTypesService.getMimeTypes()) {
@@ -45,4 +59,4 @@ export default class CodeNotesOptions {
mimeTypesService.loadMimeTypes();
}
}
}