MCPcopy
hub / github.com/ajaxorg/ace / handleKeyInsertMode

Function handleKeyInsertMode

src/keyboard/vim.js:1731–1774  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1729 }
1730
1731 function handleKeyInsertMode() {
1732 if (handleEsc()) { return true; }
1733 vim.inputState.keyBuffer.push(key);
1734 var keys = vim.inputState.keyBuffer.join("");
1735 var keysAreChars = key.length == 1;
1736 var match = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
1737 var changeQueue = vim.inputState.changeQueue;
1738
1739 if (match.type == 'none') { clearInputState(cm); return false; }
1740 else if (match.type == 'partial') {
1741 if (match.expectLiteralNext) vim.expectLiteralNext = true;
1742 if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
1743 lastInsertModeKeyTimer = keysAreChars && window.setTimeout(
1744 function() { if (vim.insertMode && vim.inputState.keyBuffer.length) { clearInputState(cm); } },
1745 getOption('insertModeEscKeysTimeout'));
1746 if (keysAreChars) {
1747 var selections = cm.listSelections();
1748 if (!changeQueue || changeQueue.removed.length != selections.length)
1749 changeQueue = vim.inputState.changeQueue = new ChangeQueue;
1750 changeQueue.inserted += key;
1751 for (var i = 0; i < selections.length; i++) {
1752 var from = cursorMin(selections[i].anchor, selections[i].head);
1753 var to = cursorMax(selections[i].anchor, selections[i].head);
1754 var text = cm.getRange(from, cm.state.overwrite ? offsetCursor(to, 0, 1) : to);
1755 changeQueue.removed[i] = (changeQueue.removed[i] || "") + text;
1756 }
1757 }
1758 return !keysAreChars;
1759 }
1760 vim.expectLiteralNext = false;
1761
1762 if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
1763 if (match.command && changeQueue) {
1764 var selections = cm.listSelections();
1765 for (var i = 0; i < selections.length; i++) {
1766 var here = selections[i].head;
1767 cm.replaceRange(changeQueue.removed[i] || "",
1768 offsetCursor(here, 0, -changeQueue.inserted.length), here, '+input');
1769 }
1770 vimGlobalState.macroModeState.lastInsertModeChanges.changes.pop();
1771 }
1772 if (!match.command) clearInputState(cm);
1773 return match.command;
1774 }
1775
1776 function handleKeyNonInsertMode() {
1777 if (handleMacroRecording() || handleEsc()) { return true; }

Callers 1

vim.jsFile · 0.85

Calls 10

handleEscFunction · 0.85
clearInputStateFunction · 0.85
getOptionFunction · 0.85
cursorMinFunction · 0.85
cursorMaxFunction · 0.85
pushMethod · 0.80
getRangeMethod · 0.80
popMethod · 0.80
offsetCursorFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…