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 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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/keymap/vim.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/cobol/cobol.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/cobol/cobol.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/coffeescript/coffeescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/livescript/livescript.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/nginx/nginx.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/nginx/nginx.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/nginx/nginx.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/ntriples/ntriples.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/pug/pug.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/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/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | MIT |
function isBinaryNumber(stream) {
return stream.match(binaryMatcher);
} | Author: Koh Zi Han, based on implementation by Koh Zi Chun | isBinaryNumber | javascript | cabloy/cabloy | src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | MIT |
function isOctalNumber(stream) {
return stream.match(octalMatcher);
} | Author: Koh Zi Han, based on implementation by Koh Zi Chun | isOctalNumber | javascript | cabloy/cabloy | src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | MIT |
function isDecimalNumber(stream, backup) {
if (backup === true) {
stream.backUp(1);
}
return stream.match(decimalMatcher);
} | Author: Koh Zi Han, based on implementation by Koh Zi Chun | isDecimalNumber | javascript | cabloy/cabloy | src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | MIT |
function isHexNumber(stream) {
return stream.match(hexMatcher);
} | Author: Koh Zi Han, based on implementation by Koh Zi Chun | isHexNumber | javascript | cabloy/cabloy | src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-codemirror/dist/staticBackend/lib/codemirror/mode/scheme/scheme.js | MIT |
function slideToLoop(index, speed, runCallbacks, internal) {
if (index === void 0) {
index = 0;
}
if (speed === void 0) {
speed = this.params.speed;
}
if (runCallbacks === void 0) {
runCallbacks = true;
}
if (typeof index === 'string') {
/**
* The `index` argument converted from `string` to `number`.
* @type {number}
*/
const indexAsNumber = parseInt(index, 10);
/**
* Determines whether the `index` argument is a valid `number`
* after being converted from the `string` type.
* @type {boolean}
*/
const isValidNumber = isFinite(indexAsNumber);
if (!isValidNumber) {
throw new Error(`The passed-in 'index' (string) couldn't be converted to 'number'. [${index}] given.`);
} // Knowing that the converted `index` is a valid number,
// we can update the original argument's value.
index = indexAsNumber;
}
const swiper = this;
let newIndex = index;
if (swiper.params.loop) {
newIndex += swiper.loopedSlides;
}
return swiper.slideTo(newIndex, speed, runCallbacks, internal);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | slideToLoop | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function slideNext(speed, runCallbacks, internal) {
if (speed === void 0) {
speed = this.params.speed;
}
if (runCallbacks === void 0) {
runCallbacks = true;
}
const swiper = this;
const {
animating,
enabled,
params
} = swiper;
if (!enabled) return swiper;
let perGroup = params.slidesPerGroup;
if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
}
const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
if (params.loop) {
if (animating && params.loopPreventsSlide) return false;
swiper.loopFix(); // eslint-disable-next-line
swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
}
if (params.rewind && swiper.isEnd) {
return swiper.slideTo(0, speed, runCallbacks, internal);
}
return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | slideNext | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function slidePrev(speed, runCallbacks, internal) {
if (speed === void 0) {
speed = this.params.speed;
}
if (runCallbacks === void 0) {
runCallbacks = true;
}
const swiper = this;
const {
params,
animating,
snapGrid,
slidesGrid,
rtlTranslate,
enabled
} = swiper;
if (!enabled) return swiper;
if (params.loop) {
if (animating && params.loopPreventsSlide) return false;
swiper.loopFix(); // eslint-disable-next-line
swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
}
const translate = rtlTranslate ? swiper.translate : -swiper.translate;
function normalize(val) {
if (val < 0) return -Math.floor(Math.abs(val));
return Math.floor(val);
}
const normalizedTranslate = normalize(translate);
const normalizedSnapGrid = snapGrid.map(val => normalize(val));
let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
if (typeof prevSnap === 'undefined' && params.cssMode) {
let prevSnapIndex;
snapGrid.forEach((snap, snapIndex) => {
if (normalizedTranslate >= snap) {
// prevSnap = snap;
prevSnapIndex = snapIndex;
}
});
if (typeof prevSnapIndex !== 'undefined') {
prevSnap = snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
}
}
let prevIndex = 0;
if (typeof prevSnap !== 'undefined') {
prevIndex = slidesGrid.indexOf(prevSnap);
if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
prevIndex = Math.max(prevIndex, 0);
}
}
if (params.rewind && swiper.isBeginning) {
const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
}
return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | slidePrev | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function normalize(val) {
if (val < 0) return -Math.floor(Math.abs(val));
return Math.floor(val);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | normalize | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function slideReset(speed, runCallbacks, internal) {
if (speed === void 0) {
speed = this.params.speed;
}
if (runCallbacks === void 0) {
runCallbacks = true;
}
const swiper = this;
return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | slideReset | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function slideToClosest(speed, runCallbacks, internal, threshold) {
if (speed === void 0) {
speed = this.params.speed;
}
if (runCallbacks === void 0) {
runCallbacks = true;
}
if (threshold === void 0) {
threshold = 0.5;
}
const swiper = this;
let index = swiper.activeIndex;
const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
if (translate >= swiper.snapGrid[snapIndex]) {
// The current translate is on or after the current snap index, so the choice
// is between the current index and the one after it.
const currentSnap = swiper.snapGrid[snapIndex];
const nextSnap = swiper.snapGrid[snapIndex + 1];
if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
index += swiper.params.slidesPerGroup;
}
} else {
// The current translate is before the current snap index, so the choice
// is between the current index and the one before it.
const prevSnap = swiper.snapGrid[snapIndex - 1];
const currentSnap = swiper.snapGrid[snapIndex];
if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
index -= swiper.params.slidesPerGroup;
}
}
index = Math.max(index, 0);
index = Math.min(index, swiper.slidesGrid.length - 1);
return swiper.slideTo(index, speed, runCallbacks, internal);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | slideToClosest | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function slideToClickedSlide() {
const swiper = this;
const {
params,
$wrapperEl
} = swiper;
const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
let slideToIndex = swiper.clickedIndex;
let realIndex;
if (params.loop) {
if (swiper.animating) return;
realIndex = parseInt($(swiper.clickedSlide).attr('data-swiper-slide-index'), 10);
if (params.centeredSlides) {
if (slideToIndex < swiper.loopedSlides - slidesPerView / 2 || slideToIndex > swiper.slides.length - swiper.loopedSlides + slidesPerView / 2) {
swiper.loopFix();
slideToIndex = $wrapperEl.children(`.${params.slideClass}[data-swiper-slide-index="${realIndex}"]:not(.${params.slideDuplicateClass})`).eq(0).index();
nextTick(() => {
swiper.slideTo(slideToIndex);
});
} else {
swiper.slideTo(slideToIndex);
}
} else if (slideToIndex > swiper.slides.length - slidesPerView) {
swiper.loopFix();
slideToIndex = $wrapperEl.children(`.${params.slideClass}[data-swiper-slide-index="${realIndex}"]:not(.${params.slideDuplicateClass})`).eq(0).index();
nextTick(() => {
swiper.slideTo(slideToIndex);
});
} else {
swiper.slideTo(slideToIndex);
}
} else {
swiper.slideTo(slideToIndex);
}
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | slideToClickedSlide | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function loopCreate() {
const swiper = this;
const document = getDocument();
const {
params,
$wrapperEl
} = swiper; // Remove duplicated slides
const $selector = $wrapperEl.children().length > 0 ? $($wrapperEl.children()[0].parentNode) : $wrapperEl;
$selector.children(`.${params.slideClass}.${params.slideDuplicateClass}`).remove();
let slides = $selector.children(`.${params.slideClass}`);
if (params.loopFillGroupWithBlank) {
const blankSlidesNum = params.slidesPerGroup - slides.length % params.slidesPerGroup;
if (blankSlidesNum !== params.slidesPerGroup) {
for (let i = 0; i < blankSlidesNum; i += 1) {
const blankNode = $(document.createElement('div')).addClass(`${params.slideClass} ${params.slideBlankClass}`);
$selector.append(blankNode);
}
slides = $selector.children(`.${params.slideClass}`);
}
}
if (params.slidesPerView === 'auto' && !params.loopedSlides) params.loopedSlides = slides.length;
swiper.loopedSlides = Math.ceil(parseFloat(params.loopedSlides || params.slidesPerView, 10));
swiper.loopedSlides += params.loopAdditionalSlides;
if (swiper.loopedSlides > slides.length && swiper.params.loopedSlidesLimit) {
swiper.loopedSlides = slides.length;
}
const prependSlides = [];
const appendSlides = [];
slides.each((el, index) => {
const slide = $(el);
slide.attr('data-swiper-slide-index', index);
});
for (let i = 0; i < swiper.loopedSlides; i += 1) {
const index = i - Math.floor(i / slides.length) * slides.length;
appendSlides.push(slides.eq(index)[0]);
prependSlides.unshift(slides.eq(slides.length - index - 1)[0]);
}
for (let i = 0; i < appendSlides.length; i += 1) {
$selector.append($(appendSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
}
for (let i = prependSlides.length - 1; i >= 0; i -= 1) {
$selector.prepend($(prependSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
}
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | loopCreate | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function loopFix() {
const swiper = this;
swiper.emit('beforeLoopFix');
const {
activeIndex,
slides,
loopedSlides,
allowSlidePrev,
allowSlideNext,
snapGrid,
rtlTranslate: rtl
} = swiper;
let newIndex;
swiper.allowSlidePrev = true;
swiper.allowSlideNext = true;
const snapTranslate = -snapGrid[activeIndex];
const diff = snapTranslate - swiper.getTranslate(); // Fix For Negative Oversliding
if (activeIndex < loopedSlides) {
newIndex = slides.length - loopedSlides * 3 + activeIndex;
newIndex += loopedSlides;
const slideChanged = swiper.slideTo(newIndex, 0, false, true);
if (slideChanged && diff !== 0) {
swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
}
} else if (activeIndex >= slides.length - loopedSlides) {
// Fix For Positive Oversliding
newIndex = -slides.length + activeIndex + loopedSlides;
newIndex += loopedSlides;
const slideChanged = swiper.slideTo(newIndex, 0, false, true);
if (slideChanged && diff !== 0) {
swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
}
}
swiper.allowSlidePrev = allowSlidePrev;
swiper.allowSlideNext = allowSlideNext;
swiper.emit('loopFix');
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | loopFix | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function loopDestroy() {
const swiper = this;
const {
$wrapperEl,
params,
slides
} = swiper;
$wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass},.${params.slideClass}.${params.slideBlankClass}`).remove();
slides.removeAttr('data-swiper-slide-index');
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | loopDestroy | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function setGrabCursor(moving) {
const swiper = this;
if (swiper.support.touch || !swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
el.style.cursor = 'move';
el.style.cursor = moving ? 'grabbing' : 'grab';
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | setGrabCursor | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function unsetGrabCursor() {
const swiper = this;
if (swiper.support.touch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
return;
}
swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | unsetGrabCursor | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function closestElement(selector, base) {
if (base === void 0) {
base = this;
}
function __closestFrom(el) {
if (!el || el === getDocument() || el === getWindow()) return null;
if (el.assignedSlot) el = el.assignedSlot;
const found = el.closest(selector);
if (!found && !el.getRootNode) {
return null;
}
return found || __closestFrom(el.getRootNode().host);
}
return __closestFrom(base);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | closestElement | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function __closestFrom(el) {
if (!el || el === getDocument() || el === getWindow()) return null;
if (el.assignedSlot) el = el.assignedSlot;
const found = el.closest(selector);
if (!found && !el.getRootNode) {
return null;
}
return found || __closestFrom(el.getRootNode().host);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | __closestFrom | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function onTouchStart(event) {
const swiper = this;
const document = getDocument();
const window = getWindow();
const data = swiper.touchEventsData;
const {
params,
touches,
enabled
} = swiper;
if (!enabled) return;
if (swiper.animating && params.preventInteractionOnTransition) {
return;
}
if (!swiper.animating && params.cssMode && params.loop) {
swiper.loopFix();
}
let e = event;
if (e.originalEvent) e = e.originalEvent;
let $targetEl = $(e.target);
if (params.touchEventsTarget === 'wrapper') {
if (!$targetEl.closest(swiper.wrapperEl).length) return;
}
data.isTouchEvent = e.type === 'touchstart';
if (!data.isTouchEvent && 'which' in e && e.which === 3) return;
if (!data.isTouchEvent && 'button' in e && e.button > 0) return;
if (data.isTouched && data.isMoved) return; // change target el for shadow root component
const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== ''; // eslint-disable-next-line
const eventPath = event.composedPath ? event.composedPath() : event.path;
if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) {
$targetEl = $(eventPath[0]);
}
const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
const isTargetShadow = !!(e.target && e.target.shadowRoot); // use closestElement for shadow root element to get the actual closest for nested shadow root element
if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, $targetEl[0]) : $targetEl.closest(noSwipingSelector)[0])) {
swiper.allowClick = true;
return;
}
if (params.swipeHandler) {
if (!$targetEl.closest(params.swipeHandler)[0]) return;
}
touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
const startX = touches.currentX;
const startY = touches.currentY; // Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore
const edgeSwipeDetection = params.edgeSwipeDetection || params.iOSEdgeSwipeDetection;
const edgeSwipeThreshold = params.edgeSwipeThreshold || params.iOSEdgeSwipeThreshold;
if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
if (edgeSwipeDetection === 'prevent') {
event.preventDefault();
} else {
return;
}
}
Object.assign(data, {
isTouched: true,
isMoved: false,
allowTouchCallbacks: true,
isScrolling: undefined,
startMoving: undefined
});
touches.startX = startX;
touches.startY = startY;
data.touchStartTime = now();
swiper.allowClick = true;
swiper.updateSize();
swiper.swipeDirection = undefined;
if (params.threshold > 0) data.allowThresholdMove = false;
if (e.type !== 'touchstart') {
let preventDefault = true;
if ($targetEl.is(data.focusableElements)) {
preventDefault = false;
if ($targetEl[0].nodeName === 'SELECT') {
data.isTouched = false;
}
}
if (document.activeElement && $(document.activeElement).is(data.focusableElements) && document.activeElement !== $targetEl[0]) {
document.activeElement.blur();
}
const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !$targetEl[0].isContentEditable) {
e.preventDefault();
}
}
if (swiper.params.freeMode && swiper.params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
swiper.freeMode.onTouchStart();
}
swiper.emit('touchStart', e);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | onTouchStart | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function onTouchMove(event) {
const document = getDocument();
const swiper = this;
const data = swiper.touchEventsData;
const {
params,
touches,
rtlTranslate: rtl,
enabled
} = swiper;
if (!enabled) return;
let e = event;
if (e.originalEvent) e = e.originalEvent;
if (!data.isTouched) {
if (data.startMoving && data.isScrolling) {
swiper.emit('touchMoveOpposite', e);
}
return;
}
if (data.isTouchEvent && e.type !== 'touchmove') return;
const targetTouch = e.type === 'touchmove' && e.targetTouches && (e.targetTouches[0] || e.changedTouches[0]);
const pageX = e.type === 'touchmove' ? targetTouch.pageX : e.pageX;
const pageY = e.type === 'touchmove' ? targetTouch.pageY : e.pageY;
if (e.preventedByNestedSwiper) {
touches.startX = pageX;
touches.startY = pageY;
return;
}
if (!swiper.allowTouchMove) {
if (!$(e.target).is(data.focusableElements)) {
swiper.allowClick = false;
}
if (data.isTouched) {
Object.assign(touches, {
startX: pageX,
startY: pageY,
currentX: pageX,
currentY: pageY
});
data.touchStartTime = now();
}
return;
}
if (data.isTouchEvent && params.touchReleaseOnEdges && !params.loop) {
if (swiper.isVertical()) {
// Vertical
if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
data.isTouched = false;
data.isMoved = false;
return;
}
} else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) {
return;
}
}
if (data.isTouchEvent && document.activeElement) {
if (e.target === document.activeElement && $(e.target).is(data.focusableElements)) {
data.isMoved = true;
swiper.allowClick = false;
return;
}
}
if (data.allowTouchCallbacks) {
swiper.emit('touchMove', e);
}
if (e.targetTouches && e.targetTouches.length > 1) return;
touches.currentX = pageX;
touches.currentY = pageY;
const diffX = touches.currentX - touches.startX;
const diffY = touches.currentY - touches.startY;
if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
if (typeof data.isScrolling === 'undefined') {
let touchAngle;
if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
data.isScrolling = false;
} else {
// eslint-disable-next-line
if (diffX * diffX + diffY * diffY >= 25) {
touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
}
}
}
if (data.isScrolling) {
swiper.emit('touchMoveOpposite', e);
}
if (typeof data.startMoving === 'undefined') {
if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
data.startMoving = true;
}
}
if (data.isScrolling) {
data.isTouched = false;
return;
}
if (!data.startMoving) {
return;
}
swiper.allowClick = false;
if (!params.cssMode && e.cancelable) {
e.preventDefault();
}
if (params.touchMoveStopPropagation && !params.nested) {
e.stopPropagation();
}
if (!data.isMoved) {
if (params.loop && !params.cssMode) {
swiper.loopFix();
}
data.startTranslate = swiper.getTranslate();
swiper.setTransition(0);
if (swiper.animating) {
swiper.$wrapperEl.trigger('webkitTransitionEnd transitionend');
}
data.allowMomentumBounce = false; // Grab Cursor
if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
swiper.setGrabCursor(true);
}
swiper.emit('sliderFirstMove', e);
}
swiper.emit('sliderMove', e);
data.isMoved = true;
let diff = swiper.isHorizontal() ? diffX : diffY;
touches.diff = diff;
diff *= params.touchRatio;
if (rtl) diff = -diff;
swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
data.currentTranslate = diff + data.startTranslate;
let disableParentSwiper = true;
let resistanceRatio = params.resistanceRatio;
if (params.touchReleaseOnEdges) {
resistanceRatio = 0;
}
if (diff > 0 && data.currentTranslate > swiper.minTranslate()) {
disableParentSwiper = false;
if (params.resistance) data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
} else if (diff < 0 && data.currentTranslate < swiper.maxTranslate()) {
disableParentSwiper = false;
if (params.resistance) data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
}
if (disableParentSwiper) {
e.preventedByNestedSwiper = true;
} // Directions locks
if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
data.currentTranslate = data.startTranslate;
}
if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
data.currentTranslate = data.startTranslate;
}
if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
data.currentTranslate = data.startTranslate;
} // Threshold
if (params.threshold > 0) {
if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
if (!data.allowThresholdMove) {
data.allowThresholdMove = true;
touches.startX = touches.currentX;
touches.startY = touches.currentY;
data.currentTranslate = data.startTranslate;
touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
return;
}
} else {
data.currentTranslate = data.startTranslate;
return;
}
}
if (!params.followFinger || params.cssMode) return; // Update active index in free mode
if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
swiper.updateActiveIndex();
swiper.updateSlidesClasses();
}
if (swiper.params.freeMode && params.freeMode.enabled && swiper.freeMode) {
swiper.freeMode.onTouchMove();
} // Update progress
swiper.updateProgress(data.currentTranslate); // Update translate
swiper.setTranslate(data.currentTranslate);
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | onTouchMove | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function onTouchEnd(event) {
const swiper = this;
const data = swiper.touchEventsData;
const {
params,
touches,
rtlTranslate: rtl,
slidesGrid,
enabled
} = swiper;
if (!enabled) return;
let e = event;
if (e.originalEvent) e = e.originalEvent;
if (data.allowTouchCallbacks) {
swiper.emit('touchEnd', e);
}
data.allowTouchCallbacks = false;
if (!data.isTouched) {
if (data.isMoved && params.grabCursor) {
swiper.setGrabCursor(false);
}
data.isMoved = false;
data.startMoving = false;
return;
} // Return Grab Cursor
if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
swiper.setGrabCursor(false);
} // Time diff
const touchEndTime = now();
const timeDiff = touchEndTime - data.touchStartTime; // Tap, doubleTap, Click
if (swiper.allowClick) {
const pathTree = e.path || e.composedPath && e.composedPath();
swiper.updateClickedSlide(pathTree && pathTree[0] || e.target);
swiper.emit('tap click', e);
if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
swiper.emit('doubleTap doubleClick', e);
}
}
data.lastClickTime = now();
nextTick(() => {
if (!swiper.destroyed) swiper.allowClick = true;
});
if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 || data.currentTranslate === data.startTranslate) {
data.isTouched = false;
data.isMoved = false;
data.startMoving = false;
return;
}
data.isTouched = false;
data.isMoved = false;
data.startMoving = false;
let currentPos;
if (params.followFinger) {
currentPos = rtl ? swiper.translate : -swiper.translate;
} else {
currentPos = -data.currentTranslate;
}
if (params.cssMode) {
return;
}
if (swiper.params.freeMode && params.freeMode.enabled) {
swiper.freeMode.onTouchEnd({
currentPos
});
return;
} // Find current slide
let stopIndex = 0;
let groupSize = swiper.slidesSizesGrid[0];
for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
if (typeof slidesGrid[i + increment] !== 'undefined') {
if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
stopIndex = i;
groupSize = slidesGrid[i + increment] - slidesGrid[i];
}
} else if (currentPos >= slidesGrid[i]) {
stopIndex = i;
groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
}
}
let rewindFirstIndex = null;
let rewindLastIndex = null;
if (params.rewind) {
if (swiper.isBeginning) {
rewindLastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
} else if (swiper.isEnd) {
rewindFirstIndex = 0;
}
} // Find current slide size
const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
if (timeDiff > params.longSwipesMs) {
// Long touches
if (!params.longSwipes) {
swiper.slideTo(swiper.activeIndex);
return;
}
if (swiper.swipeDirection === 'next') {
if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
}
if (swiper.swipeDirection === 'prev') {
if (ratio > 1 - params.longSwipesRatio) {
swiper.slideTo(stopIndex + increment);
} else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
swiper.slideTo(rewindLastIndex);
} else {
swiper.slideTo(stopIndex);
}
}
} else {
// Short swipes
if (!params.shortSwipes) {
swiper.slideTo(swiper.activeIndex);
return;
}
const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
if (!isNavButtonTarget) {
if (swiper.swipeDirection === 'next') {
swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
}
if (swiper.swipeDirection === 'prev') {
swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
}
} else if (e.target === swiper.navigation.nextEl) {
swiper.slideTo(stopIndex + increment);
} else {
swiper.slideTo(stopIndex);
}
}
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | onTouchEnd | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function onResize() {
const swiper = this;
const {
params,
el
} = swiper;
if (el && el.offsetWidth === 0) return; // Breakpoints
if (params.breakpoints) {
swiper.setBreakpoint();
} // Save locks
const {
allowSlideNext,
allowSlidePrev,
snapGrid
} = swiper; // Disable locks on resize
swiper.allowSlideNext = true;
swiper.allowSlidePrev = true;
swiper.updateSize();
swiper.updateSlides();
swiper.updateSlidesClasses();
if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides) {
swiper.slideTo(swiper.slides.length - 1, 0, false, true);
} else {
swiper.slideTo(swiper.activeIndex, 0, false, true);
}
if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
swiper.autoplay.run();
} // Return locks after resize
swiper.allowSlidePrev = allowSlidePrev;
swiper.allowSlideNext = allowSlideNext;
if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
swiper.checkOverflow();
}
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | onResize | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
function onClick(e) {
const swiper = this;
if (!swiper.enabled) return;
if (!swiper.allowClick) {
if (swiper.params.preventClicks) e.preventDefault();
if (swiper.params.preventClicksPropagation && swiper.animating) {
e.stopPropagation();
e.stopImmediatePropagation();
}
}
} | Determines whether the `index` argument is a valid `number`
after being converted from the `string` type.
@type {boolean} | onClick | javascript | cabloy/cabloy | src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | https://github.com/cabloy/cabloy/blob/master/src/module-system/a-swiper/backend/static/vendor/swiper/8.4.5/swiper-bundle.esm.browser.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.