ep_vim 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,8 +29,6 @@ A vim-mode plugin for [Etherpad](https://etherpad.org/). Adds modal editing with
29
29
 
30
30
  ## Differences from vi
31
31
 
32
- - **Ctrl key mapping** — browser shortcuts conflict with common vim bindings (`Ctrl+d`, `Ctrl+u`, `Ctrl+r`, etc.); These will be implemented under a configurable setting.
33
- - **Clipboard toggle** — the default register writes to the system clipboard. We will add a setting to turn on the default vim behavior.
34
32
  - **No command line, macros, or globals** - these are not planned, but PRs welcome.
35
33
 
36
34
  ## Installation
package/ep.json CHANGED
@@ -9,7 +9,8 @@
9
9
  "postToolbarInit": "ep_vim/static/js/index"
10
10
  },
11
11
  "hooks": {
12
- "eejsBlock_editbarMenuLeft": "ep_vim/index"
12
+ "eejsBlock_editbarMenuLeft": "ep_vim/index",
13
+ "eejsBlock_mySettings": "ep_vim/index"
13
14
  }
14
15
  }
15
16
  ]
package/index.js CHANGED
@@ -6,3 +6,8 @@ exports.eejsBlock_editbarMenuLeft = (hook, args, cb) => {
6
6
  args.content += eejs.require('ep_vim/templates/editbarButtons.ejs');
7
7
  return cb();
8
8
  };
9
+
10
+ exports.eejsBlock_mySettings = (_hook, args, cb) => {
11
+ args.content += eejs.require('ep_vim/templates/settings.ejs');
12
+ return cb();
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ep_vim",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Vim-mode plugin for Etherpad with modal editing, motions, and operators",
5
5
  "author": {
6
6
  "name": "Seth Rothschild",
@@ -30,6 +30,9 @@ let vimEnabled =
30
30
  typeof localStorage !== "undefined" &&
31
31
  localStorage.getItem("ep_vimEnabled") === "true";
32
32
 
33
+ let useSystemClipboard = true;
34
+ let useCtrlKeys = true;
35
+
33
36
  const state = {
34
37
  mode: "normal",
35
38
  pendingKey: null,
@@ -66,7 +69,7 @@ const setRegister = (value) => {
66
69
  }
67
70
  state.register = value;
68
71
  const text = Array.isArray(value) ? value.join("\n") + "\n" : value;
69
- if (navigator.clipboard) {
72
+ if (useSystemClipboard && navigator.clipboard) {
70
73
  navigator.clipboard.writeText(text).catch(() => {});
71
74
  }
72
75
  };
@@ -1162,6 +1165,22 @@ exports.postToolbarInit = (_hookName, _args) => {
1162
1165
  localStorage.setItem("ep_vimEnabled", vimEnabled ? "true" : "false");
1163
1166
  btn.classList.toggle("vim-enabled", vimEnabled);
1164
1167
  });
1168
+
1169
+ const clipboardCheckbox = document.getElementById(
1170
+ "options-vim-use-system-clipboard",
1171
+ );
1172
+ if (!clipboardCheckbox) return;
1173
+ useSystemClipboard = clipboardCheckbox.checked;
1174
+ clipboardCheckbox.addEventListener("change", () => {
1175
+ useSystemClipboard = clipboardCheckbox.checked;
1176
+ });
1177
+
1178
+ const ctrlKeysCheckbox = document.getElementById("options-vim-use-ctrl-keys");
1179
+ if (!ctrlKeysCheckbox) return;
1180
+ useCtrlKeys = ctrlKeysCheckbox.checked;
1181
+ ctrlKeysCheckbox.addEventListener("change", () => {
1182
+ useCtrlKeys = ctrlKeysCheckbox.checked;
1183
+ });
1165
1184
  };
1166
1185
 
1167
1186
  exports.postAceInit = (_hookName, { ace }) => {
@@ -1181,7 +1200,10 @@ exports.aceKeyEvent = (_hookName, { evt, rep, editorInfo }) => {
1181
1200
 
1182
1201
  const isBrowserShortcut =
1183
1202
  (evt.ctrlKey || evt.metaKey) &&
1184
- (evt.key === "x" || evt.key === "c" || evt.key === "v" || evt.key === "r");
1203
+ (evt.key === "x" ||
1204
+ evt.key === "c" ||
1205
+ evt.key === "v" ||
1206
+ (evt.key === "r" && !useCtrlKeys));
1185
1207
  if (isBrowserShortcut) return false;
1186
1208
 
1187
1209
  state.currentRep = rep;
@@ -1247,6 +1269,51 @@ exports.aceKeyEvent = (_hookName, { evt, rep, editorInfo }) => {
1247
1269
  : rep.selStart;
1248
1270
  const lineText = rep.lines.atIndex(line).text;
1249
1271
  const ctx = { rep, editorInfo, line, char, lineText };
1272
+
1273
+ if (useCtrlKeys && evt.ctrlKey && state.mode === "normal") {
1274
+ if (state.countBuffer !== "") {
1275
+ state.pendingCount = parseInt(state.countBuffer, 10);
1276
+ state.countBuffer = "";
1277
+ }
1278
+ const count = state.pendingCount !== null ? state.pendingCount : 1;
1279
+
1280
+ if (evt.key === "r") {
1281
+ editorInfo.ace_doUndoRedo("redo");
1282
+ state.pendingCount = null;
1283
+ state.pendingRegister = null;
1284
+ evt.preventDefault();
1285
+ return true;
1286
+ }
1287
+
1288
+ const halfPage = 15;
1289
+ if (evt.key === "d") {
1290
+ const target = Math.min(line + halfPage * count, rep.lines.length() - 1);
1291
+ const targetLen = rep.lines.atIndex(target).text.length;
1292
+ moveBlockCursor(
1293
+ editorInfo,
1294
+ target,
1295
+ Math.min(char, Math.max(0, targetLen - 1)),
1296
+ );
1297
+ state.pendingCount = null;
1298
+ state.pendingRegister = null;
1299
+ evt.preventDefault();
1300
+ return true;
1301
+ }
1302
+ if (evt.key === "u") {
1303
+ const target = Math.max(line - halfPage * count, 0);
1304
+ const targetLen = rep.lines.atIndex(target).text.length;
1305
+ moveBlockCursor(
1306
+ editorInfo,
1307
+ target,
1308
+ Math.min(char, Math.max(0, targetLen - 1)),
1309
+ );
1310
+ state.pendingCount = null;
1311
+ state.pendingRegister = null;
1312
+ evt.preventDefault();
1313
+ return true;
1314
+ }
1315
+ }
1316
+
1250
1317
  const handled = handleKey(evt.key, ctx);
1251
1318
  if (handled) evt.preventDefault();
1252
1319
  return handled;
@@ -0,0 +1,8 @@
1
+ <p>
2
+ <input type="checkbox" id="options-vim-use-system-clipboard" checked></input>
3
+ <label for="options-vim-use-system-clipboard">Use system clipboard (vim)</label>
4
+ </p>
5
+ <p>
6
+ <input type="checkbox" id="options-vim-use-ctrl-keys" checked></input>
7
+ <label for="options-vim-use-ctrl-keys">Use Ctrl keys (vim)</label>
8
+ </p>