MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / repeatInsertModeChanges

Function repeatInsertModeChanges

lib/web/CodeMirror/keymap/vim.js:5670–5708  ·  view source on GitHub ↗
(cm, changes, repeat)

Source from the content-addressed store, hash-verified

5668 }
5669
5670 function repeatInsertModeChanges(cm, changes, repeat) {
5671 function keyHandler(binding) {
5672 if (typeof binding == 'string') {
5673 CodeMirror.commands[binding](cm);
5674 } else {
5675 binding(cm);
5676 }
5677 return true;
5678 }
5679 var head = cm.getCursor('head');
5680 var visualBlock = vimGlobalState.macroModeState.lastInsertModeChanges.visualBlock;
5681 if (visualBlock) {
5682 // Set up block selection again for repeating the changes.
5683 selectForInsert(cm, head, visualBlock + 1);
5684 repeat = cm.listSelections().length;
5685 cm.setCursor(head);
5686 }
5687 for (var i = 0; i < repeat; i++) {
5688 if (visualBlock) {
5689 cm.setCursor(offsetCursor(head, i, 0));
5690 }
5691 for (var j = 0; j < changes.length; j++) {
5692 var change = changes[j];
5693 if (change instanceof InsertModeKey) {
5694 CodeMirror.lookupKey(change.keyName, 'vim-insert', keyHandler);
5695 } else if (typeof change == "string") {
5696 var cur = cm.getCursor();
5697 cm.replaceRange(change, cur, cur);
5698 } else {
5699 var start = cm.getCursor();
5700 var end = offsetCursor(start, 0, change[0].length);
5701 cm.replaceRange(change[0], start, end);
5702 }
5703 }
5704 }
5705 if (visualBlock) {
5706 cm.setCursor(offsetCursor(head, 0, 1));
5707 }
5708 }
5709
5710 resetVimGlobalState();
5711 return vimApi;

Callers 2

executeMacroRegisterFunction · 0.85
repeatInsertFunction · 0.85

Calls 3

selectForInsertFunction · 0.85
replaceRangeMethod · 0.80
offsetCursorFunction · 0.70

Tested by

no test coverage detected