ep_vim 0.12.0 → 0.12.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/static/js/index.js +89 -100
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ep_vim",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Vim-mode plugin for Etherpad with modal editing, motions, and operators",
5
5
  "author": {
6
6
  "name": "Seth Rothschild",
@@ -540,6 +540,8 @@ registerMotion("L", (ctx) => {
540
540
  };
541
541
  });
542
542
 
543
+ // --- Char search motions ---
544
+
543
545
  registerParamMotion("f", (key, ctx) => {
544
546
  const pos = charSearchPos("f", ctx.lineText, ctx.char, key, ctx.count);
545
547
  return pos !== -1 ? pos : null;
@@ -768,6 +770,22 @@ commands["visual-line"]["~"] = (ctx) => {
768
770
  moveBlockCursor(ctx.editorInfo, start[0], start[1]);
769
771
  };
770
772
 
773
+ commands["visual-char"]["i"] = () => {
774
+ state.pendingKey = "i";
775
+ };
776
+
777
+ commands["visual-char"]["a"] = () => {
778
+ state.pendingKey = "a";
779
+ };
780
+
781
+ commands["visual-line"]["i"] = () => {
782
+ state.pendingKey = "i";
783
+ };
784
+
785
+ commands["visual-line"]["a"] = () => {
786
+ state.pendingKey = "a";
787
+ };
788
+
771
789
  commands.normal["gv"] = ({ editorInfo, rep }) => {
772
790
  if (!state.lastVisualSelection) return;
773
791
  const { anchor, cursor, mode } = state.lastVisualSelection;
@@ -777,24 +795,7 @@ commands.normal["gv"] = ({ editorInfo, rep }) => {
777
795
  updateVisualSelection(editorInfo, rep);
778
796
  };
779
797
 
780
- // --- Miscellaneous ---
781
-
782
- commands.normal["u"] = ({ editorInfo }) => {
783
- editorInfo.ace_doUndoRedo("undo");
784
- };
785
-
786
- commands.normal["."] = (ctx) => {
787
- if (!state.lastCommand) return;
788
- const { key, count, param } = state.lastCommand;
789
- if (param !== null && parameterized[key]) {
790
- parameterized[key](param, ctx);
791
- } else if (commands[state.mode] && commands[state.mode][key]) {
792
- const newCtx = { ...ctx, count };
793
- commands[state.mode][key](newCtx);
794
- }
795
- };
796
-
797
- // --- Mode transitions ---
798
+ // --- Insert mode entry ---
798
799
 
799
800
  commands.normal["i"] = ({ editorInfo, line, char }) => {
800
801
  clearEmptyLineCursor();
@@ -820,22 +821,6 @@ commands.normal["I"] = ({ editorInfo, line, lineText }) => {
820
821
  state.mode = "insert";
821
822
  };
822
823
 
823
- commands["visual-char"]["i"] = () => {
824
- state.pendingKey = "i";
825
- };
826
-
827
- commands["visual-char"]["a"] = () => {
828
- state.pendingKey = "a";
829
- };
830
-
831
- commands["visual-line"]["i"] = () => {
832
- state.pendingKey = "i";
833
- };
834
-
835
- commands["visual-line"]["a"] = () => {
836
- state.pendingKey = "a";
837
- };
838
-
839
824
  commands.normal["o"] = ({ editorInfo, line, lineText }) => {
840
825
  clearEmptyLineCursor();
841
826
  replaceRange(
@@ -855,7 +840,7 @@ commands.normal["O"] = ({ editorInfo, line }) => {
855
840
  state.mode = "insert";
856
841
  };
857
842
 
858
- // --- More normal mode commands ---
843
+ // --- Editing commands ---
859
844
 
860
845
  commands.normal["r"] = () => {
861
846
  state.pendingKey = "r";
@@ -1005,6 +990,27 @@ commands.normal["S"] = ({ editorInfo, line, lineText }) => {
1005
990
  recordCommand("S", 1);
1006
991
  };
1007
992
 
993
+ // --- Undo, redo, repeat ---
994
+
995
+ commands.normal["u"] = ({ editorInfo }) => {
996
+ editorInfo.ace_doUndoRedo("undo");
997
+ };
998
+
999
+ commands.normal["<C-r>"] = ({ editorInfo }) => {
1000
+ editorInfo.ace_doUndoRedo("redo");
1001
+ };
1002
+
1003
+ commands.normal["."] = (ctx) => {
1004
+ if (!state.lastCommand) return;
1005
+ const { key, count, param } = state.lastCommand;
1006
+ if (param !== null && parameterized[key]) {
1007
+ parameterized[key](param, ctx);
1008
+ } else if (commands[state.mode] && commands[state.mode][key]) {
1009
+ const newCtx = { ...ctx, count };
1010
+ commands[state.mode][key](newCtx);
1011
+ }
1012
+ };
1013
+
1008
1014
  // --- Search ---
1009
1015
 
1010
1016
  commands.normal["/"] = () => {
@@ -1060,6 +1066,8 @@ commands.normal["#"] = (ctx) => {
1060
1066
  if (pos) moveBlockCursor(ctx.editorInfo, pos[0], pos[1]);
1061
1067
  };
1062
1068
 
1069
+ // --- Scroll ---
1070
+
1063
1071
  commands.normal["zz"] = ({ line }) => {
1064
1072
  if (!state.editorDoc) return;
1065
1073
  const lineDiv = state.editorDoc.body.querySelectorAll("div")[line];
@@ -1078,6 +1086,49 @@ commands.normal["zb"] = ({ line }) => {
1078
1086
  if (lineDiv) lineDiv.scrollIntoView({ block: "end" });
1079
1087
  };
1080
1088
 
1089
+ const halfPage = 15;
1090
+ const fullPage = halfPage * 2;
1091
+
1092
+ commands.normal["<C-d>"] = ({ editorInfo, rep, line, char, count }) => {
1093
+ const target = Math.min(line + halfPage * count, rep.lines.length() - 1);
1094
+ const targetLen = rep.lines.atIndex(target).text.length;
1095
+ moveBlockCursor(
1096
+ editorInfo,
1097
+ target,
1098
+ Math.min(char, Math.max(0, targetLen - 1)),
1099
+ );
1100
+ };
1101
+
1102
+ commands.normal["<C-u>"] = ({ editorInfo, rep, line, char, count }) => {
1103
+ const target = Math.max(line - halfPage * count, 0);
1104
+ const targetLen = rep.lines.atIndex(target).text.length;
1105
+ moveBlockCursor(
1106
+ editorInfo,
1107
+ target,
1108
+ Math.min(char, Math.max(0, targetLen - 1)),
1109
+ );
1110
+ };
1111
+
1112
+ commands.normal["<C-f>"] = ({ editorInfo, rep, line, char, count }) => {
1113
+ const target = Math.min(line + fullPage * count, rep.lines.length() - 1);
1114
+ const targetLen = rep.lines.atIndex(target).text.length;
1115
+ moveBlockCursor(
1116
+ editorInfo,
1117
+ target,
1118
+ Math.min(char, Math.max(0, targetLen - 1)),
1119
+ );
1120
+ };
1121
+
1122
+ commands.normal["<C-b>"] = ({ editorInfo, rep, line, char, count }) => {
1123
+ const target = Math.max(line - fullPage * count, 0);
1124
+ const targetLen = rep.lines.atIndex(target).text.length;
1125
+ moveBlockCursor(
1126
+ editorInfo,
1127
+ target,
1128
+ Math.min(char, Math.max(0, targetLen - 1)),
1129
+ );
1130
+ };
1131
+
1081
1132
  // --- Dispatch ---
1082
1133
 
1083
1134
  const handleKey = (key, ctx) => {
@@ -1303,71 +1354,9 @@ exports.aceKeyEvent = (_hookName, { evt, rep, editorInfo }) => {
1303
1354
  const ctx = { rep, editorInfo, line, char, lineText };
1304
1355
 
1305
1356
  if (useCtrlKeys && evt.ctrlKey && state.mode === "normal") {
1306
- if (state.countBuffer !== "") {
1307
- state.pendingCount = parseInt(state.countBuffer, 10);
1308
- state.countBuffer = "";
1309
- }
1310
- const count = state.pendingCount !== null ? state.pendingCount : 1;
1311
-
1312
- if (evt.key === "r") {
1313
- editorInfo.ace_doUndoRedo("redo");
1314
- state.pendingCount = null;
1315
- state.pendingRegister = null;
1316
- evt.preventDefault();
1317
- return true;
1318
- }
1319
-
1320
- const halfPage = 15;
1321
- if (evt.key === "d") {
1322
- const target = Math.min(line + halfPage * count, rep.lines.length() - 1);
1323
- const targetLen = rep.lines.atIndex(target).text.length;
1324
- moveBlockCursor(
1325
- editorInfo,
1326
- target,
1327
- Math.min(char, Math.max(0, targetLen - 1)),
1328
- );
1329
- state.pendingCount = null;
1330
- state.pendingRegister = null;
1331
- evt.preventDefault();
1332
- return true;
1333
- }
1334
- if (evt.key === "u") {
1335
- const target = Math.max(line - halfPage * count, 0);
1336
- const targetLen = rep.lines.atIndex(target).text.length;
1337
- moveBlockCursor(
1338
- editorInfo,
1339
- target,
1340
- Math.min(char, Math.max(0, targetLen - 1)),
1341
- );
1342
- state.pendingCount = null;
1343
- state.pendingRegister = null;
1344
- evt.preventDefault();
1345
- return true;
1346
- }
1347
- const fullPage = halfPage * 2;
1348
- if (evt.key === "f") {
1349
- const target = Math.min(line + fullPage * count, rep.lines.length() - 1);
1350
- const targetLen = rep.lines.atIndex(target).text.length;
1351
- moveBlockCursor(
1352
- editorInfo,
1353
- target,
1354
- Math.min(char, Math.max(0, targetLen - 1)),
1355
- );
1356
- state.pendingCount = null;
1357
- state.pendingRegister = null;
1358
- evt.preventDefault();
1359
- return true;
1360
- }
1361
- if (evt.key === "b") {
1362
- const target = Math.max(line - fullPage * count, 0);
1363
- const targetLen = rep.lines.atIndex(target).text.length;
1364
- moveBlockCursor(
1365
- editorInfo,
1366
- target,
1367
- Math.min(char, Math.max(0, targetLen - 1)),
1368
- );
1369
- state.pendingCount = null;
1370
- state.pendingRegister = null;
1357
+ const ctrlKey = "<C-" + evt.key + ">";
1358
+ if (commands.normal[ctrlKey]) {
1359
+ handleKey(ctrlKey, ctx);
1371
1360
  evt.preventDefault();
1372
1361
  return true;
1373
1362
  }