code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function getIndex(ranges, cursor, end) { for (var i = 0; i < ranges.length; i++) { var atAnchor = end != 'head' && cursorEqual(ranges[i].anchor, cursor); var atHead = end != 'anchor' && cursorEqual(ranges[i].head, cursor); if (atAnchor || atHead) { return i; } } return -1; }
Clips cursor to ensure that line is within the buffer's range If includeLineBreak is true, then allow cur.ch == lineLength.
getIndex
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function getSelectedAreaRange(cm, vim) { var lastSelection = vim.lastSelection; var getCurrentSelectedAreaRange = function () { var selections = cm.listSelections(); var start = selections[0]; var end = selections[selections.length - 1]; var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head; var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor; return [selectionStart, selectionEnd]; }; var getLastSelectedAreaRange = function () { var selectionStart = cm.getCursor(); var selectionEnd = cm.getCursor(); var block = lastSelection.visualBlock; if (block) { var width = block.width; var height = block.height; selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width); var selections = []; // selectBlock creates a 'proper' rectangular block. // We do not want that in all cases, so we manually set selections. for (var i = selectionStart.line; i < selectionEnd.line; i++) { var anchor = Pos(i, selectionStart.ch); var head = Pos(i, selectionEnd.ch); var range = { anchor: anchor, head: head }; selections.push(range); } cm.setSelections(selections); } else { var start = lastSelection.anchorMark.find(); var end = lastSelection.headMark.find(); var line = end.line - start.line; var ch = end.ch - start.ch; selectionEnd = { line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch }; if (lastSelection.visualLine) { selectionStart = Pos(selectionStart.line, 0); selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line)); } cm.setSelection(selectionStart, selectionEnd); } return [selectionStart, selectionEnd]; }; if (!vim.visualMode) { // In case of replaying the action. return getLastSelectedAreaRange(); } else { return getCurrentSelectedAreaRange(); } }
Clips cursor to ensure that line is within the buffer's range If includeLineBreak is true, then allow cur.ch == lineLength.
getSelectedAreaRange
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
getCurrentSelectedAreaRange = function () { var selections = cm.listSelections(); var start = selections[0]; var end = selections[selections.length - 1]; var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head; var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor; return [selectionStart, selectionEnd]; }
Clips cursor to ensure that line is within the buffer's range If includeLineBreak is true, then allow cur.ch == lineLength.
getCurrentSelectedAreaRange
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
getLastSelectedAreaRange = function () { var selectionStart = cm.getCursor(); var selectionEnd = cm.getCursor(); var block = lastSelection.visualBlock; if (block) { var width = block.width; var height = block.height; selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width); var selections = []; // selectBlock creates a 'proper' rectangular block. // We do not want that in all cases, so we manually set selections. for (var i = selectionStart.line; i < selectionEnd.line; i++) { var anchor = Pos(i, selectionStart.ch); var head = Pos(i, selectionEnd.ch); var range = { anchor: anchor, head: head }; selections.push(range); } cm.setSelections(selections); } else { var start = lastSelection.anchorMark.find(); var end = lastSelection.headMark.find(); var line = end.line - start.line; var ch = end.ch - start.ch; selectionEnd = { line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch }; if (lastSelection.visualLine) { selectionStart = Pos(selectionStart.line, 0); selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line)); } cm.setSelection(selectionStart, selectionEnd); } return [selectionStart, selectionEnd]; }
Clips cursor to ensure that line is within the buffer's range If includeLineBreak is true, then allow cur.ch == lineLength.
getLastSelectedAreaRange
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function updateLastSelection(cm, vim) { var anchor = vim.sel.anchor; var head = vim.sel.head; // To accommodate the effect of lastPastedText in the last selection if (vim.lastPastedText) { head = cm.posFromIndex(cm.indexFromPos(anchor) + vim.lastPastedText.length); vim.lastPastedText = null; } vim.lastSelection = { anchorMark: cm.setBookmark(anchor), headMark: cm.setBookmark(head), anchor: copyCursor(anchor), head: copyCursor(head), visualMode: vim.visualMode, visualLine: vim.visualLine, visualBlock: vim.visualBlock, }; }
Clips cursor to ensure that line is within the buffer's range If includeLineBreak is true, then allow cur.ch == lineLength.
updateLastSelection
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function expandSelection(cm, start, end) { var sel = cm.state.vim.sel; var head = sel.head; var anchor = sel.anchor; var tmp; if (cursorIsBefore(end, start)) { tmp = end; end = start; start = tmp; } if (cursorIsBefore(head, anchor)) { head = cursorMin(start, head); anchor = cursorMax(anchor, end); } else { anchor = cursorMin(start, anchor); head = cursorMax(head, end); head = offsetCursor(head, 0, -1); if (head.ch == -1 && head.line != cm.firstLine()) { head = Pos(head.line - 1, lineLength(cm, head.line - 1)); } } return [anchor, head]; }
Clips cursor to ensure that line is within the buffer's range If includeLineBreak is true, then allow cur.ch == lineLength.
expandSelection
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function updateCmSelection(cm, sel, mode) { var vim = cm.state.vim; sel = sel || vim.sel; var mode = mode || vim.visualLine ? 'line' : vim.visualBlock ? 'block' : 'char'; var cmSel = makeCmSelection(cm, sel, mode); cm.setSelections(cmSel.ranges, cmSel.primary); updateFakeCursor(cm); }
Updates the CodeMirror selection to match the provided vim selection. If no arguments are given, it uses the current vim selection state.
updateCmSelection
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function makeCmSelection(cm, sel, mode, exclusive) { var head = copyCursor(sel.head); var anchor = copyCursor(sel.anchor); if (mode == 'char') { var headOffset = !exclusive && !cursorIsBefore(sel.head, sel.anchor) ? 1 : 0; var anchorOffset = cursorIsBefore(sel.head, sel.anchor) ? 1 : 0; head = offsetCursor(sel.head, 0, headOffset); anchor = offsetCursor(sel.anchor, 0, anchorOffset); return { ranges: [{ anchor: anchor, head: head }], primary: 0, }; } else if (mode == 'line') { if (!cursorIsBefore(sel.head, sel.anchor)) { anchor.ch = 0; var lastLine = cm.lastLine(); if (head.line > lastLine) { head.line = lastLine; } head.ch = lineLength(cm, head.line); } else { head.ch = 0; anchor.ch = lineLength(cm, anchor.line); } return { ranges: [{ anchor: anchor, head: head }], primary: 0, }; } else if (mode == 'block') { var top = Math.min(anchor.line, head.line), left = Math.min(anchor.ch, head.ch), bottom = Math.max(anchor.line, head.line), right = Math.max(anchor.ch, head.ch) + 1; var height = bottom - top + 1; var primary = head.line == top ? 0 : height - 1; var ranges = []; for (var i = 0; i < height; i++) { ranges.push({ anchor: Pos(top + i, left), head: Pos(top + i, right), }); } return { ranges: ranges, primary: primary, }; } }
Updates the CodeMirror selection to match the provided vim selection. If no arguments are given, it uses the current vim selection state.
makeCmSelection
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function getHead(cm) { var cur = cm.getCursor('head'); if (cm.getSelection().length == 1) { // Small corner case when only 1 character is selected. The "real" // head is the left of head and anchor. cur = cursorMin(cur, cm.getCursor('anchor')); } return cur; }
Updates the CodeMirror selection to match the provided vim selection. If no arguments are given, it uses the current vim selection state.
getHead
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function exitVisualMode(cm, moveHead) { var vim = cm.state.vim; if (moveHead !== false) { cm.setCursor(clipCursorToContent(cm, vim.sel.head)); } updateLastSelection(cm, vim); vim.visualMode = false; vim.visualLine = false; vim.visualBlock = false; if (!vim.insertMode) CodeMirror.signal(cm, 'vim-mode-change', { mode: 'normal' }); clearFakeCursor(vim); }
If moveHead is set to false, the CodeMirror selection will not be touched. The caller assumes the responsibility of putting the cursor in the right place.
exitVisualMode
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function clipToLine(cm, curStart, curEnd) { var selection = cm.getRange(curStart, curEnd); // Only clip if the selection ends with trailing newline + whitespace if (/\n\s*$/.test(selection)) { var lines = selection.split('\n'); // We know this is all whitespace. lines.pop(); // Cases: // 1. Last word is an empty line - do not clip the trailing '\n' // 2. Last word is not an empty line - clip the trailing '\n' var line; // Find the line containing the last word, and clip all whitespace up // to it. for (var line = lines.pop(); lines.length > 0 && line && isWhiteSpaceString(line); line = lines.pop()) { curEnd.line--; curEnd.ch = 0; } // If the last word is not an empty line, clip an additional newline if (line) { curEnd.line--; curEnd.ch = lineLength(cm, curEnd.line); } else { curEnd.ch = 0; } } }
If moveHead is set to false, the CodeMirror selection will not be touched. The caller assumes the responsibility of putting the cursor in the right place.
clipToLine
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function expandSelectionToLine(_cm, curStart, curEnd) { curStart.ch = 0; curEnd.ch = 0; curEnd.line++; }
If moveHead is set to false, the CodeMirror selection will not be touched. The caller assumes the responsibility of putting the cursor in the right place.
expandSelectionToLine
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findFirstNonWhiteSpaceCharacter(text) { if (!text) { return 0; } var firstNonWS = text.search(/\S/); return firstNonWS == -1 ? text.length : firstNonWS; }
If moveHead is set to false, the CodeMirror selection will not be touched. The caller assumes the responsibility of putting the cursor in the right place.
findFirstNonWhiteSpaceCharacter
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function expandWordUnderCursor(cm, inclusive, _forward, bigWord, noSymbol) { var cur = getHead(cm); var line = cm.getLine(cur.line); var idx = cur.ch; // Seek to first word or non-whitespace character, depending on if // noSymbol is true. var test = noSymbol ? wordCharTest[0] : bigWordCharTest[0]; while (!test(line.charAt(idx))) { idx++; if (idx >= line.length) { return null; } } if (bigWord) { test = bigWordCharTest[0]; } else { test = wordCharTest[0]; if (!test(line.charAt(idx))) { test = wordCharTest[1]; } } var end = idx, start = idx; while (test(line.charAt(end)) && end < line.length) { end++; } while (test(line.charAt(start)) && start >= 0) { start--; } start++; if (inclusive) { // If present, include all whitespace after word. // Otherwise, include all whitespace before word, except indentation. var wordEnd = end; while (/\s/.test(line.charAt(end)) && end < line.length) { end++; } if (wordEnd == end) { var wordStart = start; while (/\s/.test(line.charAt(start - 1)) && start > 0) { start--; } if (!start) { start = wordStart; } } } return { start: Pos(cur.line, start), end: Pos(cur.line, end) }; }
If moveHead is set to false, the CodeMirror selection will not be touched. The caller assumes the responsibility of putting the cursor in the right place.
expandWordUnderCursor
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function expandTagUnderCursor(cm, head, inclusive) { var cur = head; if (!CodeMirror.findMatchingTag || !CodeMirror.findEnclosingTag) { return { start: cur, end: cur }; } var tags = CodeMirror.findMatchingTag(cm, head) || CodeMirror.findEnclosingTag(cm, head); if (!tags || !tags.open || !tags.close) { return { start: cur, end: cur }; } if (inclusive) { return { start: tags.open.from, end: tags.close.to }; } return { start: tags.open.to, end: tags.close.from }; }
Depends on the following: - editor mode should be htmlmixedmode / xml - mode/xml/xml.js should be loaded - addon/fold/xml-fold.js should be loaded If any of the above requirements are not true, this function noops. This is _NOT_ a 100% accurate implementation of vim tag text objects. The following caveats apply (based off cursory testing, I'm sure there are other discrepancies): - Does not work inside comments: ``` <!-- <div>broken</div> --> ``` - Does not work when tags have different cases: ``` <div>broken</DIV> ``` - Does not work when cursor is inside a broken tag: ``` <div><brok><en></div> ```
expandTagUnderCursor
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function recordJumpPosition(cm, oldCur, newCur) { if (!cursorEqual(oldCur, newCur)) { vimGlobalState.jumpList.add(cm, oldCur, newCur); } }
Depends on the following: - editor mode should be htmlmixedmode / xml - mode/xml/xml.js should be loaded - addon/fold/xml-fold.js should be loaded If any of the above requirements are not true, this function noops. This is _NOT_ a 100% accurate implementation of vim tag text objects. The following caveats apply (based off cursory testing, I'm sure there are other discrepancies): - Does not work inside comments: ``` <!-- <div>broken</div> --> ``` - Does not work when tags have different cases: ``` <div>broken</DIV> ``` - Does not work when cursor is inside a broken tag: ``` <div><brok><en></div> ```
recordJumpPosition
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function recordLastCharacterSearch(increment, args) { vimGlobalState.lastCharacterSearch.increment = increment; vimGlobalState.lastCharacterSearch.forward = args.forward; vimGlobalState.lastCharacterSearch.selectedCharacter = args.selectedCharacter; }
Depends on the following: - editor mode should be htmlmixedmode / xml - mode/xml/xml.js should be loaded - addon/fold/xml-fold.js should be loaded If any of the above requirements are not true, this function noops. This is _NOT_ a 100% accurate implementation of vim tag text objects. The following caveats apply (based off cursory testing, I'm sure there are other discrepancies): - Does not work inside comments: ``` <!-- <div>broken</div> --> ``` - Does not work when tags have different cases: ``` <div>broken</DIV> ``` - Does not work when cursor is inside a broken tag: ``` <div><brok><en></div> ```
recordLastCharacterSearch
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findSymbol(cm, repeat, forward, symb) { var cur = copyCursor(cm.getCursor()); var increment = forward ? 1 : -1; var endLine = forward ? cm.lineCount() : -1; var curCh = cur.ch; var line = cur.line; var lineText = cm.getLine(line); var state = { lineText: lineText, nextCh: lineText.charAt(curCh), lastCh: null, index: curCh, symb: symb, reverseSymb: (forward ? { ')': '(', '}': '{' } : { '(': ')', '{': '}' })[symb], forward: forward, depth: 0, curMoveThrough: false, }; var mode = symbolToMode[symb]; if (!mode) return cur; var init = findSymbolModes[mode].init; var isComplete = findSymbolModes[mode].isComplete; if (init) { init(state); } while (line !== endLine && repeat) { state.index += increment; state.nextCh = state.lineText.charAt(state.index); if (!state.nextCh) { line += increment; state.lineText = cm.getLine(line) || ''; if (increment > 0) { state.index = 0; } else { var lineLen = state.lineText.length; state.index = lineLen > 0 ? lineLen - 1 : 0; } state.nextCh = state.lineText.charAt(state.index); } if (isComplete(state)) { cur.line = line; cur.ch = state.index; repeat--; } } if (state.nextCh || state.curMoveThrough) { return Pos(line, state.index); } return cur; }
Depends on the following: - editor mode should be htmlmixedmode / xml - mode/xml/xml.js should be loaded - addon/fold/xml-fold.js should be loaded If any of the above requirements are not true, this function noops. This is _NOT_ a 100% accurate implementation of vim tag text objects. The following caveats apply (based off cursory testing, I'm sure there are other discrepancies): - Does not work inside comments: ``` <!-- <div>broken</div> --> ``` - Does not work when tags have different cases: ``` <div>broken</DIV> ``` - Does not work when cursor is inside a broken tag: ``` <div><brok><en></div> ```
findSymbol
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findWord(cm, cur, forward, bigWord, emptyLineIsWord) { var lineNum = cur.line; var pos = cur.ch; var line = cm.getLine(lineNum); var dir = forward ? 1 : -1; var charTests = bigWord ? bigWordCharTest : wordCharTest; if (emptyLineIsWord && line == '') { lineNum += dir; line = cm.getLine(lineNum); if (!isLine(cm, lineNum)) { return null; } pos = forward ? 0 : line.length; } while (true) { if (emptyLineIsWord && line == '') { return { from: 0, to: 0, line: lineNum }; } var stop = dir > 0 ? line.length : -1; var wordStart = stop, wordEnd = stop; // Find bounds of next word. while (pos != stop) { var foundWord = false; for (var i = 0; i < charTests.length && !foundWord; ++i) { if (charTests[i](line.charAt(pos))) { wordStart = pos; // Advance to end of word. while (pos != stop && charTests[i](line.charAt(pos))) { pos += dir; } wordEnd = pos; foundWord = wordStart != wordEnd; if (wordStart == cur.ch && lineNum == cur.line && wordEnd == wordStart + dir) { // We started at the end of a word. Find the next one. continue; } else { return { from: Math.min(wordStart, wordEnd + 1), to: Math.max(wordStart, wordEnd), line: lineNum, }; } } } if (!foundWord) { pos += dir; } } // Advance to next/prev line. lineNum += dir; if (!isLine(cm, lineNum)) { return null; } line = cm.getLine(lineNum); pos = dir > 0 ? 0 : line.length; } }
Depends on the following: - editor mode should be htmlmixedmode / xml - mode/xml/xml.js should be loaded - addon/fold/xml-fold.js should be loaded If any of the above requirements are not true, this function noops. This is _NOT_ a 100% accurate implementation of vim tag text objects. The following caveats apply (based off cursory testing, I'm sure there are other discrepancies): - Does not work inside comments: ``` <!-- <div>broken</div> --> ``` - Does not work when tags have different cases: ``` <div>broken</DIV> ``` - Does not work when cursor is inside a broken tag: ``` <div><brok><en></div> ```
findWord
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function moveToWord(cm, cur, repeat, forward, wordEnd, bigWord) { var curStart = copyCursor(cur); var words = []; if ((forward && !wordEnd) || (!forward && wordEnd)) { repeat++; } // For 'e', empty lines are not considered words, go figure. var emptyLineIsWord = !(forward && wordEnd); for (var i = 0; i < repeat; i++) { var word = findWord(cm, cur, forward, bigWord, emptyLineIsWord); if (!word) { var eodCh = lineLength(cm, cm.lastLine()); words.push(forward ? { line: cm.lastLine(), from: eodCh, to: eodCh } : { line: 0, from: 0, to: 0 }); break; } words.push(word); cur = Pos(word.line, forward ? word.to - 1 : word.from); } var shortCircuit = words.length != repeat; var firstWord = words[0]; var lastWord = words.pop(); if (forward && !wordEnd) { // w if (!shortCircuit && (firstWord.from != curStart.ch || firstWord.line != curStart.line)) { // We did not start in the middle of a word. Discard the extra word at the end. lastWord = words.pop(); } return Pos(lastWord.line, lastWord.from); } else if (forward && wordEnd) { return Pos(lastWord.line, lastWord.to - 1); } else if (!forward && wordEnd) { // ge if (!shortCircuit && (firstWord.to != curStart.ch || firstWord.line != curStart.line)) { // We did not start in the middle of a word. Discard the extra word at the end. lastWord = words.pop(); } return Pos(lastWord.line, lastWord.to); } else { // b return Pos(lastWord.line, lastWord.from); } }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
moveToWord
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function moveToEol(cm, head, motionArgs, vim, keepHPos) { var cur = head; var retval = Pos(cur.line + motionArgs.repeat - 1, Infinity); var end = cm.clipPos(retval); end.ch--; if (!keepHPos) { vim.lastHPos = Infinity; vim.lastHSPos = cm.charCoords(end, 'div').left; } return retval; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
moveToEol
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function moveToCharacter(cm, repeat, forward, character) { var cur = cm.getCursor(); var start = cur.ch; var idx; for (var i = 0; i < repeat; i++) { var line = cm.getLine(cur.line); idx = charIdxInLine(start, line, character, forward, true); if (idx == -1) { return null; } start = idx; } return Pos(cm.getCursor().line, idx); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
moveToCharacter
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function moveToColumn(cm, repeat) { // repeat is always >= 1, so repeat - 1 always corresponds // to the column we want to go to. var line = cm.getCursor().line; return clipCursorToContent(cm, Pos(line, repeat - 1)); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
moveToColumn
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function updateMark(cm, vim, markName, pos) { if (!inArray(markName, validMarks)) { return; } if (vim.marks[markName]) { vim.marks[markName].clear(); } vim.marks[markName] = cm.setBookmark(pos); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
updateMark
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function charIdxInLine(start, line, character, forward, includeChar) { // Search for char in line. // motion_options: {forward, includeChar} // If includeChar = true, include it too. // If forward = true, search forward, else search backwards. // If char is not found on this line, do nothing var idx; if (forward) { idx = line.indexOf(character, start + 1); if (idx != -1 && !includeChar) { idx -= 1; } } else { idx = line.lastIndexOf(character, start - 1); if (idx != -1 && !includeChar) { idx += 1; } } return idx; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
charIdxInLine
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findParagraph(cm, head, repeat, dir, inclusive) { var line = head.line; var min = cm.firstLine(); var max = cm.lastLine(); var start, end, i = line; function isEmpty(i) { return !cm.getLine(i); } function isBoundary(i, dir, any) { if (any) { return isEmpty(i) != isEmpty(i + dir); } return !isEmpty(i) && isEmpty(i + dir); } if (dir) { while (min <= i && i <= max && repeat > 0) { if (isBoundary(i, dir)) { repeat--; } i += dir; } return new Pos(i, 0); } var vim = cm.state.vim; if (vim.visualLine && isBoundary(line, 1, true)) { var anchor = vim.sel.anchor; if (isBoundary(anchor.line, -1, true)) { if (!inclusive || anchor.line != line) { line += 1; } } } var startState = isEmpty(line); for (i = line; i <= max && repeat; i++) { if (isBoundary(i, 1, true)) { if (!inclusive || isEmpty(i) != startState) { repeat--; } } } end = new Pos(i, 0); // select boundary before paragraph for the last one if (i > max && !startState) { startState = true; } else { inclusive = false; } for (i = line; i > min; i--) { if (!inclusive || isEmpty(i) == startState || i == line) { if (isBoundary(i, -1, true)) { break; } } } start = new Pos(i, 0); return { start: start, end: end }; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
findParagraph
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function isEmpty(i) { return !cm.getLine(i); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
isEmpty
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function isBoundary(i, dir, any) { if (any) { return isEmpty(i) != isEmpty(i + dir); } return !isEmpty(i) && isEmpty(i + dir); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
isBoundary
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findSentence(cm, cur, repeat, dir) { /* Takes an index object { line: the line string, ln: line number, pos: index in line, dir: direction of traversal (-1 or 1) } and modifies the line, ln, and pos members to represent the next valid position or sets them to null if there are no more valid positions. */ function nextChar(cm, idx) { if (idx.pos + idx.dir < 0 || idx.pos + idx.dir >= idx.line.length) { idx.ln += idx.dir; if (!isLine(cm, idx.ln)) { idx.line = null; idx.ln = null; idx.pos = null; return; } idx.line = cm.getLine(idx.ln); idx.pos = idx.dir > 0 ? 0 : idx.line.length - 1; } else { idx.pos += idx.dir; } } /* Performs one iteration of traversal in forward direction Returns an index object of the new location */ function forward(cm, ln, pos, dir) { var line = cm.getLine(ln); var stop = line === ''; var curr = { line: line, ln: ln, pos: pos, dir: dir, }; var last_valid = { ln: curr.ln, pos: curr.pos, }; var skip_empty_lines = curr.line === ''; // Move one step to skip character we start on nextChar(cm, curr); while (curr.line !== null) { last_valid.ln = curr.ln; last_valid.pos = curr.pos; if (curr.line === '' && !skip_empty_lines) { return { ln: curr.ln, pos: curr.pos }; } else if (stop && curr.line !== '' && !isWhiteSpaceString(curr.line[curr.pos])) { return { ln: curr.ln, pos: curr.pos }; } else if ( isEndOfSentenceSymbol(curr.line[curr.pos]) && !stop && (curr.pos === curr.line.length - 1 || isWhiteSpaceString(curr.line[curr.pos + 1])) ) { stop = true; } nextChar(cm, curr); } /* Set the position to the last non whitespace character on the last valid line in the case that we reach the end of the document. */ var line = cm.getLine(last_valid.ln); last_valid.pos = 0; for (var i = line.length - 1; i >= 0; --i) { if (!isWhiteSpaceString(line[i])) { last_valid.pos = i; break; } } return last_valid; } /* Performs one iteration of traversal in reverse direction Returns an index object of the new location */ function reverse(cm, ln, pos, dir) { var line = cm.getLine(ln); var curr = { line: line, ln: ln, pos: pos, dir: dir, }; var last_valid = { ln: curr.ln, pos: null, }; var skip_empty_lines = curr.line === ''; // Move one step to skip character we start on nextChar(cm, curr); while (curr.line !== null) { if (curr.line === '' && !skip_empty_lines) { if (last_valid.pos !== null) { return last_valid; } else { return { ln: curr.ln, pos: curr.pos }; } } else if ( isEndOfSentenceSymbol(curr.line[curr.pos]) && last_valid.pos !== null && !(curr.ln === last_valid.ln && curr.pos + 1 === last_valid.pos) ) { return last_valid; } else if (curr.line !== '' && !isWhiteSpaceString(curr.line[curr.pos])) { skip_empty_lines = false; last_valid = { ln: curr.ln, pos: curr.pos }; } nextChar(cm, curr); } /* Set the position to the first non whitespace character on the last valid line in the case that we reach the beginning of the document. */ var line = cm.getLine(last_valid.ln); last_valid.pos = 0; for (var i = 0; i < line.length; ++i) { if (!isWhiteSpaceString(line[i])) { last_valid.pos = i; break; } } return last_valid; } var curr_index = { ln: cur.line, pos: cur.ch, }; while (repeat > 0) { if (dir < 0) { curr_index = reverse(cm, curr_index.ln, curr_index.pos, dir); } else { curr_index = forward(cm, curr_index.ln, curr_index.pos, dir); } repeat--; } return Pos(curr_index.ln, curr_index.pos); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
findSentence
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function nextChar(cm, idx) { if (idx.pos + idx.dir < 0 || idx.pos + idx.dir >= idx.line.length) { idx.ln += idx.dir; if (!isLine(cm, idx.ln)) { idx.line = null; idx.ln = null; idx.pos = null; return; } idx.line = cm.getLine(idx.ln); idx.pos = idx.dir > 0 ? 0 : idx.line.length - 1; } else { idx.pos += idx.dir; } }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
nextChar
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function forward(cm, ln, pos, dir) { var line = cm.getLine(ln); var stop = line === ''; var curr = { line: line, ln: ln, pos: pos, dir: dir, }; var last_valid = { ln: curr.ln, pos: curr.pos, }; var skip_empty_lines = curr.line === ''; // Move one step to skip character we start on nextChar(cm, curr); while (curr.line !== null) { last_valid.ln = curr.ln; last_valid.pos = curr.pos; if (curr.line === '' && !skip_empty_lines) { return { ln: curr.ln, pos: curr.pos }; } else if (stop && curr.line !== '' && !isWhiteSpaceString(curr.line[curr.pos])) { return { ln: curr.ln, pos: curr.pos }; } else if ( isEndOfSentenceSymbol(curr.line[curr.pos]) && !stop && (curr.pos === curr.line.length - 1 || isWhiteSpaceString(curr.line[curr.pos + 1])) ) { stop = true; } nextChar(cm, curr); } /* Set the position to the last non whitespace character on the last valid line in the case that we reach the end of the document. */ var line = cm.getLine(last_valid.ln); last_valid.pos = 0; for (var i = line.length - 1; i >= 0; --i) { if (!isWhiteSpaceString(line[i])) { last_valid.pos = i; break; } } return last_valid; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
forward
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function reverse(cm, ln, pos, dir) { var line = cm.getLine(ln); var curr = { line: line, ln: ln, pos: pos, dir: dir, }; var last_valid = { ln: curr.ln, pos: null, }; var skip_empty_lines = curr.line === ''; // Move one step to skip character we start on nextChar(cm, curr); while (curr.line !== null) { if (curr.line === '' && !skip_empty_lines) { if (last_valid.pos !== null) { return last_valid; } else { return { ln: curr.ln, pos: curr.pos }; } } else if ( isEndOfSentenceSymbol(curr.line[curr.pos]) && last_valid.pos !== null && !(curr.ln === last_valid.ln && curr.pos + 1 === last_valid.pos) ) { return last_valid; } else if (curr.line !== '' && !isWhiteSpaceString(curr.line[curr.pos])) { skip_empty_lines = false; last_valid = { ln: curr.ln, pos: curr.pos }; } nextChar(cm, curr); } /* Set the position to the first non whitespace character on the last valid line in the case that we reach the beginning of the document. */ var line = cm.getLine(last_valid.ln); last_valid.pos = 0; for (var i = 0; i < line.length; ++i) { if (!isWhiteSpaceString(line[i])) { last_valid.pos = i; break; } } return last_valid; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
reverse
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function selectCompanionObject(cm, head, symb, inclusive) { var cur = head, start, end; var bracketRegexp = { '(': /[()]/, ')': /[()]/, '[': /[[\]]/, ']': /[[\]]/, '{': /[{}]/, '}': /[{}]/, '<': /[<>]/, '>': /[<>]/, }[symb]; var openSym = { '(': '(', ')': '(', '[': '[', ']': '[', '{': '{', '}': '{', '<': '<', '>': '<', }[symb]; var curChar = cm.getLine(cur.line).charAt(cur.ch); // Due to the behavior of scanForBracket, we need to add an offset if the // cursor is on a matching open bracket. var offset = curChar === openSym ? 1 : 0; start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, undefined, { bracketRegex: bracketRegexp }); end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, undefined, { bracketRegex: bracketRegexp }); if (!start || !end) { return { start: cur, end: cur }; } start = start.pos; end = end.pos; if ((start.line == end.line && start.ch > end.ch) || start.line > end.line) { var tmp = start; start = end; end = tmp; } if (inclusive) { end.ch += 1; } else { start.ch += 1; } return { start: start, end: end }; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
selectCompanionObject
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findBeginningAndEnd(cm, head, symb, inclusive) { var cur = copyCursor(head); var line = cm.getLine(cur.line); var chars = line.split(''); var start, end, i, len; var firstIndex = chars.indexOf(symb); // the decision tree is to always look backwards for the beginning first, // but if the cursor is in front of the first instance of the symb, // then move the cursor forward if (cur.ch < firstIndex) { cur.ch = firstIndex; // Why is this line even here??? // cm.setCursor(cur.line, firstIndex+1); } // otherwise if the cursor is currently on the closing symbol else if (firstIndex < cur.ch && chars[cur.ch] == symb) { end = cur.ch; // assign end to the current cursor --cur.ch; // make sure to look backwards } // if we're currently on the symbol, we've got a start if (chars[cur.ch] == symb && !end) { start = cur.ch + 1; // assign start to ahead of the cursor } else { // go backwards to find the start for (i = cur.ch; i > -1 && !start; i--) { if (chars[i] == symb) { start = i + 1; } } } // look forwards for the end symbol if (start && !end) { for (i = start, len = chars.length; i < len && !end; i++) { if (chars[i] == symb) { end = i; } } } // nothing found if (!start || !end) { return { start: cur, end: cur }; } // include the symbols if (inclusive) { --start; ++end; } return { start: Pos(cur.line, start), end: Pos(cur.line, end), }; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
findBeginningAndEnd
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function getSearchState(cm) { var vim = cm.state.vim; return vim.searchState_ || (vim.searchState_ = new SearchState()); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
getSearchState
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function splitBySlash(argString) { return splitBySeparator(argString, '/'); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
splitBySlash
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findUnescapedSlashes(argString) { return findUnescapedSeparators(argString, '/'); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
findUnescapedSlashes
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function splitBySeparator(argString, separator) { var slashes = findUnescapedSeparators(argString, separator) || []; if (!slashes.length) return []; var tokens = []; // in case of strings like foo/bar if (slashes[0] !== 0) return; for (var i = 0; i < slashes.length; i++) { if (typeof slashes[i] == 'number') tokens.push(argString.substring(slashes[i] + 1, slashes[i + 1])); } return tokens; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
splitBySeparator
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findUnescapedSeparators(str, separator) { if (!separator) separator = '/'; var escapeNextChar = false; var slashes = []; for (var i = 0; i < str.length; i++) { var c = str.charAt(i); if (!escapeNextChar && c == separator) { slashes.push(i); } escapeNextChar = !escapeNextChar && c == '\\'; } return slashes; }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
findUnescapedSeparators
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function translateRegex(str) { // When these match, add a '\' if unescaped or remove one if escaped. var specials = '|(){'; // Remove, but never add, a '\' for these. var unescape = '}'; var escapeNextChar = false; var out = []; for (var i = -1; i < str.length; i++) { var c = str.charAt(i) || ''; var n = str.charAt(i + 1) || ''; var specialComesNext = n && specials.indexOf(n) != -1; if (escapeNextChar) { if (c !== '\\' || !specialComesNext) { out.push(c); } escapeNextChar = false; } else { if (c === '\\') { escapeNextChar = true; // Treat the unescape list as special for removing, but not adding '\'. if (n && unescape.indexOf(n) != -1) { specialComesNext = true; } // Not passing this test means removing a '\'. if (!specialComesNext || n === '\\') { out.push(c); } } else { out.push(c); if (specialComesNext && n !== '\\') { out.push('\\'); } } } } return out.join(''); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
translateRegex
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function translateRegexReplace(str) { var escapeNextChar = false; var out = []; for (var i = -1; i < str.length; i++) { var c = str.charAt(i) || ''; var n = str.charAt(i + 1) || ''; if (charUnescapes[c + n]) { out.push(charUnescapes[c + n]); i++; } else if (escapeNextChar) { // At any point in the loop, escapeNextChar is true if the previous // character was a '\' and was not escaped. out.push(c); escapeNextChar = false; } else { if (c === '\\') { escapeNextChar = true; if (isNumber(n) || n === '$') { out.push('$'); } else if (n !== '/' && n !== '\\') { out.push('\\'); } } else { if (c === '$') { out.push('$'); } out.push(c); if (n === '/') { out.push('\\'); } } } } return out.join(''); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
translateRegexReplace
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function unescapeRegexReplace(str) { var stream = new CodeMirror.StringStream(str); var output = []; while (!stream.eol()) { // Search for \. while (stream.peek() && stream.peek() != '\\') { output.push(stream.next()); } var matched = false; for (var matcher in unescapes) { if (stream.match(matcher, true)) { matched = true; output.push(unescapes[matcher]); break; } } if (!matched) { // Don't change anything output.push(stream.next()); } } return output.join(''); }
@param {CodeMirror} cm CodeMirror object. @param {Pos} cur The position to start from. @param {int} repeat Number of words to move past. @param {boolean} forward True to search forward. False to search backward. @param {boolean} wordEnd True to move to end of word. False to move to beginning of word. @param {boolean} bigWord True if punctuation count as part of the word. False if only alphabet characters count as part of the word. @return {Cursor} The position the cursor should move to.
unescapeRegexReplace
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function parseQuery(query, ignoreCase, smartCase) { // First update the last search register var lastSearchRegister = vimGlobalState.registerController.getRegister('/'); lastSearchRegister.setText(query); // Check if the query is already a regex. if (query instanceof RegExp) { return query; } // First try to extract regex + flags from the input. If no flags found, // extract just the regex. IE does not accept flags directly defined in // the regex string in the form /regex/flags var slashes = findUnescapedSlashes(query); var regexPart; var forceIgnoreCase; if (!slashes.length) { // Query looks like 'regexp' regexPart = query; } else { // Query looks like 'regexp/...' regexPart = query.substring(0, slashes[0]); var flagsPart = query.substring(slashes[0]); forceIgnoreCase = flagsPart.indexOf('i') != -1; } if (!regexPart) { return null; } if (!getOption('pcre')) { regexPart = translateRegex(regexPart); } if (smartCase) { ignoreCase = /^[^A-Z]*$/.test(regexPart); } var regexp = new RegExp(regexPart, ignoreCase || forceIgnoreCase ? 'i' : undefined); return regexp; }
Extract the regular expression from the query and return a Regexp object. Returns null if the query is blank. If ignoreCase is passed in, the Regexp object will have the 'i' flag set. If smartCase is passed in, and the query contains upper case letters, then ignoreCase is overridden, and the 'i' flag will not be set. If the query contains the /i in the flag part of the regular expression, then both ignoreCase and smartCase are ignored, and 'i' will be passed through to the Regex object.
parseQuery
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function dom(n) { if (typeof n === 'string') n = document.createElement(n); for (var a, i = 1; i < arguments.length; i++) { if (!(a = arguments[i])) continue; if (typeof a !== 'object') a = document.createTextNode(a); if (a.nodeType) n.appendChild(a); else for (var key in a) { if (!Object.prototype.hasOwnProperty.call(a, key)) continue; if (key[0] === '$') n.style[key.slice(1)] = a[key]; else n.setAttribute(key, a[key]); } } return n; }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
dom
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function showConfirm(cm, template) { var pre = dom('pre', { $color: 'red' }, template); if (cm.openNotification) { cm.openNotification(pre, { bottom: true, duration: 5000 }); } else { alert(pre.innerText); } }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
showConfirm
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function makePrompt(prefix, desc) { return dom( document.createDocumentFragment(), dom( 'span', { $fontFamily: 'monospace', $whiteSpace: 'pre' }, prefix, dom('input', { type: 'text', autocorrect: 'off', autocapitalize: 'off', spellcheck: 'false' }) ), desc && dom('span', { $color: '#888' }, desc) ); }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
makePrompt
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function showPrompt(cm, options) { var shortText = (options.prefix || '') + ' ' + (options.desc || ''); var template = makePrompt(options.prefix, options.desc); if (cm.openDialog) { cm.openDialog(template, options.onClose, { onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp, bottom: true, selectValueOnOpen: false, value: options.value, }); } else { options.onClose(prompt(shortText, '')); } }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
showPrompt
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function regexEqual(r1, r2) { if (r1 instanceof RegExp && r2 instanceof RegExp) { var props = ['global', 'multiline', 'ignoreCase', 'source']; for (var i = 0; i < props.length; i++) { var prop = props[i]; if (r1[prop] !== r2[prop]) { return false; } } return true; } return false; }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
regexEqual
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function updateSearchQuery(cm, rawQuery, ignoreCase, smartCase) { if (!rawQuery) { return; } var state = getSearchState(cm); var query = parseQuery(rawQuery, !!ignoreCase, !!smartCase); if (!query) { return; } highlightSearchMatches(cm, query); if (regexEqual(query, state.getQuery())) { return query; } state.setQuery(query); return query; }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
updateSearchQuery
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function searchOverlay(query) { if (query.source.charAt(0) == '^') { var matchSol = true; } return { token: function (stream) { if (matchSol && !stream.sol()) { stream.skipToEnd(); return; } var match = stream.match(query, false); if (match) { if (match[0].length == 0) { // Matched empty string, skip to next. stream.next(); return 'searching'; } if (!stream.sol()) { // Backtrack 1 to match \b stream.backUp(1); if (!query.exec(stream.next() + match[0])) { stream.next(); return null; } } stream.match(query); return 'searching'; } while (!stream.eol()) { stream.next(); if (stream.match(query, false)) break; } }, query: query, }; }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
searchOverlay
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function highlightSearchMatches(cm, query) { clearTimeout(highlightTimeout); highlightTimeout = setTimeout(function () { var searchState = getSearchState(cm); var overlay = searchState.getOverlay(); if (!overlay || query != overlay.query) { if (overlay) { cm.removeOverlay(overlay); } overlay = searchOverlay(query); cm.addOverlay(overlay); if (cm.showMatchesOnScrollbar) { if (searchState.getScrollbarAnnotate()) { searchState.getScrollbarAnnotate().clear(); } searchState.setScrollbarAnnotate(cm.showMatchesOnScrollbar(query)); } searchState.setOverlay(overlay); } }, 50); }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
highlightSearchMatches
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findNext(cm, prev, query, repeat) { if (repeat === undefined) { repeat = 1; } return cm.operation(function () { var pos = cm.getCursor(); var cursor = cm.getSearchCursor(query, pos); for (var i = 0; i < repeat; i++) { var found = cursor.find(prev); if (i == 0 && found && cursorEqual(cursor.from(), pos)) { found = cursor.find(prev); } if (!found) { // SearchCursor may have returned null because it hit EOF, wrap // around and try again. cursor = cm.getSearchCursor(query, prev ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0)); if (!cursor.find(prev)) { return; } } } return cursor.from(); }); }
dom - Document Object Manipulator Usage: dom('<tag>'|<node>[, ...{<attributes>|<$styles>}|<child-node>|'<text>']) Examples: dom('div', {id:'xyz'}, dom('p', 'CM rocks!', {$color:'red'})) dom(document.head, dom('script', 'alert("hello!")')) Not supported: dom('p', ['arrays are objects'], Error('objects specify attributes'))
findNext
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function findNextFromAndToInclusive(cm, prev, query, repeat, vim) { if (repeat === undefined) { repeat = 1; } return cm.operation(function () { var pos = cm.getCursor(); var cursor = cm.getSearchCursor(query, pos); // Go back one result to ensure that if the cursor is currently a match, we keep it. var found = cursor.find(!prev); // If we haven't moved, go back one more (similar to if i==0 logic in findNext). if (!vim.visualMode && found && cursorEqual(cursor.from(), pos)) { cursor.find(!prev); } for (var i = 0; i < repeat; i++) { found = cursor.find(prev); if (!found) { // SearchCursor may have returned null because it hit EOF, wrap // around and try again. cursor = cm.getSearchCursor(query, prev ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0)); if (!cursor.find(prev)) { return; } } } return [cursor.from(), cursor.to()]; }); }
Pretty much the same as `findNext`, except for the following differences: 1. Before starting the search, move to the previous search. This way if our cursor is already inside a match, we should return the current match. 2. Rather than only returning the cursor's from, we return the cursor's from and to as a tuple.
findNextFromAndToInclusive
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function clearSearchHighlight(cm) { var state = getSearchState(cm); cm.removeOverlay(getSearchState(cm).getOverlay()); state.setOverlay(null); if (state.getScrollbarAnnotate()) { state.getScrollbarAnnotate().clear(); state.setScrollbarAnnotate(null); } }
Pretty much the same as `findNext`, except for the following differences: 1. Before starting the search, move to the previous search. This way if our cursor is already inside a match, we should return the current match. 2. Rather than only returning the cursor's from, we return the cursor's from and to as a tuple.
clearSearchHighlight
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function isInRange(pos, start, end) { if (typeof pos != 'number') { // Assume it is a cursor position. Get the line number. pos = pos.line; } if (start instanceof Array) { return inArray(pos, start); } else { if (typeof end == 'number') { return pos >= start && pos <= end; } else { return pos == start; } } }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
isInRange
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function getUserVisibleLines(cm) { var scrollInfo = cm.getScrollInfo(); var occludeToleranceTop = 6; var occludeToleranceBottom = 10; var from = cm.coordsChar({ left: 0, top: occludeToleranceTop + scrollInfo.top }, 'local'); var bottomY = scrollInfo.clientHeight - occludeToleranceBottom + scrollInfo.top; var to = cm.coordsChar({ left: 0, top: bottomY }, 'local'); return { top: from.line, bottom: to.line }; }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
getUserVisibleLines
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function getMarkPos(cm, vim, markName) { if (markName == "'" || markName == '`') { return vimGlobalState.jumpList.find(cm, -1) || Pos(0, 0); } else if (markName == '.') { return getLastEditPos(cm); } var mark = vim.marks[markName]; return mark && mark.find(); }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
getMarkPos
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function getLastEditPos(cm) { var done = cm.doc.history.done; for (var i = done.length; i--; ) { if (done[i].changes) { return copyCursor(done[i].changes[0].to); } } }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
getLastEditPos
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function parseArgs() { if (params.argString) { var args = new CodeMirror.StringStream(params.argString); if (args.eat('!')) { reverse = true; } if (args.eol()) { return; } if (!args.eatSpace()) { return 'Invalid arguments'; } var opts = args.match(/([dinuox]+)?\s*(\/.+\/)?\s*/); if (!opts && !args.eol()) { return 'Invalid arguments'; } if (opts[1]) { ignoreCase = opts[1].indexOf('i') != -1; unique = opts[1].indexOf('u') != -1; var decimal = opts[1].indexOf('d') != -1 || (opts[1].indexOf('n') != -1 && 1); var hex = opts[1].indexOf('x') != -1 && 1; var octal = opts[1].indexOf('o') != -1 && 1; if (decimal + hex + octal > 1) { return 'Invalid arguments'; } number = (decimal && 'decimal') || (hex && 'hex') || (octal && 'octal'); } if (opts[2]) { pattern = new RegExp(opts[2].substr(1, opts[2].length - 2), ignoreCase ? 'i' : ''); } } }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
parseArgs
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function compareFn(a, b) { if (reverse) { var tmp; tmp = a; a = b; b = tmp; } if (ignoreCase) { a = a.toLowerCase(); b = b.toLowerCase(); } var anum = number && numberRegex.exec(a); var bnum = number && numberRegex.exec(b); if (!anum) { return a < b ? -1 : 1; } anum = parseInt((anum[1] + anum[2]).toLowerCase(), radix); bnum = parseInt((bnum[1] + bnum[2]).toLowerCase(), radix); return anum - bnum; }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
compareFn
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function comparePatternFn(a, b) { if (reverse) { var tmp; tmp = a; a = b; b = tmp; } if (ignoreCase) { a[0] = a[0].toLowerCase(); b[0] = b[0].toLowerCase(); } return a[0] < b[0] ? -1 : 1; }
Check if pos is in the specified range, INCLUSIVE. Range can be specified with 1 or 2 arguments. If the first range argument is an array, treat it as an array of line numbers. Match pos against any of the lines. If the first range argument is a number, if there is only 1 range argument, check if pos has the same line number if there are 2 range arguments, then check if pos is in between the two range arguments.
comparePatternFn
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function doReplace(cm, confirm, global, lineStart, lineEnd, searchCursor, query, replaceWith, callback) { // Set up all the functions. cm.state.vim.exMode = true; var done = false; var lastPos, modifiedLineNumber, joined; function replaceAll() { cm.operation(function () { while (!done) { replace(); next(); } stop(); }); } function replace() { var text = cm.getRange(searchCursor.from(), searchCursor.to()); var newText = text.replace(query, replaceWith); var unmodifiedLineNumber = searchCursor.to().line; searchCursor.replace(newText); modifiedLineNumber = searchCursor.to().line; lineEnd += modifiedLineNumber - unmodifiedLineNumber; joined = modifiedLineNumber < unmodifiedLineNumber; } function next() { // The below only loops to skip over multiple occurrences on the same // line when 'global' is not true. while (searchCursor.findNext() && isInRange(searchCursor.from(), lineStart, lineEnd)) { if (!global && searchCursor.from().line == modifiedLineNumber && !joined) { continue; } cm.scrollIntoView(searchCursor.from(), 30); cm.setSelection(searchCursor.from(), searchCursor.to()); lastPos = searchCursor.from(); done = false; return; } done = true; } function stop(close) { if (close) { close(); } cm.focus(); if (lastPos) { cm.setCursor(lastPos); var vim = cm.state.vim; vim.exMode = false; vim.lastHPos = vim.lastHSPos = lastPos.ch; } if (callback) { callback(); } } function onPromptKeyDown(e, _value, close) { // Swallow all keys. CodeMirror.e_stop(e); var keyName = CodeMirror.keyName(e); switch (keyName) { case 'Y': replace(); next(); break; case 'N': next(); break; case 'A': // replaceAll contains a call to close of its own. We don't want it // to fire too early or multiple times. var savedCallback = callback; callback = undefined; cm.operation(replaceAll); callback = savedCallback; break; case 'L': replace(); // fall through and exit. case 'Q': case 'Esc': case 'Ctrl-C': case 'Ctrl-[': stop(close); break; } if (done) { stop(close); } return true; } // Actually do replace. next(); if (done) { showConfirm(cm, 'No matches for ' + query.source); return; } if (!confirm) { replaceAll(); if (callback) { callback(); } return; } showPrompt(cm, { prefix: dom('span', 'replace with ', dom('strong', replaceWith), ' (y/n/a/q/l)'), onKeyDown: onPromptKeyDown, }); }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
doReplace
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function replaceAll() { cm.operation(function () { while (!done) { replace(); next(); } stop(); }); }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
replaceAll
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function replace() { var text = cm.getRange(searchCursor.from(), searchCursor.to()); var newText = text.replace(query, replaceWith); var unmodifiedLineNumber = searchCursor.to().line; searchCursor.replace(newText); modifiedLineNumber = searchCursor.to().line; lineEnd += modifiedLineNumber - unmodifiedLineNumber; joined = modifiedLineNumber < unmodifiedLineNumber; }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
replace
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function next() { // The below only loops to skip over multiple occurrences on the same // line when 'global' is not true. while (searchCursor.findNext() && isInRange(searchCursor.from(), lineStart, lineEnd)) { if (!global && searchCursor.from().line == modifiedLineNumber && !joined) { continue; } cm.scrollIntoView(searchCursor.from(), 30); cm.setSelection(searchCursor.from(), searchCursor.to()); lastPos = searchCursor.from(); done = false; return; } done = true; }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
next
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function stop(close) { if (close) { close(); } cm.focus(); if (lastPos) { cm.setCursor(lastPos); var vim = cm.state.vim; vim.exMode = false; vim.lastHPos = vim.lastHSPos = lastPos.ch; } if (callback) { callback(); } }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
stop
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function onPromptKeyDown(e, _value, close) { // Swallow all keys. CodeMirror.e_stop(e); var keyName = CodeMirror.keyName(e); switch (keyName) { case 'Y': replace(); next(); break; case 'N': next(); break; case 'A': // replaceAll contains a call to close of its own. We don't want it // to fire too early or multiple times. var savedCallback = callback; callback = undefined; cm.operation(replaceAll); callback = savedCallback; break; case 'L': replace(); // fall through and exit. case 'Q': case 'Esc': case 'Ctrl-C': case 'Ctrl-[': stop(close); break; } if (done) { stop(close); } return true; }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
onPromptKeyDown
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function exitInsertMode(cm) { var vim = cm.state.vim; var macroModeState = vimGlobalState.macroModeState; var insertModeChangeRegister = vimGlobalState.registerController.getRegister('.'); var isPlaying = macroModeState.isPlaying; var lastChange = macroModeState.lastInsertModeChanges; if (!isPlaying) { cm.off('change', onChange); CodeMirror.off(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown); } if (!isPlaying && vim.insertModeRepeat > 1) { // Perform insert mode repeat for commands like 3,a and 3,o. repeatLastEdit(cm, vim, vim.insertModeRepeat - 1, true /** repeatForInsert */); vim.lastEditInputState.repeatOverride = vim.insertModeRepeat; } delete vim.insertModeRepeat; vim.insertMode = false; cm.setCursor(cm.getCursor().line, cm.getCursor().ch - 1); cm.setOption('keyMap', 'vim'); cm.setOption('disableInput', true); cm.toggleOverwrite(false); // exit replace mode if we were in it. // update the ". register before exiting insert mode insertModeChangeRegister.setText(lastChange.changes.join('')); CodeMirror.signal(cm, 'vim-mode-change', { mode: 'normal' }); if (macroModeState.isRecording) { logInsertModeChange(macroModeState); } }
@param {CodeMirror} cm CodeMirror instance we are in. @param {boolean} confirm Whether to confirm each replace. @param {Cursor} lineStart Line to start replacing from. @param {Cursor} lineEnd Line to stop replacing at. @param {RegExp} query Query for performing matches with. @param {string} replaceWith Text to replace matches with. May contain $1, $2, etc for replacing captured groups using JavaScript replace. @param {function()} callback A callback for when the replace is done.
exitInsertMode
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function onChange(cm, changeObj) { var macroModeState = vimGlobalState.macroModeState; var lastChange = macroModeState.lastInsertModeChanges; if (!macroModeState.isPlaying) { while (changeObj) { lastChange.expectCursorActivityForChange = true; if (lastChange.ignoreCount > 1) { lastChange.ignoreCount--; } else if ( changeObj.origin == '+input' || changeObj.origin == 'paste' || changeObj.origin === undefined /* only in testing */ ) { var selectionCount = cm.listSelections().length; if (selectionCount > 1) lastChange.ignoreCount = selectionCount; var text = changeObj.text.join('\n'); if (lastChange.maybeReset) { lastChange.changes = []; lastChange.maybeReset = false; } if (text) { if (cm.state.overwrite && !/\n/.test(text)) { lastChange.changes.push([text]); } else { lastChange.changes.push(text); } } } // Change objects may be chained with next. changeObj = changeObj.next; } } }
Listens for changes made in insert mode. Should only be active in insert mode.
onChange
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function onCursorActivity(cm) { var vim = cm.state.vim; if (vim.insertMode) { // Tracking cursor activity in insert mode (for macro support). var macroModeState = vimGlobalState.macroModeState; if (macroModeState.isPlaying) { return; } var lastChange = macroModeState.lastInsertModeChanges; if (lastChange.expectCursorActivityForChange) { lastChange.expectCursorActivityForChange = false; } else { // Cursor moved outside the context of an edit. Reset the change. lastChange.maybeReset = true; } } else if (!cm.curOp.isVimOp) { handleExternalSelection(cm, vim); } if (vim.visualMode) { updateFakeCursor(cm); } }
Listens for any kind of cursor activity on CodeMirror.
onCursorActivity
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function updateFakeCursor(cm) { var className = 'cm-animate-fat-cursor'; var vim = cm.state.vim; var from = clipCursorToContent(cm, copyCursor(vim.sel.head)); var to = offsetCursor(from, 0, 1); clearFakeCursor(vim); // In visual mode, the cursor may be positioned over EOL. if (from.ch == cm.getLine(from.line).length) { var widget = dom('span', { class: className }, '\u00a0'); vim.fakeCursorBookmark = cm.setBookmark(from, { widget: widget }); } else { vim.fakeCursor = cm.markText(from, to, { className: className }); } }
Keeps track of a fake cursor to support visual mode cursor behavior.
updateFakeCursor
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function clearFakeCursor(vim) { if (vim.fakeCursor) { vim.fakeCursor.clear(); vim.fakeCursor = null; } if (vim.fakeCursorBookmark) { vim.fakeCursorBookmark.clear(); vim.fakeCursorBookmark = null; } }
Keeps track of a fake cursor to support visual mode cursor behavior.
clearFakeCursor
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function handleExternalSelection(cm, vim) { var anchor = cm.getCursor('anchor'); var head = cm.getCursor('head'); // Enter or exit visual mode to match mouse selection. if (vim.visualMode && !cm.somethingSelected()) { exitVisualMode(cm, false); } else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) { vim.visualMode = true; vim.visualLine = false; CodeMirror.signal(cm, 'vim-mode-change', { mode: 'visual' }); } if (vim.visualMode) { // Bind CodeMirror selection model to vim selection model. // Mouse selections are considered visual characterwise. var headOffset = !cursorIsBefore(head, anchor) ? -1 : 0; var anchorOffset = cursorIsBefore(head, anchor) ? -1 : 0; head = offsetCursor(head, 0, headOffset); anchor = offsetCursor(anchor, 0, anchorOffset); vim.sel = { anchor: anchor, head: head, }; updateMark(cm, vim, '<', cursorMin(head, anchor)); updateMark(cm, vim, '>', cursorMax(head, anchor)); } else if (!vim.insertMode) { // Reset lastHPos if selection was modified by something outside of vim mode e.g. by mouse. vim.lastHPos = cm.getCursor().ch; } }
Keeps track of a fake cursor to support visual mode cursor behavior.
handleExternalSelection
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function InsertModeKey(keyName) { this.keyName = keyName; }
Wrapper for special keys pressed in insert mode
InsertModeKey
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function onKeyEventTargetKeyDown(e) { var macroModeState = vimGlobalState.macroModeState; var lastChange = macroModeState.lastInsertModeChanges; var keyName = CodeMirror.keyName(e); if (!keyName) { return; } function onKeyFound() { if (lastChange.maybeReset) { lastChange.changes = []; lastChange.maybeReset = false; } lastChange.changes.push(new InsertModeKey(keyName)); return true; } if (keyName.indexOf('Delete') != -1 || keyName.indexOf('Backspace') != -1) { CodeMirror.lookupKey(keyName, 'vim-insert', onKeyFound); } }
Handles raw key down events from the text area. - Should only be active in insert mode. - For recording deletes in insert mode.
onKeyEventTargetKeyDown
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function onKeyFound() { if (lastChange.maybeReset) { lastChange.changes = []; lastChange.maybeReset = false; } lastChange.changes.push(new InsertModeKey(keyName)); return true; }
Handles raw key down events from the text area. - Should only be active in insert mode. - For recording deletes in insert mode.
onKeyFound
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function repeatLastEdit(cm, vim, repeat, repeatForInsert) { var macroModeState = vimGlobalState.macroModeState; macroModeState.isPlaying = true; var isAction = !!vim.lastEditActionCommand; var cachedInputState = vim.inputState; function repeatCommand() { if (isAction) { commandDispatcher.processAction(cm, vim, vim.lastEditActionCommand); } else { commandDispatcher.evalInput(cm, vim); } } function repeatInsert(repeat) { if (macroModeState.lastInsertModeChanges.changes.length > 0) { // For some reason, repeat cw in desktop VIM does not repeat // insert mode changes. Will conform to that behavior. repeat = !vim.lastEditActionCommand ? 1 : repeat; var changeObject = macroModeState.lastInsertModeChanges; repeatInsertModeChanges(cm, changeObject.changes, repeat); } } vim.inputState = vim.lastEditInputState; if (isAction && vim.lastEditActionCommand.interlaceInsertRepeat) { // o and O repeat have to be interlaced with insert repeats so that the // insertions appear on separate lines instead of the last line. for (var i = 0; i < repeat; i++) { repeatCommand(); repeatInsert(1); } } else { if (!repeatForInsert) { // Hack to get the cursor to end up at the right place. If I is // repeated in insert mode repeat, cursor will be 1 insert // change set left of where it should be. repeatCommand(); } repeatInsert(repeat); } vim.inputState = cachedInputState; if (vim.insertMode && !repeatForInsert) { // Don't exit insert mode twice. If repeatForInsert is set, then we // were called by an exitInsertMode call lower on the stack. exitInsertMode(cm); } macroModeState.isPlaying = false; }
Repeats the last edit, which includes exactly 1 command and at most 1 insert. Operator and motion commands are read from lastEditInputState, while action commands are read from lastEditActionCommand. If repeatForInsert is true, then the function was called by exitInsertMode to repeat the insert mode changes the user just made. The corresponding enterInsertMode call was made with a count.
repeatLastEdit
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function repeatCommand() { if (isAction) { commandDispatcher.processAction(cm, vim, vim.lastEditActionCommand); } else { commandDispatcher.evalInput(cm, vim); } }
Repeats the last edit, which includes exactly 1 command and at most 1 insert. Operator and motion commands are read from lastEditInputState, while action commands are read from lastEditActionCommand. If repeatForInsert is true, then the function was called by exitInsertMode to repeat the insert mode changes the user just made. The corresponding enterInsertMode call was made with a count.
repeatCommand
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function repeatInsert(repeat) { if (macroModeState.lastInsertModeChanges.changes.length > 0) { // For some reason, repeat cw in desktop VIM does not repeat // insert mode changes. Will conform to that behavior. repeat = !vim.lastEditActionCommand ? 1 : repeat; var changeObject = macroModeState.lastInsertModeChanges; repeatInsertModeChanges(cm, changeObject.changes, repeat); } }
Repeats the last edit, which includes exactly 1 command and at most 1 insert. Operator and motion commands are read from lastEditInputState, while action commands are read from lastEditActionCommand. If repeatForInsert is true, then the function was called by exitInsertMode to repeat the insert mode changes the user just made. The corresponding enterInsertMode call was made with a count.
repeatInsert
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function repeatInsertModeChanges(cm, changes, repeat) { function keyHandler(binding) { if (typeof binding == 'string') { CodeMirror.commands[binding](cm); } else { binding(cm); } return true; } var head = cm.getCursor('head'); var visualBlock = vimGlobalState.macroModeState.lastInsertModeChanges.visualBlock; if (visualBlock) { // Set up block selection again for repeating the changes. selectForInsert(cm, head, visualBlock + 1); repeat = cm.listSelections().length; cm.setCursor(head); } for (var i = 0; i < repeat; i++) { if (visualBlock) { cm.setCursor(offsetCursor(head, i, 0)); } for (var j = 0; j < changes.length; j++) { var change = changes[j]; if (change instanceof InsertModeKey) { CodeMirror.lookupKey(change.keyName, 'vim-insert', keyHandler); } else if (typeof change == 'string') { var cur = cm.getCursor(); cm.replaceRange(change, cur, cur); } else { var start = cm.getCursor(); var end = offsetCursor(start, 0, change[0].length); cm.replaceRange(change[0], start, end); } } } if (visualBlock) { cm.setCursor(offsetCursor(head, 0, 1)); } }
Repeats the last edit, which includes exactly 1 command and at most 1 insert. Operator and motion commands are read from lastEditInputState, while action commands are read from lastEditActionCommand. If repeatForInsert is true, then the function was called by exitInsertMode to repeat the insert mode changes the user just made. The corresponding enterInsertMode call was made with a count.
repeatInsertModeChanges
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function keyHandler(binding) { if (typeof binding == 'string') { CodeMirror.commands[binding](cm); } else { binding(cm); } return true; }
Repeats the last edit, which includes exactly 1 command and at most 1 insert. Operator and motion commands are read from lastEditInputState, while action commands are read from lastEditActionCommand. If repeatForInsert is true, then the function was called by exitInsertMode to repeat the insert mode changes the user just made. The corresponding enterInsertMode call was made with a count.
keyHandler
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/keymap/vim.js
MIT
function makeKeywords(str) { var obj = {}, words = str.split(' '); for (var i = 0; i < words.length; ++i) obj[words[i]] = true; return obj; }
Author: Gautam Mehta Branched from CodeMirror's Scheme mode
makeKeywords
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/cobol/cobol.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/cobol/cobol.js
MIT
function isNumber(ch, stream) { // hex if (ch === '0' && stream.eat(/x/i)) { stream.eatWhile(tests.hex); return true; } // leading sign if ((ch == '+' || ch == '-') && tests.digit.test(stream.peek())) { stream.eat(tests.sign); ch = stream.next(); } if (tests.digit.test(ch)) { stream.eat(ch); stream.eatWhile(tests.digit); if ('.' == stream.peek()) { stream.eat('.'); stream.eatWhile(tests.digit); } if (stream.eat(tests.exponent)) { stream.eat(tests.sign); stream.eatWhile(tests.digit); } return true; } return false; }
Author: Gautam Mehta Branched from CodeMirror's Scheme mode
isNumber
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/cobol/cobol.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/cobol/cobol.js
MIT
function wordRegexp(words) { return new RegExp('^((' + words.join(')|(') + '))\\b'); }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
wordRegexp
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
function tokenBase(stream, state) { // Handle scope changes if (stream.sol()) { if (state.scope.align === null) state.scope.align = false; var scopeOffset = state.scope.offset; if (stream.eatSpace()) { var lineOffset = stream.indentation(); if (lineOffset > scopeOffset && state.scope.type == 'coffee') { return 'indent'; } else if (lineOffset < scopeOffset) { return 'dedent'; } return null; } else { if (scopeOffset > 0) { dedent(stream, state); } } } if (stream.eatSpace()) { return null; } var ch = stream.peek(); // Handle docco title comment (single line) if (stream.match('####')) { stream.skipToEnd(); return 'comment'; } // Handle multi line comments if (stream.match('###')) { state.tokenize = longComment; return state.tokenize(stream, state); } // Single line comment if (ch === '#') { stream.skipToEnd(); return 'comment'; } // Handle number literals if (stream.match(/^-?[0-9\.]/, false)) { var floatLiteral = false; // Floats if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; } if (stream.match(/^-?\d+\.\d*/)) { floatLiteral = true; } if (stream.match(/^-?\.\d+/)) { floatLiteral = true; } if (floatLiteral) { // prevent from getting extra . on 1.. if (stream.peek() == '.') { stream.backUp(1); } return 'number'; } // Integers var intLiteral = false; // Hex if (stream.match(/^-?0x[0-9a-f]+/i)) { intLiteral = true; } // Decimal if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) { intLiteral = true; } // Zero by itself with no other piece of number. if (stream.match(/^-?0(?![\dx])/i)) { intLiteral = true; } if (intLiteral) { return 'number'; } } // Handle strings if (stream.match(stringPrefixes)) { state.tokenize = tokenFactory(stream.current(), false, 'string'); return state.tokenize(stream, state); } // Handle regex literals if (stream.match(regexPrefixes)) { if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division state.tokenize = tokenFactory(stream.current(), true, 'string-2'); return state.tokenize(stream, state); } else { stream.backUp(1); } } // Handle operators and delimiters if (stream.match(operators) || stream.match(wordOperators)) { return 'operator'; } if (stream.match(delimiters)) { return 'punctuation'; } if (stream.match(constants)) { return 'atom'; } if (stream.match(atProp) || (state.prop && stream.match(identifiers))) { return 'property'; } if (stream.match(keywords)) { return 'keyword'; } if (stream.match(identifiers)) { return 'variable'; } // Handle non-detected items stream.next(); return ERRORCLASS; }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
tokenBase
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
function tokenFactory(delimiter, singleline, outclass) { return function (stream, state) { while (!stream.eol()) { stream.eatWhile(/[^'"\/\\]/); if (stream.eat('\\')) { stream.next(); if (singleline && stream.eol()) { return outclass; } } else if (stream.match(delimiter)) { state.tokenize = tokenBase; return outclass; } else { stream.eat(/['"\/]/); } } if (singleline) { if (parserConf.singleLineStringErrors) { outclass = ERRORCLASS; } else { state.tokenize = tokenBase; } } return outclass; }; }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
tokenFactory
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
function longComment(stream, state) { while (!stream.eol()) { stream.eatWhile(/[^#]/); if (stream.match('###')) { state.tokenize = tokenBase; break; } stream.eatWhile('#'); } return 'comment'; }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
longComment
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
function indent(stream, state, type) { type = type || 'coffee'; var offset = 0, align = false, alignOffset = null; for (var scope = state.scope; scope; scope = scope.prev) { if (scope.type === 'coffee' || scope.type == '}') { offset = scope.offset + conf.indentUnit; break; } } if (type !== 'coffee') { align = null; alignOffset = stream.column() + stream.current().length; } else if (state.scope.align) { state.scope.align = false; } state.scope = { offset: offset, type: type, prev: state.scope, align: align, alignOffset: alignOffset, }; }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
indent
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
function dedent(stream, state) { if (!state.scope.prev) return; if (state.scope.type === 'coffee') { var _indent = stream.indentation(); var matched = false; for (var scope = state.scope; scope; scope = scope.prev) { if (_indent === scope.offset) { matched = true; break; } } if (!matched) { return true; } while (state.scope.prev && state.scope.offset !== _indent) { state.scope = state.scope.prev; } return false; } else { state.scope = state.scope.prev; return false; } }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
dedent
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
function tokenLexer(stream, state) { var style = state.tokenize(stream, state); var current = stream.current(); // Handle scope changes. if (current === 'return') { state.dedent = true; } if (((current === '->' || current === '=>') && stream.eol()) || style === 'indent') { indent(stream, state); } var delimiter_index = '[({'.indexOf(current); if (delimiter_index !== -1) { indent(stream, state, '])}'.slice(delimiter_index, delimiter_index + 1)); } if (indentKeywords.exec(current)) { indent(stream, state); } if (current == 'then') { dedent(stream, state); } if (style === 'dedent') { if (dedent(stream, state)) { return ERRORCLASS; } } delimiter_index = '])}'.indexOf(current); if (delimiter_index !== -1) { while (state.scope.type == 'coffee' && state.scope.prev) state.scope = state.scope.prev; if (state.scope.type == current) state.scope = state.scope.prev; } if (state.dedent && stream.eol()) { if (state.scope.type == 'coffee' && state.scope.prev) state.scope = state.scope.prev; state.dedent = false; } return style; }
Link to the project's GitHub page: https://github.com/pickhardt/coffeescript-codemirror-mode
tokenLexer
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/coffeescript/coffeescript.js
MIT
tokenBase = function (stream, state) { var next_rule = state.next || 'start'; if (next_rule) { state.next = state.next; var nr = Rules[next_rule]; if (nr.splice) { for (var i$ = 0; i$ < nr.length; ++i$) { var r = nr[i$]; if (r.regex && stream.match(r.regex)) { state.next = r.next || state.next; return r.token; } } stream.next(); return 'error'; } if (stream.match((r = Rules[next_rule]))) { if (r.regex && stream.match(r.regex)) { state.next = r.next; return r.token; } else { stream.next(); return 'error'; } } } stream.next(); return 'error'; }
Link to the project's GitHub page: https://github.com/duralog/CodeMirror
tokenBase
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/livescript/livescript.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/livescript/livescript.js
MIT
function tokenCComment(stream, state) { var maybeEnd = false, ch; while ((ch = stream.next()) != null) { if (maybeEnd && ch == '/') { state.tokenize = tokenBase; break; } maybeEnd = ch == '*'; } return ret('comment', 'comment'); }
/ var ch = stream.next(); if (ch == '@') { stream.eatWhile(/[\w\\\-]/); return ret('meta', stream.current()); } else if (ch == '/' && stream.eat('*')) { state.tokenize = tokenCComment; return tokenCComment(stream, state); } else if (ch == '<' && stream.eat('!')) { state.tokenize = tokenSGMLComment; return tokenSGMLComment(stream, state); } else if (ch == '=') ret(null, 'compare'); else if ((ch == '~' || ch == '|') && stream.eat('=')) return ret(null, 'compare'); else if (ch == '"' || ch == "'") { state.tokenize = tokenString(ch); return state.tokenize(stream, state); } else if (ch == '#') { stream.skipToEnd(); return ret('comment', 'comment'); } else if (ch == '!') { stream.match(/^\s*\w
tokenCComment
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/nginx/nginx.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/nginx/nginx.js
MIT
function tokenSGMLComment(stream, state) { var dashes = 0, ch; while ((ch = stream.next()) != null) { if (dashes >= 2 && ch == '>') { state.tokenize = tokenBase; break; } dashes = ch == '-' ? dashes + 1 : 0; } return ret('comment', 'comment'); }
/ var ch = stream.next(); if (ch == '@') { stream.eatWhile(/[\w\\\-]/); return ret('meta', stream.current()); } else if (ch == '/' && stream.eat('*')) { state.tokenize = tokenCComment; return tokenCComment(stream, state); } else if (ch == '<' && stream.eat('!')) { state.tokenize = tokenSGMLComment; return tokenSGMLComment(stream, state); } else if (ch == '=') ret(null, 'compare'); else if ((ch == '~' || ch == '|') && stream.eat('=')) return ret(null, 'compare'); else if (ch == '"' || ch == "'") { state.tokenize = tokenString(ch); return state.tokenize(stream, state); } else if (ch == '#') { stream.skipToEnd(); return ret('comment', 'comment'); } else if (ch == '!') { stream.match(/^\s*\w
tokenSGMLComment
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/nginx/nginx.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/nginx/nginx.js
MIT
function tokenString(quote) { return function (stream, state) { var escaped = false, ch; while ((ch = stream.next()) != null) { if (ch == quote && !escaped) break; escaped = !escaped && ch == '\\'; } if (!escaped) state.tokenize = tokenBase; return ret('string', 'string'); }; }
/ var ch = stream.next(); if (ch == '@') { stream.eatWhile(/[\w\\\-]/); return ret('meta', stream.current()); } else if (ch == '/' && stream.eat('*')) { state.tokenize = tokenCComment; return tokenCComment(stream, state); } else if (ch == '<' && stream.eat('!')) { state.tokenize = tokenSGMLComment; return tokenSGMLComment(stream, state); } else if (ch == '=') ret(null, 'compare'); else if ((ch == '~' || ch == '|') && stream.eat('=')) return ret(null, 'compare'); else if (ch == '"' || ch == "'") { state.tokenize = tokenString(ch); return state.tokenize(stream, state); } else if (ch == '#') { stream.skipToEnd(); return ret('comment', 'comment'); } else if (ch == '!') { stream.match(/^\s*\w
tokenString
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/nginx/nginx.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/nginx/nginx.js
MIT
function transitState(currState, c) { var currLocation = currState.location; var ret; // Opening. if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI; else if (currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI; else if (currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI; else if (currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI; else if (currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE; else if (currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL; // Closing. else if (currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED; else if (currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED; else if (currLocation == Location.WRITING_PRED_URI && c == '>') ret = Location.PRE_OBJ; else if (currLocation == Location.WRITING_OBJ_URI && c == '>') ret = Location.POST_OBJ; else if (currLocation == Location.WRITING_OBJ_BNODE && c == ' ') ret = Location.POST_OBJ; else if (currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ; else if (currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ; else if (currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ; // Closing typed and language literal. else if (currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG; else if (currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE; // Spaces. else if ( c == ' ' && (currLocation == Location.PRE_SUBJECT || currLocation == Location.PRE_PRED || currLocation == Location.PRE_OBJ || currLocation == Location.POST_OBJ) ) ret = currLocation; // Reset. else if (currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT; // Error else ret = Location.ERROR; currState.location = ret; }
******************************************************* This script provides syntax highlighting support for the N-Triples format. N-Triples format specification: https://www.w3.org/TR/n-triples/ *********************************************************
transitState
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/ntriples/ntriples.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/ntriples/ntriples.js
MIT
function nextToken(stream, state) { var tok = innerMode(stream, state) || restOfLine(stream, state) || interpolationContinued(stream, state) || includeFilteredContinued(stream, state) || eachContinued(stream, state) || attrsContinued(stream, state) || javaScript(stream, state) || javaScriptArguments(stream, state) || callArguments(stream, state) || yieldStatement(stream) || doctype(stream) || interpolation(stream, state) || caseStatement(stream, state) || when(stream, state) || defaultStatement(stream) || extendsStatement(stream, state) || append(stream, state) || prepend(stream, state) || block(stream, state) || include(stream, state) || includeFiltered(stream, state) || mixin(stream, state) || call(stream, state) || conditional(stream, state) || each(stream, state) || whileStatement(stream, state) || tag(stream, state) || filter(stream, state) || code(stream, state) || id(stream) || className(stream) || attrs(stream, state) || attributesBlock(stream, state) || indent(stream) || text(stream, state) || comment(stream, state) || colon(stream) || dot(stream, state) || fail(stream); return tok === true ? null : tok; }
Get the next token in the stream @param {Stream} stream @param {State} state
nextToken
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/pug/pug.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/pug/pug.js
MIT
function makeKeywords(str) { var obj = {}, words = str.split(' '); for (var i = 0; i < words.length; ++i) obj[words[i]] = true; return obj; }
Author: Koh Zi Han, based on implementation by Koh Zi Chun
makeKeywords
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
MIT
function stateStack(indent, type, prev) { // represents a state stack object this.indent = indent; this.type = type; this.prev = prev; }
Author: Koh Zi Han, based on implementation by Koh Zi Chun
stateStack
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
MIT
function pushStack(state, indent, type) { state.indentStack = new stateStack(indent, type, state.indentStack); }
Author: Koh Zi Han, based on implementation by Koh Zi Chun
pushStack
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
MIT
function popStack(state) { state.indentStack = state.indentStack.prev; }
Author: Koh Zi Han, based on implementation by Koh Zi Chun
popStack
javascript
cabloy/cabloy
src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/backend/static/lib/codemirror/mode/scheme/scheme.js
MIT