Search is not available for this dataset
query
stringlengths
7
355k
document
stringlengths
9
341k
metadata
dict
negatives
listlengths
0
101
negative_scores
listlengths
0
101
document_score
stringlengths
3
10
document_rank
stringclasses
102 values
Take an unsorted, potentially overlapping set of ranges, and build a selection out of it. 'Consumes' ranges array (modifying it).
function normalizeSelection(cm, ranges, primIndex) { var mayTouch = cm && cm.options.selectionsMayTouch; var prim = ranges[primIndex]; ranges.sort(function (a, b) { return cmp(a.from(), b.from()); }); primIndex = indexOf(ranges, prim); for (var i = 1; i < ranges.length; i++) { var cur = ranges[i], prev = ranges[i - 1]; var diff = cmp(prev.to(), cur.from()); if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) { var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to()); var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head; if (i <= primIndex) { --primIndex; } ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to)); } } return new Selection(ranges, primIndex) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "static _mergeRanges(ranges, newRange) {\n let inRange = false;\n for (let i = 0; i < ranges.length; i++) {\n const range = ranges[i];\n if (!inRange) {\n if (newRange[1] <= range[0]) {\n // Case 1: New range is before the search range\n ...
[ "0.70186657", "0.6829976", "0.6789967", "0.6774615", "0.6716162", "0.66930807", "0.6687457", "0.6687457", "0.6687457", "0.6687457", "0.6687457", "0.6687457", "0.6687457", "0.6687457", "0.66794205", "0.66419154", "0.6637528", "0.6637528", "0.6637528", "0.6637528", "0.6637528",...
0.6089187
51
Compute the position of the end of a change (its 'to' property refers to the prechange end).
function changeEnd(change) { if (!change.text) { return change.to } return Pos(change.from.line + change.text.length - 1, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0)) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function changeEnd(change) {\n if (!change.text) {\n return change.to;\n }\n\n return Pos(change.from.line + change.text.length - 1, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));\n } // Adjust a position to refer to the post-change position of the", "function changeEnd...
[ "0.8138161", "0.7955729", "0.78994995", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.78986555", "0.67363167", "0.6730652", "0.6653417", "0.6602539", "...
0.7955896
14
Adjust a position to refer to the postchange position of the same text, or the end of the change if the change covers it.
function adjustForChange(pos, change) { if (cmp(pos, change.from) < 0) { return pos } if (cmp(pos, change.to) <= 0) { return changeEnd(change) } var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch; if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; } return Pos(line, ch) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function adjustForChange(pos, change) {\n\t\t if (cmp(pos, change.from) < 0) return pos;\n\t\t if (cmp(pos, change.to) <= 0) return changeEnd(change);\n\t\t\n\t\t var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;\n\t\t if (pos.line == change.to.line) ch +=...
[ "0.7517868", "0.7517113", "0.7476506", "0.74503416", "0.74503416", "0.7446208", "0.74452215", "0.7421781", "0.7421781", "0.7421781", "0.7421781", "0.7421781", "0.7421781", "0.7421781", "0.7409264", "0.73805326", "0.73805326", "0.7374713", "0.7374713", "0.7374713", "0.7374713"...
0.74197316
26
Used by replaceSelections to allow moving the selection to the start or around the replaced test. Hint may be "start" or "around".
function computeReplacedSel(doc, changes, hint) { var out = []; var oldPrev = Pos(doc.first, 0), newPrev = oldPrev; for (var i = 0; i < changes.length; i++) { var change = changes[i]; var from = offsetPos(change.from, oldPrev, newPrev); var to = offsetPos(changeEnd(change), oldPrev, newPrev); oldPrev = change.to; newPrev = to; if (hint == "around") { var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0; out[i] = new Range(inv ? to : from, inv ? from : to); } else { out[i] = new Range(from, from); } } return new Selection(out, doc.sel.primIndex) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "replaceBeforeCursor(start, text) {\n this.insertBetween(start, this.el.selectionStart, text);\n }", "function moveSelection(event) {\n event.preventDefault();\n event.stopPropagation();\n console.log('Calling moveSelection');\n \n optimalApp.selectionPosition[0] = event.pageX - optimalApp.selectionOffse...
[ "0.66458386", "0.6270682", "0.6186922", "0.6150116", "0.6106729", "0.60771316", "0.60734135", "0.600438", "0.6004206", "0.5984542", "0.5984542", "0.5984542", "0.59713507", "0.59500116", "0.59500116", "0.59500116", "0.5949384", "0.593691", "0.58875495", "0.58433455", "0.583540...
0.56655955
65
Used to get the editor into a consistent state again when options change.
function loadMode(cm) { cm.doc.mode = getMode(cm.options, cm.doc.modeOption); resetModeState(cm); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function updateEditor() {\n\t\ttextToEditor();\n\t\tpositionEditorCaret();\n\t}", "optionsUpdateHook() { }", "function _onEditorChanged() {\n\t\t_close();\n\t\tcurrentEditor = EditorManager.getCurrentFullEditor();\n\n\t\tcurrentEditor.$textNode = $(currentEditor.getRootElement()).find(\".CodeMirror-lines\");\n...
[ "0.65174145", "0.6448267", "0.6407012", "0.6382705", "0.63655174", "0.63512903", "0.6341789", "0.6240036", "0.62384015", "0.62281793", "0.6186693", "0.61820716", "0.614012", "0.6127556", "0.61134076", "0.61133647", "0.6105441", "0.6083987", "0.6079587", "0.60270965", "0.60219...
0.0
-1
DOCUMENT DATA STRUCTURE By default, updates that start and end at the beginning of a line are treated specially, in order to make the association of line widgets and marker elements with the text behave more intuitive.
function isWholeLineUpdate(doc, change) { return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" && (!doc.cm || doc.cm.options.wholeLineUpdateBefore) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "update(text, start, end) {\n this.lineOffsets = undefined;\n const content = this.getText();\n this.setText(content.slice(0, start) + text + content.slice(end));\n }", "function updateDoc(doc, change, markedSpans, estimateHeight) {\n\t\t function spansFor(n) {return markedSpans ? marke...
[ "0.621044", "0.5764168", "0.5717833", "0.5717603", "0.5717603", "0.5697177", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56847143", "0.56391287", "0.56391287", "0.56391287", "0....
0.0
-1
Perform a change on the document data structure.
function updateDoc(doc, change, markedSpans, estimateHeight$$1) { function spansFor(n) {return markedSpans ? markedSpans[n] : null} function update(line, text, spans) { updateLine(line, text, spans, estimateHeight$$1); signalLater(line, "change", line, change); } function linesFor(start, end) { var result = []; for (var i = start; i < end; ++i) { result.push(new Line(text[i], spansFor(i), estimateHeight$$1)); } return result } var from = change.from, to = change.to, text = change.text; var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line); var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line; // Adjust the line structure if (change.full) { doc.insert(0, linesFor(0, text.length)); doc.remove(text.length, doc.size - text.length); } else if (isWholeLineUpdate(doc, change)) { // This is a whole-line replace. Treated specially to make // sure line objects move the way they are supposed to. var added = linesFor(0, text.length - 1); update(lastLine, lastLine.text, lastSpans); if (nlines) { doc.remove(from.line, nlines); } if (added.length) { doc.insert(from.line, added); } } else if (firstLine == lastLine) { if (text.length == 1) { update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans); } else { var added$1 = linesFor(1, text.length - 1); added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight$$1)); update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); doc.insert(from.line + 1, added$1); } } else if (text.length == 1) { update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0)); doc.remove(from.line + 1, nlines); } else { update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans); var added$2 = linesFor(1, text.length - 1); if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); } doc.insert(from.line + 1, added$2); } signalLater(doc, "change", doc, change); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "change(docId, doc) {\n const cleanedDoc = this._getCleanedObject(doc);\n let storedDoc = this.store[docId];\n deepExtend(storedDoc, cleanedDoc);\n\n let changedData = {};\n _.each(cleanedDoc, (value, key) => {\n changedData[key] = storedDoc[key];\n });\n\n ...
[ "0.70639664", "0.65255326", "0.60612947", "0.5983165", "0.57900375", "0.5765763", "0.57389504", "0.5728134", "0.56999445", "0.5689289", "0.568801", "0.5685086", "0.5677597", "0.5652581", "0.5643472", "0.563531", "0.563531", "0.563531", "0.56288433", "0.55978465", "0.5595986",...
0.0
-1
Call f for all linked documents.
function linkedDocs(doc, f, sharedHistOnly) { function propagate(doc, skip, sharedHist) { if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) { var rel = doc.linked[i]; if (rel.doc == skip) { continue } var shared = sharedHist && rel.sharedHist; if (sharedHistOnly && !shared) { continue } f(rel.doc, shared); propagate(rel.doc, doc, shared); } } } propagate(doc, null, true); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function linkedDocs(doc, f, sharedHistOnly) {\r\n function propagate(doc, skip, sharedHist) {\r\n if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {\r\n var rel = doc.linked[i];\r\n if (rel.doc == skip) continue;\r\n var shared = sharedHist && rel.sharedHist;\r\n if (...
[ "0.7287167", "0.7266578", "0.7266578", "0.7266578", "0.7266578", "0.7266578", "0.7266578", "0.7266578", "0.7241715", "0.7241715", "0.7241715", "0.72227263", "0.7220414", "0.7196992", "0.7166822", "0.7166822", "0.7166822", "0.7166822", "0.7166822", "0.7166822", "0.7166822", ...
0.7237167
22
Attach a document to an editor.
function attachDoc(cm, doc) { if (doc.cm) { throw new Error("This document is already in use.") } cm.doc = doc; doc.cm = cm; estimateLineHeights(cm); loadMode(cm); setDirectionClass(cm); if (!cm.options.lineWrapping) { findMaxLine(cm); } cm.options.mode = doc.modeOption; regChange(cm); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function attachDoc(cm, doc) {\n\t\t if (doc.cm) throw new Error(\"This document is already in use.\");\n\t\t cm.doc = doc;\n\t\t doc.cm = cm;\n\t\t estimateLineHeights(cm);\n\t\t loadMode(cm);\n\t\t if (!cm.options.lineWrapping) findMaxLine(cm);\n\t\t cm.options.mode = doc.modeOption;\n\t\t ...
[ "0.6626215", "0.6624217", "0.6578821", "0.6578821", "0.6578821", "0.65262896", "0.6516365", "0.6516365", "0.6516365", "0.6516365", "0.6516365", "0.6516365", "0.6516365", "0.64938515", "0.64938515", "0.64938515", "0.6477321", "0.6477321", "0.6477321", "0.6477321", "0.6477321",...
0.64563096
36
Create a history change event from an updateDocstyle change object.
function historyChangeFromChange(doc, change) { var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)}; attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true); return histChange }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function historyChangeFromChange(doc, change) {\n\t\t var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};\n\t\t attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);\n\t\t linkedDocs(doc, function(doc) {attachLocalSpans(do...
[ "0.6958748", "0.69447005", "0.69312567", "0.69312567", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.69231826", "0.6918998", "0.6918998", "0.6918998", "0.6907962", "0.6907962", "0...
0.6886383
37
Pop all selection events off the end of a history array. Stop at a change event.
function clearSelectionEvents(array) { while (array.length) { var last = lst(array); if (last.ranges) { array.pop(); } else { break } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function clearSelectionEvents(array) {\n\t\t while (array.length) {\n\t\t var last = lst(array);\n\t\t if (last.ranges) array.pop();\n\t\t else break;\n\t\t }\n\t\t }", "function clearSelectionEvents(array) {\n while (array.length) {\n var last = lst(array);\n if (last.ranges) ...
[ "0.71146864", "0.71049196", "0.71049196", "0.71049196", "0.71049196", "0.71049196", "0.71049196", "0.71049196", "0.7104582", "0.7101796", "0.7101796", "0.7101796", "0.7078037", "0.69913226", "0.69913226", "0.69913226", "0.69913226", "0.69913226", "0.69913226", "0.69913226", "...
0.7082584
26
Find the top change event in the history. Pop off selection events that are in the way.
function lastChangeEvent(hist, force) { if (force) { clearSelectionEvents(hist.done); return lst(hist.done) } else if (hist.done.length && !lst(hist.done).ranges) { return lst(hist.done) } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) { hist.done.pop(); return lst(hist.done) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function lastChangeEvent(hist, force) {\n if (force) {\n clearSelectionEvents(hist.done);\n return lst(hist.done);\n } else if (hist.done.length && !lst(hist.done).ranges) {\n return lst(hist.done);\n } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {\n hist....
[ "0.6684377", "0.63812923", "0.63594687", "0.6341587", "0.6341587", "0.6341587", "0.6277825", "0.6277825", "0.6277825", "0.6277825", "0.6277825", "0.6277825", "0.6277825", "0.6248254", "0.6231327", "0.6231327", "0.6214123", "0.6214123", "0.6214123", "0.6214123", "0.6214123", ...
0.6287047
20
Register a change in the history. Merges changes that are within a single operation, or are close together with an origin that allows merging (starting with "+") into a single event.
function addChangeToHistory(doc, change, selAfter, opId) { var hist = doc.history; hist.undone.length = 0; var time = +new Date, cur; var last; if ((hist.lastOp == opId || hist.lastOrigin == change.origin && change.origin && ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) || change.origin.charAt(0) == "*")) && (cur = lastChangeEvent(hist, hist.lastOp == opId))) { // Merge this change into the last event last = lst(cur.changes); if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) { // Optimized case for simple insertion -- don't want to add // new changesets for every character typed last.to = changeEnd(change); } else { // Add new sub-event cur.changes.push(historyChangeFromChange(doc, change)); } } else { // Can not be merged, start a new event. var before = lst(hist.done); if (!before || !before.ranges) { pushSelectionToHistory(doc.sel, hist.done); } cur = {changes: [historyChangeFromChange(doc, change)], generation: hist.generation}; hist.done.push(cur); while (hist.done.length > hist.undoDepth) { hist.done.shift(); if (!hist.done[0].ranges) { hist.done.shift(); } } } hist.done.push(selAfter); hist.generation = ++hist.maxGeneration; hist.lastModTime = hist.lastSelTime = time; hist.lastOp = hist.lastSelOp = opId; hist.lastOrigin = hist.lastSelOrigin = change.origin; if (!last) { signal(doc, "historyAdded"); } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function addChangeToHistory(doc, change, selAfter, opId) {\n var hist = doc.history;\n hist.undone.length = 0;\n var time = +new Date, cur;\n\n if ((hist.lastOp == opId ||\n hist.lastOrigin == change.origin && change.origin &&\n ((change.origin.charAt(0) == \"+\" && doc.cm && hist.lastM...
[ "0.6184258", "0.6176788", "0.6174049", "0.6174049", "0.6174049", "0.6174049", "0.6174049", "0.6174049", "0.6159121", "0.6155636", "0.6155636", "0.61505264", "0.6144719", "0.61193234", "0.611699", "0.611699", "0.6108021", "0.6108021", "0.6108021", "0.6108021", "0.6108021", "...
0.6182238
14
Called whenever the selection changes, sets the new selection as the pending selection in the history, and pushes the old pending selection into the 'done' array when it was significantly different (in number of selected ranges, emptiness, or time).
function addSelectionToHistory(doc, sel, opId, options) { var hist = doc.history, origin = options && options.origin; // A new event is started when the previous origin does not match // the current, or the origins don't allow matching. Origins // starting with * are always merged, those starting with + are // merged when similar and close together in time. if (opId == hist.lastSelOp || (origin && hist.lastSelOrigin == origin && (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin || selectionEventCanBeMerged(doc, origin, lst(hist.done), sel)))) { hist.done[hist.done.length - 1] = sel; } else { pushSelectionToHistory(sel, hist.done); } hist.lastSelTime = +new Date; hist.lastSelOrigin = origin; hist.lastSelOp = opId; if (options && options.clearRedo !== false) { clearSelectionEvents(hist.undone); } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "_gcSelections () {\n for (let i = 0; i < this._selections.length; ++i) {\n const s = this._selections[i]\n const oldOffset = s.offset\n\n // check for newly downloaded pieces in selection\n while (this.bitfield.get(s.from + s.offset) && s.from + s.offset < s.to) {\n s.offset += 1\n ...
[ "0.66129965", "0.66129965", "0.66129965", "0.6407596", "0.63369757", "0.62601", "0.62601", "0.62601", "0.61667717", "0.61398435", "0.6102082", "0.6090417", "0.6090417", "0.6082805", "0.60528", "0.6051035", "0.6049311", "0.6049311", "0.6045188", "0.6044834", "0.60216063", "0...
0.60189223
41
Used to store marked span information in the history.
function attachLocalSpans(doc, change, from, to) { var existing = change["spans_" + doc.id], n = 0; doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) { if (line.markedSpans) { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; } ++n; }); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function addMarkedSpan(line, span) {\n\t\t line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];\n\t\t span.marker.attachLine(line);\n\t\t }", "function addMarkedSpan(line, span) {\n\t line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];\n\t span....
[ "0.6327484", "0.6285503", "0.6285503", "0.6285503", "0.62029684", "0.61554384", "0.6131782", "0.6125477", "0.6125477", "0.6085742", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.60608774", "0.6...
0.54982615
81
When un/redoing restores text containing marked spans, those that have been explicitly cleared should not be restored.
function removeClearedSpans(spans) { if (!spans) { return null } var out; for (var i = 0; i < spans.length; ++i) { if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } } else if (out) { out.push(spans[i]); } } return !out ? spans : out.length ? out : null }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function remark() {\n for (var i = 0; i < vm.game.marked.length; i++) {\n var element = angular.element(document.getElementById('text-' + i));\n var marked = vm.game.marked[i];\n element.removeClass('last');\n element.removeClass('first');\n ...
[ "0.6540399", "0.65239275", "0.64625597", "0.6355469", "0.6310737", "0.6300743", "0.6291497", "0.62827456", "0.6254119", "0.6254119", "0.6254119", "0.623765", "0.62102455", "0.62023807", "0.6201539", "0.62006426", "0.61960566", "0.61960566", "0.61960566", "0.61960566", "0.6196...
0.0
-1
Retrieve and filter the old marked spans stored in a change event.
function getOldSpans(doc, change) { var found = change["spans_" + doc.id]; if (!found) { return null } var nw = []; for (var i = 0; i < change.text.length; ++i) { nw.push(removeClearedSpans(found[i])); } return nw }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function getOldSpans(doc, change) {\n\t\t var found = change[\"spans_\" + doc.id];\n\t\t if (!found) { return null }\n\t\t var nw = [];\n\t\t for (var i = 0; i < change.text.length; ++i)\n\t\t { nw.push(removeClearedSpans(found[i])); }\n\t\t return nw\n\t\t }", "function getOldSpans(doc, cha...
[ "0.7795729", "0.7775589", "0.7745061", "0.7745061", "0.7745061", "0.76677495", "0.76677495", "0.76677495", "0.76677495", "0.76677495", "0.76677495", "0.76677495", "0.76551306", "0.7651843", "0.7651843", "0.7651643", "0.76475054", "0.76475054", "0.76475054", "0.76475054", "0.7...
0.77104664
19
Used for un/redoing changes from the history. Combines the result of computing the existing spans with the set of spans that existed in the history (so that deleting around a span and then undoing brings back the span).
function mergeOldSpans(doc, change) { var old = getOldSpans(doc, change); var stretched = stretchSpansOverChange(doc, change); if (!old) { return stretched } if (!stretched) { return old } for (var i = 0; i < old.length; ++i) { var oldCur = old[i], stretchCur = stretched[i]; if (oldCur && stretchCur) { spans: for (var j = 0; j < stretchCur.length; ++j) { var span = stretchCur[j]; for (var k = 0; k < oldCur.length; ++k) { if (oldCur[k].marker == span.marker) { continue spans } } oldCur.push(span); } } else if (stretchCur) { old[i] = stretchCur; } } return old }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function getOldSpans(doc, change) {\n\t\t var found = change[\"spans_\" + doc.id];\n\t\t if (!found) return null;\n\t\t for (var i = 0, nw = []; i < change.text.length; ++i)\n\t\t nw.push(removeClearedSpans(found[i]));\n\t\t return nw;\n\t\t }", "function getOldSpans(doc, change) {\n\t\t var...
[ "0.6204699", "0.61835754", "0.61484516", "0.61484516", "0.61484516", "0.60746247", "0.60746247", "0.60746247", "0.60746247", "0.60746247", "0.60746247", "0.60746247", "0.6069308", "0.6057101", "0.6032919", "0.6032919", "0.6032919", "0.6032919", "0.6032919", "0.6032919", "0.60...
0.0
-1
Used both to provide a JSONsafe object in .getHistory, and, when detaching a document, to split the history in two
function copyHistoryArray(events, newGroup, instantiateSel) { var copy = []; for (var i = 0; i < events.length; ++i) { var event = events[i]; if (event.ranges) { copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event); continue } var changes = event.changes, newChanges = []; copy.push({changes: newChanges}); for (var j = 0; j < changes.length; ++j) { var change = changes[j], m = (void 0); newChanges.push({from: change.from, to: change.to, text: change.text}); if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) { if (indexOf(newGroup, Number(m[1])) > -1) { lst(newChanges)[prop] = change[prop]; delete change[prop]; } } } } } } return copy }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "serializeHistory(state) {\r\n if (!state)\r\n return null;\r\n // Ensure sure that all entries have url\r\n var entries = state.entries.filter(e => e.url);\r\n if (!entries.length)\r\n return null;\r\n // Ensure the index is in bounds.\r\n var index = (state.index || entries.length) - 1...
[ "0.6126061", "0.5970489", "0.5749906", "0.56571066", "0.56460977", "0.5573177", "0.5573177", "0.5573177", "0.55647707", "0.55647707", "0.55647707", "0.55647707", "0.55647707", "0.55647707", "0.55647707", "0.5560216", "0.5555117", "0.5555117", "0.5555117", "0.5555117", "0.5555...
0.0
-1
The 'scroll' parameter given to many of these indicated whether the new cursor position should be scrolled into view after modifying the selection. If shift is held or the extend flag is set, extends a range to include a given position (and optionally a second position). Otherwise, simply returns the range between the given positions. Used for cursor motion and such.
function extendRange(range, head, other, extend) { if (extend) { var anchor = range.anchor; if (other) { var posBefore = cmp(head, anchor) < 0; if (posBefore != (cmp(other, anchor) < 0)) { anchor = head; head = other; } else if (posBefore != (cmp(head, other) < 0)) { head = other; } } return new Range(anchor, head) } else { return new Range(other || head, head) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function extendRange(doc, range, head, other) {\n\t\t if (doc.cm && doc.cm.display.shift || doc.extend) {\n\t\t var anchor = range.anchor;\n\t\t if (other) {\n\t\t var posBefore = cmp(head, anchor) < 0;\n\t\t if (posBefore != (cmp(other, anchor) < 0)) {\n\t\t anchor = head;\n\t\...
[ "0.64116293", "0.6395189", "0.6395189", "0.6395189", "0.6305622", "0.62692595", "0.62692595", "0.62692595", "0.62692595", "0.62692595", "0.62692595", "0.62692595", "0.62692595", "0.62262756", "0.62262756", "0.6141464", "0.59685487", "0.5950896", "0.5858771", "0.5840827", "0.5...
0.5831049
43
Extend the primary selection range, discard the rest.
function extendSelection(doc, head, other, options, extend) { if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); } setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function extendRange(range, head, other, extend) {\n if (extend) {\n var anchor = range.anchor;\n\n if (other) {\n var posBefore = cmp(head, anchor) < 0;\n\n if (posBefore != cmp(other, anchor) < 0) {\n anchor = head;\n head = other;\n } else if (posBefore != cmp...
[ "0.7361317", "0.72121984", "0.71236956", "0.71236956", "0.71236956", "0.7040623", "0.7038878", "0.7036874", "0.7036874", "0.7036874", "0.7036874", "0.7036874", "0.7036874", "0.7036874", "0.7036874", "0.70040554", "0.70040554", "0.67941666", "0.6732129", "0.6732129", "0.673212...
0.6841599
30
Extend all selections (pos is an array of selections with length equal the number of selections)
function extendSelections(doc, heads, options) { var out = []; var extend = doc.cm && (doc.cm.display.shift || doc.extend); for (var i = 0; i < doc.sel.ranges.length; i++) { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); } var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex); setSelection(doc, newSel, options); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function extendSelections(doc, heads, options) {\n\t\t for (var out = [], i = 0; i < doc.sel.ranges.length; i++)\n\t\t out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);\n\t\t var newSel = normalizeSelection(out, doc.sel.primIndex);\n\t\t setSelection(doc, newSel, options);\n\t\t }", "f...
[ "0.67245656", "0.6698209", "0.6698209", "0.6698209", "0.66711736", "0.66366756", "0.6630632", "0.6630632", "0.6630632", "0.6630632", "0.6630632", "0.6630632", "0.6630632", "0.6630632", "0.6622489", "0.65663224", "0.65663224", "0.65525466", "0.65525466", "0.65525466", "0.65331...
0.63706243
41
Updates a single range in the selection.
function replaceOneSelection(doc, i, range, options) { var ranges = doc.sel.ranges.slice(0); ranges[i] = range; setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "updateInRange(editor, range, offset = 0, updateFunc) {\n const baseRange = editor.getSelectedRange();\n editor.setSelectedRange(range);\n updateFunc();\n editor.setSelectedRange([baseRange[0] + offset, baseRange[1] + offset]);\n }", "updateRange(start, end) {\n this.range.start = start\n this....
[ "0.7218381", "0.69966", "0.6366824", "0.6361162", "0.6361162", "0.6361162", "0.63484067", "0.63484067", "0.63484067", "0.63484067", "0.63484067", "0.63484067", "0.63484067", "0.63484067", "0.63363445", "0.63199526", "0.63136816", "0.63136816", "0.6311347", "0.6283103", "0.626...
0.62980735
35
Reset the selection to a single range.
function setSimpleSelection(doc, anchor, head, options) { setSelection(doc, simpleSelection(anchor, head), options); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "_resetSelection() {\n this.__selectedRangeArr = [];\n this.__anchorSelectionIndex = -1;\n this.__leadSelectionIndex = -1;\n }", "restoreRange() {\n if (this.lastRange) {\n this.lastRange.select();\n this.focus();\n }\n }", "reset() {\n this._selection = -1;\n }", "funct...
[ "0.79797", "0.7659073", "0.7618294", "0.74684507", "0.74392134", "0.7276428", "0.7236947", "0.7173246", "0.6906848", "0.6906848", "0.6906848", "0.688273", "0.687953", "0.687953", "0.687953", "0.687953", "0.687953", "0.687953", "0.687953", "0.687953", "0.6857984", "0.6857239...
0.0
-1
Give beforeSelectionChange handlers a change to influence a selection update.
function filterSelectionChange(doc, sel, options) { var obj = { ranges: sel.ranges, update: function(ranges) { var this$1 = this; this.ranges = []; for (var i = 0; i < ranges.length; i++) { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor), clipPos(doc, ranges[i].head)); } }, origin: options && options.origin }; signal(doc, "beforeSelectionChange", doc, obj); if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); } if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) } else { return sel } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function SelectionChange() {}", "function SelectionChange() {}", "function SelectionChange() {}", "function SelectionChange() {}", "function SelectionChange() { }", "function SelectionChange() { }", "beforeSelectRow(rowid, e){\n }", "selectionChanged(context, onContextChanged) {\n retur...
[ "0.7436134", "0.7436134", "0.7436134", "0.7436134", "0.7315609", "0.7315609", "0.64987767", "0.6486742", "0.64495426", "0.64479816", "0.6396452", "0.6395277", "0.6395277", "0.6395277", "0.6390618", "0.6350694", "0.63113916", "0.6283778", "0.6238949", "0.6238949", "0.61821294"...
0.5919608
60
Set a new selection.
function setSelection(doc, sel, options) { setSelectionNoUndo(doc, sel, options); addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function setSelection(doc, sel, options) {\n\t\t setSelectionNoUndo(doc, sel, options);\n\t\t addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);\n\t\t }", "function setSelection(doc, sel, options) {\n\t\t setSelectionNoUndo(doc, sel, options);\n\t\t addSelectionToHistory(d...
[ "0.7453179", "0.7453179", "0.7395772", "0.7395772", "0.7395772", "0.7356902", "0.72738075", "0.72738075", "0.7272042", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.724487", "0.7192502", "0.6912936...
0.7300484
29
Verify that the selection does not partially select any atomic marked ranges.
function reCheckSelection(doc) { setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false)); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "get hasSelection() {\n const start = this._model.finalSelectionStart;\n const end = this._model.finalSelectionEnd;\n if (!start || !end) {\n return false;\n }\n return start[0] !== end[0] || start[1] !== end[1];\n }", "function selectionIsSane() {\n\t\t\tvar minSi...
[ "0.6870172", "0.60677147", "0.6066715", "0.6055218", "0.60424894", "0.5962891", "0.5962891", "0.5962891", "0.5962891", "0.5962891", "0.5962891", "0.5962891", "0.596198", "0.5916995", "0.5891306", "0.5881634", "0.5881634", "0.5879924", "0.5879924", "0.5879924", "0.5879924", ...
0.57861257
68
Return a selection that does not partially select any atomic ranges.
function skipAtomicInSelection(doc, sel, bias, mayClear) { var out; for (var i = 0; i < sel.ranges.length; i++) { var range = sel.ranges[i]; var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]; var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear); var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear); if (out || newAnchor != range.anchor || newHead != range.head) { if (!out) { out = sel.ranges.slice(0, i); } out[i] = new Range(newAnchor, newHead); } } return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "selection_excluding(cells) {\n const selection = new Set(this.selection);\n for (const cell of cells) {\n selection.delete(cell);\n }\n return selection;\n }", "function skipAtomicInSelection(doc, sel, bias, mayClear) {\n var out;\n for (var i = 0; i < sel.ranges.l...
[ "0.6847842", "0.6637457", "0.6637457", "0.6637457", "0.6637457", "0.6637457", "0.6637457", "0.6637457", "0.6596417", "0.6477013", "0.6475794", "0.6475794", "0.6437837", "0.6437837", "0.6437837", "0.6437837", "0.6437837", "0.6437837", "0.6437837", "0.6437837", "0.6437837", "...
0.6439841
23
Ensure a given position is not inside an atomic range.
function skipAtomic(doc, pos, oldPos, bias, mayClear) { var dir = bias || 1; var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) || (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) || skipAtomicInner(doc, pos, oldPos, -dir, mayClear) || (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true)); if (!found) { doc.cantEdit = true; return Pos(doc.first, 0) } return found }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "static isInsideRange(position, range) {\n if (range.start.line === range.end.line) {\n return range.start.line === position.line\n && range.start.character <= position.character\n && position.character <= range.end.character;\n }\n else if (range.start....
[ "0.59879375", "0.5966708", "0.59146243", "0.562402", "0.56166", "0.5598513", "0.5584527", "0.5547357", "0.5532226", "0.5531274", "0.5508034", "0.54775023", "0.547714", "0.5409574", "0.54091066", "0.5399065", "0.5388472", "0.5386206", "0.53633547", "0.5344547", "0.5343511", ...
0.0
-1
UPDATING Allow "beforeChange" event handlers to influence a change
function filterChange(doc, change, update) { var obj = { canceled: false, from: change.from, to: change.to, text: change.text, origin: change.origin, cancel: function () { return obj.canceled = true; } }; if (update) { obj.update = function (from, to, text, origin) { if (from) { obj.from = clipPos(doc, from); } if (to) { obj.to = clipPos(doc, to); } if (text) { obj.text = text; } if (origin !== undefined) { obj.origin = origin; } }; } signal(doc, "beforeChange", doc, obj); if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); } if (obj.canceled) { return null } return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "_beforeChange () {\n // nop\n }", "_beforeChange () {\n // nop\n }", "afterValidChange() { }", "internalOnChange(event) {\n const me = this,\n value = me.value,\n oldValue = me._lastValue;\n\n // Don't trigger change if we enter invalid value or if value has not changed (for IE when p...
[ "0.79965526", "0.79965526", "0.73935664", "0.71237224", "0.71210444", "0.69660723", "0.69213545", "0.6910988", "0.6855578", "0.6853958", "0.6851805", "0.68481123", "0.68263054", "0.68100536", "0.6746932", "0.6740989", "0.67285186", "0.67158806", "0.6686307", "0.66838264", "0....
0.0
-1
Apply a change to a document, and add it to the document's history, and propagating it to all linked documents.
function makeChange(doc, change, ignoreReadOnly) { if (doc.cm) { if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) } if (doc.cm.state.suppressEdits) { return } } if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) { change = filterChange(doc, change, true); if (!change) { return } } // Possibly split or suppress the update based on the presence // of read-only spans in its range. var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to); if (split) { for (var i = split.length - 1; i >= 0; --i) { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); } } else { makeChangeInner(doc, change); } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "apply(doc) {\n if (this.length != doc.length)\n throw new RangeError(\"Applying change set to a document with the wrong length\");\n iterChanges(this, (fromA, toA, fromB, _toB, text) => doc = doc.replace(fromB, fromB + (toA - fromA), text), false);\n return doc;\n }", "function...
[ "0.63618726", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.6286882", "0.62850475", "0.6271915", "0.6271915", "0.6271915", "0.6271915", "0.6271915", "0.6271915", "0.6271915", "0.6271915", ...
0.0
-1
Revert a change stored in a document's history.
function makeChangeFromHistory(doc, type, allowSelectionOnly) { var suppress = doc.cm && doc.cm.state.suppressEdits; if (suppress && !allowSelectionOnly) { return } var hist = doc.history, event, selAfter = doc.sel; var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done; // Verify that there is a useable event (so that ctrl-z won't // needlessly clear selection events) var i = 0; for (; i < source.length; i++) { event = source[i]; if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges) { break } } if (i == source.length) { return } hist.lastOrigin = hist.lastSelOrigin = null; for (;;) { event = source.pop(); if (event.ranges) { pushSelectionToHistory(event, dest); if (allowSelectionOnly && !event.equals(doc.sel)) { setSelection(doc, event, {clearRedo: false}); return } selAfter = event; } else if (suppress) { source.push(event); return } else { break } } // Build up a reverse change object to add to the opposite history // stack (redo when undoing, and vice versa). var antiChanges = []; pushSelectionToHistory(selAfter, dest); dest.push({changes: antiChanges, generation: hist.generation}); hist.generation = event.generation || ++hist.maxGeneration; var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange"); var loop = function ( i ) { var change = event.changes[i]; change.origin = type; if (filter && !filterChange(doc, change, false)) { source.length = 0; return {} } antiChanges.push(historyChangeFromChange(doc, change)); var after = i ? computeSelAfterChange(doc, change) : lst(source); makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change)); if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); } var rebased = []; // Propagate to the linked documents linkedDocs(doc, function (doc, sharedHist) { if (!sharedHist && indexOf(rebased, doc.history) == -1) { rebaseHist(doc.history, change); rebased.push(doc.history); } makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change)); }); }; for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) { var returned = loop( i$1 ); if ( returned ) return returned.v; } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function undo() {\n var doc = app.activeDocument;\n var states = doc.historyStates;\n \n var curr = 0;\n for (var i=0; i<states.length; i++) {\n if (states[i] == doc.activeHistoryState) {\n curr = i;\n }\n }\n \n var prev ...
[ "0.666816", "0.66606236", "0.66574264", "0.6404945", "0.6340584", "0.6331039", "0.627892", "0.627892", "0.62788844", "0.62650436", "0.62059116", "0.6139741", "0.6129738", "0.6100485", "0.60984457", "0.609307", "0.6078671", "0.59942985", "0.59702957", "0.59355396", "0.5929626"...
0.0
-1
Subviews need their line numbers shifted when text is added above or below them in the parent document.
function shiftDoc(doc, distance) { if (distance == 0) { return } doc.first += distance; doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range( Pos(range.anchor.line + distance, range.anchor.ch), Pos(range.head.line + distance, range.head.ch) ); }), doc.sel.primIndex); if (doc.cm) { regChange(doc.cm, doc.first, doc.first - distance, distance); for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++) { regLineChange(doc.cm, l, "gutter"); } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function bn(e,t,a,n){null==t&&(t=e.doc.first),null==a&&(a=e.doc.first+e.doc.size),n||(n=0);var r=e.display;if(n&&a<r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>t)&&(r.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=r.viewTo)// Change after\n Jo&&pe(e.doc,t)<r.viewTo&&vn(e);else if(a<=r.viewFrom)// C...
[ "0.59886837", "0.5932061", "0.5651753", "0.56376565", "0.55780476", "0.55274785", "0.55163205", "0.55099046", "0.5506641", "0.54507947", "0.5449167", "0.5448703", "0.54459953", "0.54459953", "0.54459953", "0.54459953", "0.54459953", "0.54459953", "0.54459953", "0.54459953", "...
0.0
-1
More lowerlevel change function, handling only a single document (not linked ones).
function makeChangeSingleDoc(doc, change, selAfter, spans) { if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) } if (change.to.line < doc.first) { shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line)); return } if (change.from.line > doc.lastLine()) { return } // Clip the change to the size of this doc if (change.from.line < doc.first) { var shift = change.text.length - 1 - (doc.first - change.from.line); shiftDoc(doc, shift); change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch), text: [lst(change.text)], origin: change.origin}; } var last = doc.lastLine(); if (change.to.line > last) { change = {from: change.from, to: Pos(last, getLine(doc, last).text.length), text: [change.text[0]], origin: change.origin}; } change.removed = getBetween(doc, change.from, change.to); if (!selAfter) { selAfter = computeSelAfterChange(doc, change); } if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); } else { updateDoc(doc, change, spans); } setSelectionNoUndo(doc, selAfter, sel_dontScroll); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "change(docId, doc) {\n const cleanedDoc = this._getCleanedObject(doc);\n let storedDoc = this.store[docId];\n deepExtend(storedDoc, cleanedDoc);\n\n let changedData = {};\n _.each(cleanedDoc, (value, key) => {\n changedData[key] = storedDoc[key];\n });\n\n ...
[ "0.70032144", "0.66065466", "0.6573964", "0.65447193", "0.6487679", "0.6487679", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.6454598", "0.640634", "0.640634", "0.640634", "...
0.6435666
21
Handle the interaction of a change to a document with the editor that this document is part of.
function makeChangeSingleDocInEditor(cm, change, spans) { var doc = cm.doc, display = cm.display, from = change.from, to = change.to; var recomputeMaxLength = false, checkWidthStart = from.line; if (!cm.options.lineWrapping) { checkWidthStart = lineNo(visualLine(getLine(doc, from.line))); doc.iter(checkWidthStart, to.line + 1, function (line) { if (line == display.maxLine) { recomputeMaxLength = true; return true } }); } if (doc.sel.contains(change.from, change.to) > -1) { signalCursorActivity(cm); } updateDoc(doc, change, spans, estimateHeight(cm)); if (!cm.options.lineWrapping) { doc.iter(checkWidthStart, from.line + change.text.length, function (line) { var len = lineLength(line); if (len > display.maxLineLength) { display.maxLine = line; display.maxLineLength = len; display.maxLineChanged = true; recomputeMaxLength = false; } }); if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; } } retreatFrontier(doc, from.line); startWorker(cm, 400); var lendiff = change.text.length - (to.line - from.line) - 1; // Remember that these lines changed, for updating the display if (change.full) { regChange(cm); } else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) { regLineChange(cm, from.line, "text"); } else { regChange(cm, from.line, to.line + 1, lendiff); } var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change"); if (changeHandler || changesHandler) { var obj = { from: from, to: to, text: change.text, removed: change.removed, origin: change.origin }; if (changeHandler) { signalLater(cm, "change", cm, obj); } if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); } } cm.display.selForContextMenu = null; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function _onCurrentDocumentChange() {\n var doc = DocumentManager.getCurrentDocument(),\n container = _editorHolder.get(0);\n \n var perfTimerName = PerfUtils.markStart(\"EditorManager._onCurrentDocumentChange():\\t\" + (!doc || doc.file.fullPath));\n\n // Remove scroller-sha...
[ "0.6988773", "0.68636054", "0.6660369", "0.659211", "0.65215796", "0.638791", "0.6327432", "0.63088477", "0.62785864", "0.62495303", "0.6163697", "0.6127141", "0.6116209", "0.6116209", "0.6100855", "0.60965884", "0.6076851", "0.6076851", "0.6037296", "0.60166854", "0.60105", ...
0.59418476
58
Rebasing/resetting history to deal with externallysourced changes
function rebaseHistSelSingle(pos, from, to, diff) { if (to < pos.line) { pos.line += diff; } else if (from < pos.line) { pos.line = from; pos.ch = 0; } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function resetHistory() {\n // TODO: clean out localStorage\n ExCommandHistory.resetHistory();\n }", "function clearChangeHistory() {\n changeHistory = [];\n historyPosition = 0;\n }", "function setHistory() {\n // clear undo history\n $('#undoHistoryList')\n .empty()...
[ "0.7397952", "0.7375274", "0.711438", "0.6920561", "0.6904765", "0.687358", "0.686189", "0.680521", "0.67269665", "0.6600654", "0.6581299", "0.65552354", "0.65401167", "0.6529911", "0.6517975", "0.6485189", "0.6480019", "0.64591163", "0.6439742", "0.64371014", "0.64327615", ...
0.0
-1
Tries to rebase an array of history events given a change in the document. If the change touches the same lines as the event, the event, and everything 'behind' it, is discarded. If the change is before the event, the event's positions are updated. Uses a copyonwrite scheme for the positions, to avoid having to reallocate them all on every rebase, but also avoid problems with shared position objects being unsafely updated.
function rebaseHistArray(array, from, to, diff) { for (var i = 0; i < array.length; ++i) { var sub = array[i], ok = true; if (sub.ranges) { if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; } for (var j = 0; j < sub.ranges.length; j++) { rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff); rebaseHistSelSingle(sub.ranges[j].head, from, to, diff); } continue } for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) { var cur = sub.changes[j$1]; if (to < cur.from.line) { cur.from = Pos(cur.from.line + diff, cur.from.ch); cur.to = Pos(cur.to.line + diff, cur.to.ch); } else if (from <= cur.to.line) { ok = false; break } } if (!ok) { array.splice(0, i + 1); i = 0; } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function rebaseHistArray(array, from, to, diff) {\n for (var i = 0; i < array.length; ++i) {\n var sub = array[i], ok = true;\n for (var j = 0; j < sub.changes.length; ++j) {\n var cur = sub.changes[j];\n if (!sub.copied) { cur.from = copyPos(cur.from); cur.to = copyPos(cur.to); }\n ...
[ "0.6718455", "0.6718455", "0.6718455", "0.6718455", "0.6492295", "0.648774", "0.6472811", "0.6472811", "0.6472811", "0.6472811", "0.6472811", "0.6472811", "0.6472811", "0.64685804", "0.64341486", "0.64341486", "0.6425354", "0.6421519", "0.63940966", "0.63940966", "0.63940966"...
0.64719915
28
Utility for applying a change to a line by handle or number, returning the number and optionally registering the line as changed.
function changeLine(doc, handle, changeType, op) { var no = handle, line = handle; if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); } else { no = lineNo(handle); } if (no == null) { return null } if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); } return line }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function changeLine(doc, handle, changeType, op) {\n\t var no = handle, line = handle;\n\t if (typeof handle == \"number\") line = getLine(doc, clipLine(doc, handle));\n\t else no = lineNo(handle);\n\t if (no == null) return null;\n\t if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType)...
[ "0.7356353", "0.7356353", "0.7356353", "0.73486423", "0.73486423", "0.73486423", "0.73486423", "0.73486423", "0.73486423", "0.73486423", "0.7346209", "0.73159844", "0.7314361", "0.7234829", "0.7234829", "0.7226441", "0.7226441", "0.7226441", "0.7226441", "0.7226441", "0.72264...
0.73417675
24
The document is represented as a BTree consisting of leaves, with chunk of lines in them, and branches, with up to ten leaves or other branch nodes below them. The top node is always a branch node, and is the document object itself (meaning it has additional methods and properties). All nodes have parent links. The tree is used both to go from line numbers to line objects, and to go from objects to numbers. It also indexes by height, and is used to convert between height and line object, and to find the total height of the document. See also
function LeafChunk(lines) { var this$1 = this; this.lines = lines; this.parent = null; var height = 0; for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1; height += lines[i].height; } this.height = height; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function BTree(){\n\tthis.root = null;\n\tthis.length = 0;\n}", "function documentFragment(children, height, depth, maxFontSize) {\n this.children = children || [];\n this.height = height || 0;\n this.depth = depth || 0;\n this.maxFontSize = maxFontSize || 0;\n}", "function documentFragment(childre...
[ "0.56859744", "0.54539", "0.54539", "0.53151244", "0.5282311", "0.5281514", "0.5276573", "0.52501154", "0.52340657", "0.5199419", "0.51836556", "0.51800025", "0.5177543", "0.51744926", "0.5172286", "0.5172286", "0.5167587", "0.5155838", "0.5155838", "0.5152973", "0.5139416", ...
0.5045281
49
Create a marker, wire it up to the right lines, and
function markText(doc, from, to, options, type) { // Shared markers (across linked documents) are handled separately // (markTextShared will call out to this again, once per // document). if (options && options.shared) { return markTextShared(doc, from, to, options, type) } // Ensure we are in an operation. if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) } var marker = new TextMarker(doc, type), diff = cmp(from, to); if (options) { copyObj(options, marker, false); } // Don't connect empty markers unless clearWhenEmpty is false if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) { return marker } if (marker.replacedWith) { // Showing up as a widget implies collapsed (widget replaces text) marker.collapsed = true; marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget"); if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); } if (options.insertLeft) { marker.widgetNode.insertLeft = true; } } if (marker.collapsed) { if (conflictingCollapsedRange(doc, from.line, from, to, marker) || from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) { throw new Error("Inserting collapsed marker partially overlapping an existing one") } seeCollapsedSpans(); } if (marker.addToHistory) { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); } var curLine = from.line, cm = doc.cm, updateMaxLine; doc.iter(curLine, to.line + 1, function (line) { if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) { updateMaxLine = true; } if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); } addMarkedSpan(line, new MarkedSpan(marker, curLine == from.line ? from.ch : null, curLine == to.line ? to.ch : null)); ++curLine; }); // lineIsHidden depends on the presence of the spans, so needs a second pass if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) { if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); } }); } if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); } if (marker.readOnly) { seeReadOnlySpans(); if (doc.history.done.length || doc.history.undone.length) { doc.clearHistory(); } } if (marker.collapsed) { marker.id = ++nextMarkerId; marker.atomic = true; } if (cm) { // Sync editor state if (updateMaxLine) { cm.curOp.updateMaxLine = true; } if (marker.collapsed) { regChange(cm, from.line, to.line + 1); } else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css) { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } } if (marker.atomic) { reCheckSelection(cm.doc); } signalLater(cm, "markerAdded", cm, marker); } return marker }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function drawMarker(lineWidth, lineHeightPerc, offset, markerLength, horiz) {\n var start, end;\n var height = em.height();\n if (horiz) {\n start = { x: offset, y: height};\n end = { x: offset, y: height - (markerLength*lineHeightPerc)};\n...
[ "0.706403", "0.6922555", "0.6829682", "0.67605793", "0.6707079", "0.66788775", "0.6592433", "0.6586964", "0.6577096", "0.6535049", "0.645897", "0.6454014", "0.6452927", "0.644539", "0.6428748", "0.64162165", "0.63716215", "0.6367775", "0.63661844", "0.6362076", "0.6345258", ...
0.0
-1
These must be handled carefully, because naively registering a handler for each editor will cause the editors to never be garbage collected.
function forEachCodeMirror(f) { if (!document.getElementsByClassName) { return } var byClass = document.getElementsByClassName("CodeMirror"); for (var i = 0; i < byClass.length; i++) { var cm = byClass[i].CodeMirror; if (cm) { f(cm); } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function _registerHandlers(editor) {\n $(editor).on(\"keyEvent\", _cursorHandler);\n $(editor.document).one(\"change\", _handler);\n editor.document.addRef();\n }", "getEditorListeners() {\n return {\n focusout: 'onEditorFocusOut',\n focusin: 'onEditorFocusIn',\n start: ...
[ "0.7412128", "0.6621844", "0.6621844", "0.6262634", "0.6257714", "0.607542", "0.6045522", "0.60446435", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", "0.597748", ...
0.0
-1
Called when the window resizes
function onResize(cm) { var d = cm.display; // Might be a text scaling operation, clear size caches. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null; d.scrollbarsClipped = false; cm.setSize(); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function onWindowResize() {\n updateSizes();\n }", "function windowResized() {\n resize();\n redraw();\n}", "onWindowResize() {\n\t\tthis.windowHeight = this.getWindowHeight();\n\t\tthis.updatePosition();\n\t}", "function onWindowResize() {\n\n\t\t\t}", "function windowResized() {\n resizeCanvas...
[ "0.8751041", "0.8488573", "0.84693223", "0.8312482", "0.79967594", "0.79899037", "0.79610854", "0.79416203", "0.7917026", "0.7901147", "0.78813344", "0.78804415", "0.7867091", "0.7867091", "0.78272027", "0.7821096", "0.78160036", "0.7803246", "0.77958447", "0.7787981", "0.778...
0.0
-1
This is a kludge to keep keymaps mostly working as raw objects (backwards compatibility) while at the same time support features like normalization and multistroke key bindings. It compiles a new normalized keymap, and then updates the old object to reflect this.
function normalizeKeyMap(keymap) { var copy = {}; for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) { var value = keymap[keyname]; if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue } if (value == "...") { delete keymap[keyname]; continue } var keys = map(keyname.split(" "), normalizeKeyName); for (var i = 0; i < keys.length; i++) { var val = (void 0), name = (void 0); if (i == keys.length - 1) { name = keys.join(" "); val = value; } else { name = keys.slice(0, i + 1).join(" "); val = "..."; } var prev = copy[name]; if (!prev) { copy[name] = val; } else if (prev != val) { throw new Error("Inconsistent bindings for " + name) } } delete keymap[keyname]; } } for (var prop in copy) { keymap[prop] = copy[prop]; } return keymap }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function normalizeKeyMap(keymap) {\n\t\t var copy = {};\n\t\t for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {\n\t\t var value = keymap[keyname];\n\t\t if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }\n\t\t if (value == \"...\") { delete keymap[keyname]; co...
[ "0.68504876", "0.6619002", "0.6602381", "0.6602381", "0.6601707", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.65574884", "0.58333474", "0.5548513", "0.5541882", "0.554113", "0.5...
0.66288286
17
Modifier key presses don't count as 'real' key presses for the purpose of keymap fallthrough.
function isModifierKey(value) { var name = typeof value == "string" ? value : keyNames[value.keyCode]; return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod" }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function usualKeys(e) {\n\t\t\tview.put(String.fromCharCode(e.which));\n\t\t\treturn false;\n\t\t}", "function bufferModifier(e) { return e.shiftKey*1 + e.ctrlKey*2 + e.altKey*4 }", "function keyName(event, noShift) {\n\t\t if (presto && event.keyCode == 34 && event[\"char\"]) { return false }\n\t\t var ...
[ "0.71549004", "0.69038826", "0.684083", "0.6807286", "0.6790032", "0.67511195", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", "0.6713231", ...
0.6497272
61
Look up the name of a key as indicated by an event object.
function keyName(event, noShift) { if (presto && event.keyCode == 34 && event["char"]) { return false } var name = keyNames[event.keyCode]; if (name == null || event.altGraphKey) { return false } // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause, // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+) if (event.keyCode == 3 && event.code) { name = event.code; } return addModifierNames(name, event, noShift) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function getEventName(event_id) {\n for(var i in event_reference) {\n var obj = event_reference[i];\n if(obj.id === event_id)\n return obj.name;\n }\n return undefined;\n}", "function grabKey(obj, key) {\n return obj[key];\n}", "function getKey(object, key) {\n return obje...
[ "0.68437785", "0.66774225", "0.6616543", "0.63617873", "0.6232344", "0.58947927", "0.58873767", "0.582189", "0.5820872", "0.57668227", "0.57626027", "0.5733329", "0.57292217", "0.571779", "0.571779", "0.571779", "0.571779", "0.57143486", "0.57070446", "0.57045966", "0.5690433...
0.0
-1
Helper for deleting text near the selection(s), used to implement backspace, delete, and similar functionality.
function deleteNearSelection(cm, compute) { var ranges = cm.doc.sel.ranges, kill = []; // Build up a set of ranges to kill first, merging overlapping // ranges. for (var i = 0; i < ranges.length; i++) { var toKill = compute(ranges[i]); while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) { var replaced = kill.pop(); if (cmp(replaced.from, toKill.from) < 0) { toKill.from = replaced.from; break } } kill.push(toKill); } // Next, remove those actual ranges. runInOp(cm, function () { for (var i = kill.length - 1; i >= 0; i--) { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); } ensureCursorVisible(cm); }); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function removeTextSelections() {\n if (document.selection) document.selection.empty();\n else if (window.getSelection) window.getSelection().removeAllRanges();\n}", "function removeTextSelection() {\n\n if (window.getSelection) {\n\n window.getSelection().removeAllRanges();\n\n } else if (document.se...
[ "0.7447715", "0.7392373", "0.70983833", "0.70505744", "0.69707197", "0.69394445", "0.69200784", "0.6823771", "0.6810343", "0.68008053", "0.6721571", "0.67189825", "0.67189825", "0.67189825", "0.67189825", "0.67189825", "0.67189825", "0.67189825", "0.67189825", "0.67189825", "...
0.577363
91
Run a handler that was bound to a key.
function doHandleBinding(cm, bound, dropShift) { if (typeof bound == "string") { bound = commands[bound]; if (!bound) { return false } } // Ensure previous input has been read, so that the handler sees a // consistent view of the document cm.display.input.ensurePolled(); var prevShift = cm.display.shift, done = false; try { if (cm.isReadOnly()) { cm.state.suppressEdits = true; } if (dropShift) { cm.display.shift = false; } done = bound(cm) != Pass; } finally { cm.display.shift = prevShift; cm.state.suppressEdits = false; } return done }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "getBindingHandler (/* key */) {}", "function receive(key, handler) {\n pxsim.board().bus.listen(key, 0x1, handler);\n }", "function bind(key, action) {\r\n bindings[key] = action; \r\n\r\n}", "function listen(key, callback) {\n handlers[key] = callback;\n}", "function handleCb(key, ...
[ "0.66893464", "0.6387576", "0.6263076", "0.6140119", "0.6125587", "0.5889015", "0.5853597", "0.5827518", "0.5789461", "0.5789461", "0.5789461", "0.5789461", "0.5789461", "0.57228875", "0.5662782", "0.5644284", "0.5632373", "0.5600212", "0.5537149", "0.55028874", "0.5479583", ...
0.0
-1
Handle a key from the keydown event.
function handleKeyBinding(cm, e) { var name = keyName(e, true); if (!name) { return false } if (e.shiftKey && !cm.state.keySeq) { // First try to resolve full name (including 'Shift-'). Failing // that, see if there is a cursor-motion command (starting with // 'go') bound to the keyname without 'Shift-'. return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); }) || dispatchKey(cm, name, e, function (b) { if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion) { return doHandleBinding(cm, b) } }) } else { return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); }) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "HandleKeyDown(event) {}", "function keydown_handler(event)\n{\n\tif (event.defaultPrevented) return;\n\tif (game.handle_key(event.code, true)) return;\n\n\t// cancel the default action to avoid it being handled twice\n\tevent.preventDefault();\n}", "function keyDownHandler(event) {\n keyHandler(true, event)...
[ "0.7755275", "0.7531081", "0.72528416", "0.71958774", "0.7193752", "0.71915567", "0.7183363", "0.71574026", "0.712335", "0.71116465", "0.7088707", "0.7052036", "0.7050431", "0.7047419", "0.7047419", "0.70428956", "0.703125", "0.7002367", "0.69746387", "0.6955946", "0.69537616...
0.0
-1
Handle a key from the keypress event
function handleCharBinding(cm, e, ch) { return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); }) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "HandleKeyDown(event) {}", "function handleKeyPress({ key }) {\n dispatch(playerTyped(key.toLowerCase()));\n }", "handleInput(keycode) {\n if (keycode !== undefined && player.moves === true) {\n key = keycode;\n }\n }", "handleKeyPress(kEvent) {\n switch (kEvent.keyCod...
[ "0.7767834", "0.765871", "0.758574", "0.74911857", "0.741585", "0.7402115", "0.7374124", "0.737354", "0.73173136", "0.72986954", "0.7289434", "0.7274268", "0.7264864", "0.72491187", "0.72488683", "0.7228675", "0.7217789", "0.7216279", "0.7157265", "0.71438694", "0.71438676", ...
0.0
-1
A mouse down can be a single click, double click, triple click, start of selection drag, start of text drag, new cursor (ctrlclick), rectangle drag (altdrag), or xwin middleclickpaste. Or it might be a click on something we should not interfere with, such as a scrollbar or widget.
function onMouseDown(e) { var cm = this, display = cm.display; if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return } display.input.ensurePolled(); display.shift = e.shiftKey; if (eventInWidget(display, e)) { if (!webkit) { // Briefly turn off draggability, to allow widgets to do // normal dragging things. display.scroller.draggable = false; setTimeout(function () { return display.scroller.draggable = true; }, 100); } return } if (clickInGutter(cm, e)) { return } var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single"; window.focus(); // #3261: make sure, that we're not starting a second selection if (button == 1 && cm.state.selectingText) { cm.state.selectingText(e); } if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return } if (button == 1) { if (pos) { leftButtonDown(cm, pos, repeat, e); } else if (e_target(e) == display.scroller) { e_preventDefault(e); } } else if (button == 2) { if (pos) { extendSelection(cm.doc, pos); } setTimeout(function () { return display.input.focus(); }, 20); } else if (button == 3) { if (captureRightClick) { cm.display.input.onContextMenu(e); } else { delayBlurEvent(cm); } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function onMouseDown(e) {\n var cm = this, display = cm.display;\n if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }\n display.input.ensurePolled();\n display.shift = e.shiftKey;\n\n if (eventInWidget(display, e)) {\n if (!webkit) {\n // Briefl...
[ "0.7091538", "0.7091538", "0.70911586", "0.70911586", "0.70911586", "0.70911586", "0.70911586", "0.70911586", "0.70911586", "0.70911586", "0.70911586", "0.70908904", "0.7087665", "0.70814776", "0.7055789", "0.7055789", "0.70555824", "0.70399", "0.70170754", "0.6998677", "0.69...
0.70232
32
Start a text drag. When it ends, see if any dragging actually happen, and treat as a click if it didn't.
function leftButtonStartDrag(cm, event, pos, behavior) { var display = cm.display, moved = false; var dragEnd = operation(cm, function (e) { if (webkit) { display.scroller.draggable = false; } cm.state.draggingText = false; off(display.wrapper.ownerDocument, "mouseup", dragEnd); off(display.wrapper.ownerDocument, "mousemove", mouseMove); off(display.scroller, "dragstart", dragStart); off(display.scroller, "drop", dragEnd); if (!moved) { e_preventDefault(e); if (!behavior.addNew) { extendSelection(cm.doc, pos, null, null, behavior.extend); } // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081) if (webkit || ie && ie_version == 9) { setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus();}, 20); } else { display.input.focus(); } } }); var mouseMove = function(e2) { moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10; }; var dragStart = function () { return moved = true; }; // Let the drag handler handle this. if (webkit) { display.scroller.draggable = true; } cm.state.draggingText = dragEnd; dragEnd.copy = !behavior.moveOnDrag; // IE's approach to draggable if (display.scroller.dragDrop) { display.scroller.dragDrop(); } on(display.wrapper.ownerDocument, "mouseup", dragEnd); on(display.wrapper.ownerDocument, "mousemove", mouseMove); on(display.scroller, "dragstart", dragStart); on(display.scroller, "drop", dragEnd); delayBlurEvent(cm); setTimeout(function () { return display.input.focus(); }, 20); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function startDragText(evt)\r\n{\r\n\r\n if(ActiveElem&&!DraggingObj) //---prevents dragging conflicts on other draggable elements---\r\n {\r\n if(evt.target.parentNode.getAttribute(\"id\")==\"activeText\")\r\n {\r\n if(evt.target.parentNode.parentNode.getAttribute(\"class\")==\"drag...
[ "0.6689381", "0.64861673", "0.6454419", "0.6442164", "0.63774365", "0.62934095", "0.622602", "0.6050684", "0.6036101", "0.6016681", "0.6009714", "0.6001581", "0.59893286", "0.59748036", "0.5961804", "0.5918658", "0.5912148", "0.58981645", "0.58869565", "0.58803177", "0.585968...
0.0
-1
Normal selection, as opposed to text dragging.
function leftButtonSelect(cm, event, start, behavior) { var display = cm.display, doc = cm.doc; e_preventDefault(event); var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges; if (behavior.addNew && !behavior.extend) { ourIndex = doc.sel.contains(start); if (ourIndex > -1) { ourRange = ranges[ourIndex]; } else { ourRange = new Range(start, start); } } else { ourRange = doc.sel.primary(); ourIndex = doc.sel.primIndex; } if (behavior.unit == "rectangle") { if (!behavior.addNew) { ourRange = new Range(start, start); } start = posFromMouse(cm, event, true, true); ourIndex = -1; } else { var range$$1 = rangeForUnit(cm, start, behavior.unit); if (behavior.extend) { ourRange = extendRange(ourRange, range$$1.anchor, range$$1.head, behavior.extend); } else { ourRange = range$$1; } } if (!behavior.addNew) { ourIndex = 0; setSelection(doc, new Selection([ourRange], 0), sel_mouse); startSel = doc.sel; } else if (ourIndex == -1) { ourIndex = ranges.length; setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), {scroll: false, origin: "*mouse"}); } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) { setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), {scroll: false, origin: "*mouse"}); startSel = doc.sel; } else { replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); } var lastPos = start; function extendTo(pos) { if (cmp(lastPos, pos) == 0) { return } lastPos = pos; if (behavior.unit == "rectangle") { var ranges = [], tabSize = cm.options.tabSize; var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize); var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize); var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol); for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); line <= end; line++) { var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize); if (left == right) { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); } else if (text.length > leftPos) { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); } } if (!ranges.length) { ranges.push(new Range(start, start)); } setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), {origin: "*mouse", scroll: false}); cm.scrollIntoView(pos); } else { var oldRange = ourRange; var range$$1 = rangeForUnit(cm, pos, behavior.unit); var anchor = oldRange.anchor, head; if (cmp(range$$1.anchor, anchor) > 0) { head = range$$1.head; anchor = minPos(oldRange.from(), range$$1.anchor); } else { head = range$$1.anchor; anchor = maxPos(oldRange.to(), range$$1.head); } var ranges$1 = startSel.ranges.slice(0); ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head)); setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse); } } var editorSize = display.wrapper.getBoundingClientRect(); // Used to ensure timeout re-tries don't fire when another extend // happened in the meantime (clearTimeout isn't reliable -- at // least on Chrome, the timeouts still happen even when cleared, // if the clear happens after their scheduled firing time). var counter = 0; function extend(e) { var curCount = ++counter; var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle"); if (!cur) { return } if (cmp(cur, lastPos) != 0) { cm.curOp.focus = activeElt(); extendTo(cur); var visible = visibleLines(display, doc); if (cur.line >= visible.to || cur.line < visible.from) { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); } } else { var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0; if (outside) { setTimeout(operation(cm, function () { if (counter != curCount) { return } display.scroller.scrollTop += outside; extend(e); }), 50); } } } function done(e) { cm.state.selectingText = false; counter = Infinity; e_preventDefault(e); display.input.focus(); off(display.wrapper.ownerDocument, "mousemove", move); off(display.wrapper.ownerDocument, "mouseup", up); doc.history.lastSelOrigin = null; } var move = operation(cm, function (e) { if (e.buttons === 0 || !e_button(e)) { done(e); } else { extend(e); } }); var up = operation(cm, done); cm.state.selectingText = up; on(display.wrapper.ownerDocument, "mousemove", move); on(display.wrapper.ownerDocument, "mouseup", up); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "unselectText_() {\n try {\n this.win.getSelection().removeAllRanges();\n } catch (e) {\n // Selection API not supported.\n }\n }", "clearSelection() {\n this._clearSelection();\n }", "cut() {\n if (this.owner.isReadOnlyMode || this.selection.isEmpty) {\n return;\...
[ "0.74885833", "0.7268716", "0.7257491", "0.72482944", "0.72482944", "0.72482944", "0.7164153", "0.7164153", "0.71332663", "0.7116289", "0.7114912", "0.7097566", "0.7063641", "0.704988", "0.70417166", "0.70114183", "0.7003303", "0.69794875", "0.6955937", "0.6951775", "0.693761...
0.0
-1
Used when mouseselecting to adjust the anchor to the proper side of a bidi jump depending on the visual position of the head.
function bidiSimplify(cm, range$$1) { var anchor = range$$1.anchor; var head = range$$1.head; var anchorLine = getLine(cm.doc, anchor.line); if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range$$1 } var order = getOrder(anchorLine); if (!order) { return range$$1 } var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index]; if (part.from != anchor.ch && part.to != anchor.ch) { return range$$1 } var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1); if (boundary == 0 || boundary == order.length) { return range$$1 } // Compute the relative visual position of the head compared to the // anchor (<0 is to the left, >0 to the right) var leftSide; if (head.line != anchor.line) { leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0; } else { var headIndex = getBidiPartAt(order, head.ch, head.sticky); var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1); if (headIndex == boundary - 1 || headIndex == boundary) { leftSide = dir < 0; } else { leftSide = dir > 0; } } var usePart = order[boundary + (leftSide ? -1 : 0)]; var from = leftSide == (usePart.level == 1); var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before"; return anchor.ch == ch && anchor.sticky == sticky ? range$$1 : new Range(new Pos(anchor.line, ch, sticky), head) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function setLabelAnchor(d) {\r\n if (d.target.x >= (d.source.x + 20)) return \"start\";\r\n if (d.target.x <= (d.source.x - 20)) return \"end\";\r\n return \"middle\";\r\n }", "function updateAnchorPos() {\n if (!labelSim.selection) return;\n\n labelSim.selection.each(function(d) {\n v...
[ "0.6865997", "0.65352046", "0.63302565", "0.6309565", "0.6135887", "0.6132395", "0.6033308", "0.6033308", "0.6033308", "0.5898258", "0.5860216", "0.5860216", "0.5860216", "0.5844974", "0.5740096", "0.5736967", "0.5736967", "0.5736967", "0.5736967", "0.569803", "0.56956744", ...
0.0
-1
Determines whether an event happened in the gutter, and fires the handlers for the corresponding event.
function gutterEvent(cm, e, type, prevent) { var mX, mY; if (e.touches) { mX = e.touches[0].clientX; mY = e.touches[0].clientY; } else { try { mX = e.clientX; mY = e.clientY; } catch(e) { return false } } if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false } if (prevent) { e_preventDefault(e); } var display = cm.display; var lineBox = display.lineDiv.getBoundingClientRect(); if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) } mY -= lineBox.top - display.viewOffset; for (var i = 0; i < cm.options.gutters.length; ++i) { var g = display.gutters.childNodes[i]; if (g && g.getBoundingClientRect().right >= mX) { var line = lineAtHeight(cm.doc, mY); var gutter = cm.options.gutters[i]; signal(cm, type, cm, line, gutter, e); return e_defaultPrevented(e) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function gutterEvent(cm, e, type, prevent, signalfn) {\n try { var mX = e.clientX, mY = e.clientY; }\n catch(e) { return false; }\n if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false;\n if (prevent) e_preventDefault(e);\n\n var display = cm.display;\n var lineBox...
[ "0.6424223", "0.6424223", "0.6424223", "0.6424223", "0.6424223", "0.6424223", "0.6424223", "0.64166504", "0.63820106", "0.63625795", "0.63530976", "0.63412756", "0.6337135", "0.6337135", "0.6337135", "0.6337135", "0.6337135", "0.6337135", "0.63256717", "0.63256717", "0.632567...
0.6320734
29
CONTEXT MENU HANDLING To make the context menu work, we need to briefly unhide the textarea (making it as unobtrusive as possible) to let the rightclick take effect on it.
function onContextMenu(cm, e) { if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return } if (signalDOMEvent(cm, e, "contextmenu")) { return } if (!captureRightClick) { cm.display.input.onContextMenu(e); } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function rightClickHandler(ev, textarea, screenElement, selectionService, shouldSelectWord) {\n moveTextAreaUnderMouseCursor(ev, textarea, screenElement);\n if (shouldSelectWord) {\n selectionService.rightClickSelect(ev);\n }\n // Get textarea ready to copy from the context menu\n textarea.va...
[ "0.68555146", "0.6613691", "0.6610034", "0.65589243", "0.65370077", "0.65265536", "0.6479694", "0.64353794", "0.6356764", "0.63425994", "0.63180727", "0.63180727", "0.63047725", "0.62931454", "0.62931454", "0.62903816", "0.6225206", "0.6213413", "0.6207998", "0.61801744", "0....
0.5823754
70
A CodeMirror instance represents an editor. This is the object that user code is usually dealing with.
function CodeMirror(place, options) { var this$1 = this; if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) } this.options = options = options ? copyObj(options) : {}; // Determine effective options based on given values and defaults. copyObj(defaults, options, false); setGuttersForLineNumbers(options); var doc = options.value; if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); } else if (options.mode) { doc.modeOption = options.mode; } this.doc = doc; var input = new CodeMirror.inputStyles[options.inputStyle](this); var display = this.display = new Display(place, doc, input); display.wrapper.CodeMirror = this; updateGutters(this); themeChanged(this); if (options.lineWrapping) { this.display.wrapper.className += " CodeMirror-wrap"; } initScrollbars(this); this.state = { keyMaps: [], // stores maps added by addKeyMap overlays: [], // highlighting overlays, as added by addOverlay modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info overwrite: false, delayingBlurEvent: false, focused: false, suppressEdits: false, // used to disable editing during key handlers when in readOnly mode pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll selectingText: false, draggingText: false, highlight: new Delayed(), // stores highlight worker timeout keySeq: null, // Unfinished key sequence specialChars: null }; if (options.autofocus && !mobile) { display.input.focus(); } // Override magic textarea content restore that IE sometimes does // on our hidden textarea on reload if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); } registerEventHandlers(this); ensureGlobalHandlers(); startOperation(this); this.curOp.forceUpdate = true; attachDoc(this, doc); if ((options.autofocus && !mobile) || this.hasFocus()) { setTimeout(bind(onFocus, this), 20); } else { onBlur(this); } for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt)) { optionHandlers[opt](this$1, options[opt], Init); } } maybeUpdateLineNumberWidth(this); if (options.finishInit) { options.finishInit(this); } for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1); } endOperation(this); // Suppress optimizelegibility in Webkit, since it breaks text // measuring on line wrapping boundaries. if (webkit && options.lineWrapping && getComputedStyle(display.lineDiv).textRendering == "optimizelegibility") { display.lineDiv.style.textRendering = "auto"; } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function CodeMirror(place, options) {\n if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);\n\n this.options = options = options || {};\n // Determine effective options based on given values and defaults.\n copyObj(defaults, options, false);\n setGuttersForLineNumbers(options);...
[ "0.7637769", "0.7595455", "0.7582652", "0.7582652", "0.75507426", "0.75500923", "0.75465775", "0.7529049", "0.7527881", "0.7526824", "0.7526294", "0.7526294", "0.74995637", "0.74958473", "0.74776506", "0.74776506", "0.74776506", "0.74776506", "0.74776506", "0.74776506", "0.74...
0.7432956
31
Attach the necessary event handlers when initializing the editor
function registerEventHandlers(cm) { var d = cm.display; on(d.scroller, "mousedown", operation(cm, onMouseDown)); // Older IE's will not fire a second mousedown for a double click if (ie && ie_version < 11) { on(d.scroller, "dblclick", operation(cm, function (e) { if (signalDOMEvent(cm, e)) { return } var pos = posFromMouse(cm, e); if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return } e_preventDefault(e); var word = cm.findWordAt(pos); extendSelection(cm.doc, word.anchor, word.head); })); } else { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); } // Some browsers fire contextmenu *after* opening the menu, at // which point we can't mess with it anymore. Context menu is // handled in onMouseDown for these browsers. on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }); // Used to suppress mouse event handling when a touch happens var touchFinished, prevTouch = {end: 0}; function finishTouch() { if (d.activeTouch) { touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000); prevTouch = d.activeTouch; prevTouch.end = +new Date; } } function isMouseLikeTouchEvent(e) { if (e.touches.length != 1) { return false } var touch = e.touches[0]; return touch.radiusX <= 1 && touch.radiusY <= 1 } function farAway(touch, other) { if (other.left == null) { return true } var dx = other.left - touch.left, dy = other.top - touch.top; return dx * dx + dy * dy > 20 * 20 } on(d.scroller, "touchstart", function (e) { if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) { d.input.ensurePolled(); clearTimeout(touchFinished); var now = +new Date; d.activeTouch = {start: now, moved: false, prev: now - prevTouch.end <= 300 ? prevTouch : null}; if (e.touches.length == 1) { d.activeTouch.left = e.touches[0].pageX; d.activeTouch.top = e.touches[0].pageY; } } }); on(d.scroller, "touchmove", function () { if (d.activeTouch) { d.activeTouch.moved = true; } }); on(d.scroller, "touchend", function (e) { var touch = d.activeTouch; if (touch && !eventInWidget(d, e) && touch.left != null && !touch.moved && new Date - touch.start < 300) { var pos = cm.coordsChar(d.activeTouch, "page"), range; if (!touch.prev || farAway(touch, touch.prev)) // Single tap { range = new Range(pos, pos); } else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap { range = cm.findWordAt(pos); } else // Triple tap { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); } cm.setSelection(range.anchor, range.head); cm.focus(); e_preventDefault(e); } finishTouch(); }); on(d.scroller, "touchcancel", finishTouch); // Sync scrolling between fake scrollbars and real scrollable // area, ensure viewport is updated when scrolling. on(d.scroller, "scroll", function () { if (d.scroller.clientHeight) { updateScrollTop(cm, d.scroller.scrollTop); setScrollLeft(cm, d.scroller.scrollLeft, true); signal(cm, "scroll", cm); } }); // Listen to wheel events in order to try and update the viewport on time. on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); }); on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); }); // Prevent wrapper from ever scrolling on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; }); d.dragFunctions = { enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }}, over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }}, start: function (e) { return onDragStart(cm, e); }, drop: operation(cm, onDrop), leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }} }; var inp = d.input.getField(); on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); }); on(inp, "keydown", operation(cm, onKeyDown)); on(inp, "keypress", operation(cm, onKeyPress)); on(inp, "focus", function (e) { return onFocus(cm, e); }); on(inp, "blur", function (e) { return onBlur(cm, e); }); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function init() {\n\n\t\t// Bind the editor elements to variables\n\t\tbindElements();\n\n\t\t// Create event listeners for keyup, mouseup, etc.\n\t\tcreateEventBindings();\n\t}", "initEventListners() {\n this.engine.getSession().selection.on('changeCursor', () => this.updateCursorLabels());\n\n th...
[ "0.80966556", "0.77389115", "0.75494534", "0.72982234", "0.7282955", "0.723292", "0.7122359", "0.71221983", "0.71001315", "0.7071713", "0.7025846", "0.6915193", "0.6894815", "0.68728834", "0.685716", "0.68458426", "0.68189013", "0.6798981", "0.6797055", "0.6743994", "0.672856...
0.0
-1
Indent the given line. The how parameter can be "smart", "add"/null, "subtract", or "prev". When aggressive is false (typically set to true for forced singleline indents), empty lines are not indented, and places where the mode returns Pass are left alone.
function indentLine(cm, n, how, aggressive) { var doc = cm.doc, state; if (how == null) { how = "add"; } if (how == "smart") { // Fall back to "prev" when the mode doesn't have an indentation // method. if (!doc.mode.indent) { how = "prev"; } else { state = getContextBefore(cm, n).state; } } var tabSize = cm.options.tabSize; var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize); if (line.stateAfter) { line.stateAfter = null; } var curSpaceString = line.text.match(/^\s*/)[0], indentation; if (!aggressive && !/\S/.test(line.text)) { indentation = 0; how = "not"; } else if (how == "smart") { indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text); if (indentation == Pass || indentation > 150) { if (!aggressive) { return } how = "prev"; } } if (how == "prev") { if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); } else { indentation = 0; } } else if (how == "add") { indentation = curSpace + cm.options.indentUnit; } else if (how == "subtract") { indentation = curSpace - cm.options.indentUnit; } else if (typeof how == "number") { indentation = curSpace + how; } indentation = Math.max(0, indentation); var indentString = "", pos = 0; if (cm.options.indentWithTabs) { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} } if (pos < indentation) { indentString += spaceStr(indentation - pos); } if (indentString != curSpaceString) { replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input"); line.stateAfter = null; return true } else { // Ensure that, if the cursor was in the whitespace at the start // of the line, it is moved to the end of that space. for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) { var range = doc.sel.ranges[i$1]; if (range.head.line == n && range.head.ch < curSpaceString.length) { var pos$1 = Pos(n, curSpaceString.length); replaceOneSelection(doc, i$1, new Range(pos$1, pos$1)); break } } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function indentLine(cm, n, how, aggressive) {\n\t var doc = cm.doc, state;\n\t if (how == null) how = \"add\";\n\t if (how == \"smart\") {\n\t // Fall back to \"prev\" when the mode doesn't have an indentation\n\t // method.\n\t if (!doc.mode.indent) how = \"prev\";\n\t else state = ge...
[ "0.7559429", "0.7559429", "0.75495756", "0.75352246", "0.75240046", "0.7493951", "0.74812", "0.74812", "0.74668497", "0.74473864", "0.74473864", "0.74473864", "0.74473864", "0.74359816", "0.7413695", "0.7406404", "0.7406404", "0.7406404", "0.7406404", "0.7406404", "0.7406404"...
0.7503435
16
The publicly visible API. Note that methodOp(f) means 'wrap f in an operation, performed on its `this` parameter'. This is not the complete set of editor methods. Most of the methods defined on the Doc type are also injected into CodeMirror.prototype, for backwards compatibility and convenience.
function addEditorMethods(CodeMirror) { var optionHandlers = CodeMirror.optionHandlers; var helpers = CodeMirror.helpers = {}; CodeMirror.prototype = { constructor: CodeMirror, focus: function(){window.focus(); this.display.input.focus();}, setOption: function(option, value) { var options = this.options, old = options[option]; if (options[option] == value && option != "mode") { return } options[option] = value; if (optionHandlers.hasOwnProperty(option)) { operation(this, optionHandlers[option])(this, value, old); } signal(this, "optionChange", this, option); }, getOption: function(option) {return this.options[option]}, getDoc: function() {return this.doc}, addKeyMap: function(map$$1, bottom) { this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map$$1)); }, removeKeyMap: function(map$$1) { var maps = this.state.keyMaps; for (var i = 0; i < maps.length; ++i) { if (maps[i] == map$$1 || maps[i].name == map$$1) { maps.splice(i, 1); return true } } }, addOverlay: methodOp(function(spec, options) { var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec); if (mode.startState) { throw new Error("Overlays may not be stateful.") } insertSorted(this.state.overlays, {mode: mode, modeSpec: spec, opaque: options && options.opaque, priority: (options && options.priority) || 0}, function (overlay) { return overlay.priority; }); this.state.modeGen++; regChange(this); }), removeOverlay: methodOp(function(spec) { var this$1 = this; var overlays = this.state.overlays; for (var i = 0; i < overlays.length; ++i) { var cur = overlays[i].modeSpec; if (cur == spec || typeof spec == "string" && cur.name == spec) { overlays.splice(i, 1); this$1.state.modeGen++; regChange(this$1); return } } }), indentLine: methodOp(function(n, dir, aggressive) { if (typeof dir != "string" && typeof dir != "number") { if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; } else { dir = dir ? "add" : "subtract"; } } if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); } }), indentSelection: methodOp(function(how) { var this$1 = this; var ranges = this.doc.sel.ranges, end = -1; for (var i = 0; i < ranges.length; i++) { var range$$1 = ranges[i]; if (!range$$1.empty()) { var from = range$$1.from(), to = range$$1.to(); var start = Math.max(end, from.line); end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1; for (var j = start; j < end; ++j) { indentLine(this$1, j, how); } var newRanges = this$1.doc.sel.ranges; if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0) { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); } } else if (range$$1.head.line > end) { indentLine(this$1, range$$1.head.line, how, true); end = range$$1.head.line; if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1); } } } }), // Fetch the parser token for a given character. Useful for hacks // that want to inspect the mode state (say, for completion). getTokenAt: function(pos, precise) { return takeToken(this, pos, precise) }, getLineTokens: function(line, precise) { return takeToken(this, Pos(line), precise, true) }, getTokenTypeAt: function(pos) { pos = clipPos(this.doc, pos); var styles = getLineStyles(this, getLine(this.doc, pos.line)); var before = 0, after = (styles.length - 1) / 2, ch = pos.ch; var type; if (ch == 0) { type = styles[2]; } else { for (;;) { var mid = (before + after) >> 1; if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; } else if (styles[mid * 2 + 1] < ch) { before = mid + 1; } else { type = styles[mid * 2 + 2]; break } } } var cut = type ? type.indexOf("overlay ") : -1; return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1) }, getModeAt: function(pos) { var mode = this.doc.mode; if (!mode.innerMode) { return mode } return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode }, getHelper: function(pos, type) { return this.getHelpers(pos, type)[0] }, getHelpers: function(pos, type) { var this$1 = this; var found = []; if (!helpers.hasOwnProperty(type)) { return found } var help = helpers[type], mode = this.getModeAt(pos); if (typeof mode[type] == "string") { if (help[mode[type]]) { found.push(help[mode[type]]); } } else if (mode[type]) { for (var i = 0; i < mode[type].length; i++) { var val = help[mode[type][i]]; if (val) { found.push(val); } } } else if (mode.helperType && help[mode.helperType]) { found.push(help[mode.helperType]); } else if (help[mode.name]) { found.push(help[mode.name]); } for (var i$1 = 0; i$1 < help._global.length; i$1++) { var cur = help._global[i$1]; if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1) { found.push(cur.val); } } return found }, getStateAfter: function(line, precise) { var doc = this.doc; line = clipLine(doc, line == null ? doc.first + doc.size - 1: line); return getContextBefore(this, line + 1, precise).state }, cursorCoords: function(start, mode) { var pos, range$$1 = this.doc.sel.primary(); if (start == null) { pos = range$$1.head; } else if (typeof start == "object") { pos = clipPos(this.doc, start); } else { pos = start ? range$$1.from() : range$$1.to(); } return cursorCoords(this, pos, mode || "page") }, charCoords: function(pos, mode) { return charCoords(this, clipPos(this.doc, pos), mode || "page") }, coordsChar: function(coords, mode) { coords = fromCoordSystem(this, coords, mode || "page"); return coordsChar(this, coords.left, coords.top) }, lineAtHeight: function(height, mode) { height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top; return lineAtHeight(this.doc, height + this.display.viewOffset) }, heightAtLine: function(line, mode, includeWidgets) { var end = false, lineObj; if (typeof line == "number") { var last = this.doc.first + this.doc.size - 1; if (line < this.doc.first) { line = this.doc.first; } else if (line > last) { line = last; end = true; } lineObj = getLine(this.doc, line); } else { lineObj = line; } return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top + (end ? this.doc.height - heightAtLine(lineObj) : 0) }, defaultTextHeight: function() { return textHeight(this.display) }, defaultCharWidth: function() { return charWidth(this.display) }, getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}}, addWidget: function(pos, node, scroll, vert, horiz) { var display = this.display; pos = cursorCoords(this, clipPos(this.doc, pos)); var top = pos.bottom, left = pos.left; node.style.position = "absolute"; node.setAttribute("cm-ignore-events", "true"); this.display.input.setUneditable(node); display.sizer.appendChild(node); if (vert == "over") { top = pos.top; } else if (vert == "above" || vert == "near") { var vspace = Math.max(display.wrapper.clientHeight, this.doc.height), hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth); // Default to positioning above (if specified and possible); otherwise default to positioning below if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight) { top = pos.top - node.offsetHeight; } else if (pos.bottom + node.offsetHeight <= vspace) { top = pos.bottom; } if (left + node.offsetWidth > hspace) { left = hspace - node.offsetWidth; } } node.style.top = top + "px"; node.style.left = node.style.right = ""; if (horiz == "right") { left = display.sizer.clientWidth - node.offsetWidth; node.style.right = "0px"; } else { if (horiz == "left") { left = 0; } else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; } node.style.left = left + "px"; } if (scroll) { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); } }, triggerOnKeyDown: methodOp(onKeyDown), triggerOnKeyPress: methodOp(onKeyPress), triggerOnKeyUp: onKeyUp, triggerOnMouseDown: methodOp(onMouseDown), execCommand: function(cmd) { if (commands.hasOwnProperty(cmd)) { return commands[cmd].call(null, this) } }, triggerElectric: methodOp(function(text) { triggerElectric(this, text); }), findPosH: function(from, amount, unit, visually) { var this$1 = this; var dir = 1; if (amount < 0) { dir = -1; amount = -amount; } var cur = clipPos(this.doc, from); for (var i = 0; i < amount; ++i) { cur = findPosH(this$1.doc, cur, dir, unit, visually); if (cur.hitSide) { break } } return cur }, moveH: methodOp(function(dir, unit) { var this$1 = this; this.extendSelectionsBy(function (range$$1) { if (this$1.display.shift || this$1.doc.extend || range$$1.empty()) { return findPosH(this$1.doc, range$$1.head, dir, unit, this$1.options.rtlMoveVisually) } else { return dir < 0 ? range$$1.from() : range$$1.to() } }, sel_move); }), deleteH: methodOp(function(dir, unit) { var sel = this.doc.sel, doc = this.doc; if (sel.somethingSelected()) { doc.replaceSelection("", null, "+delete"); } else { deleteNearSelection(this, function (range$$1) { var other = findPosH(doc, range$$1.head, dir, unit, false); return dir < 0 ? {from: other, to: range$$1.head} : {from: range$$1.head, to: other} }); } }), findPosV: function(from, amount, unit, goalColumn) { var this$1 = this; var dir = 1, x = goalColumn; if (amount < 0) { dir = -1; amount = -amount; } var cur = clipPos(this.doc, from); for (var i = 0; i < amount; ++i) { var coords = cursorCoords(this$1, cur, "div"); if (x == null) { x = coords.left; } else { coords.left = x; } cur = findPosV(this$1, coords, dir, unit); if (cur.hitSide) { break } } return cur }, moveV: methodOp(function(dir, unit) { var this$1 = this; var doc = this.doc, goals = []; var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected(); doc.extendSelectionsBy(function (range$$1) { if (collapse) { return dir < 0 ? range$$1.from() : range$$1.to() } var headPos = cursorCoords(this$1, range$$1.head, "div"); if (range$$1.goalColumn != null) { headPos.left = range$$1.goalColumn; } goals.push(headPos.left); var pos = findPosV(this$1, headPos, dir, unit); if (unit == "page" && range$$1 == doc.sel.primary()) { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); } return pos }, sel_move); if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++) { doc.sel.ranges[i].goalColumn = goals[i]; } } }), // Find the word at the given position (as returned by coordsChar). findWordAt: function(pos) { var doc = this.doc, line = getLine(doc, pos.line).text; var start = pos.ch, end = pos.ch; if (line) { var helper = this.getHelper(pos, "wordChars"); if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; } var startChar = line.charAt(start); var check = isWordChar(startChar, helper) ? function (ch) { return isWordChar(ch, helper); } : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); } : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); }; while (start > 0 && check(line.charAt(start - 1))) { --start; } while (end < line.length && check(line.charAt(end))) { ++end; } } return new Range(Pos(pos.line, start), Pos(pos.line, end)) }, toggleOverwrite: function(value) { if (value != null && value == this.state.overwrite) { return } if (this.state.overwrite = !this.state.overwrite) { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); } else { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); } signal(this, "overwriteToggle", this, this.state.overwrite); }, hasFocus: function() { return this.display.input.getField() == activeElt() }, isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) }, scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }), getScrollInfo: function() { var scroller = this.display.scroller; return {left: scroller.scrollLeft, top: scroller.scrollTop, height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight, width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth, clientHeight: displayHeight(this), clientWidth: displayWidth(this)} }, scrollIntoView: methodOp(function(range$$1, margin) { if (range$$1 == null) { range$$1 = {from: this.doc.sel.primary().head, to: null}; if (margin == null) { margin = this.options.cursorScrollMargin; } } else if (typeof range$$1 == "number") { range$$1 = {from: Pos(range$$1, 0), to: null}; } else if (range$$1.from == null) { range$$1 = {from: range$$1, to: null}; } if (!range$$1.to) { range$$1.to = range$$1.from; } range$$1.margin = margin || 0; if (range$$1.from.line != null) { scrollToRange(this, range$$1); } else { scrollToCoordsRange(this, range$$1.from, range$$1.to, range$$1.margin); } }), setSize: methodOp(function(width, height) { var this$1 = this; var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; }; if (width != null) { this.display.wrapper.style.width = interpret(width); } if (height != null) { this.display.wrapper.style.height = interpret(height); } if (this.options.lineWrapping) { clearLineMeasurementCache(this); } var lineNo$$1 = this.display.viewFrom; this.doc.iter(lineNo$$1, this.display.viewTo, function (line) { if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo$$1, "widget"); break } } } ++lineNo$$1; }); this.curOp.forceUpdate = true; signal(this, "refresh", this); }), operation: function(f){return runInOp(this, f)}, startOperation: function(){return startOperation(this)}, endOperation: function(){return endOperation(this)}, refresh: methodOp(function() { var oldHeight = this.display.cachedTextHeight; regChange(this); this.curOp.forceUpdate = true; clearCaches(this); scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop); updateGutterSpace(this); if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5) { estimateLineHeights(this); } signal(this, "refresh", this); }), swapDoc: methodOp(function(doc) { var old = this.doc; old.cm = null; attachDoc(this, doc); clearCaches(this); this.display.input.reset(); scrollToCoords(this, doc.scrollLeft, doc.scrollTop); this.curOp.forceScroll = true; signalLater(this, "swapDoc", this, old); return old }), phrase: function(phraseText) { var phrases = this.options.phrases; return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText }, getInputField: function(){return this.display.input.getField()}, getWrapperElement: function(){return this.display.wrapper}, getScrollerElement: function(){return this.display.scroller}, getGutterElement: function(){return this.display.gutters} }; eventMixin(CodeMirror); CodeMirror.registerHelper = function(type, name, value) { if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; } helpers[type][name] = value; }; CodeMirror.registerGlobalHelper = function(type, name, predicate, value) { CodeMirror.registerHelper(type, name, value); helpers[type]._global.push({pred: predicate, val: value}); }; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function addEditorMethods(CodeMirror) {\n var optionHandlers = CodeMirror.optionHandlers;\n\n var helpers = CodeMirror.helpers = {};\n\n CodeMirror.prototype = {\n constructor: CodeMirror,\n focus: function(){window.focus(); this.display.input.focus();},\n\n setOption: function(option, valu...
[ "0.6675193", "0.6675193", "0.6675193", "0.6675193", "0.6675193", "0.66579515", "0.6635314", "0.6635314", "0.66196305", "0.66196305", "0.66196305", "0.66196305", "0.66196305", "0.66196305", "0.66078043", "0.6596803", "0.6596803", "0.61544967", "0.613479", "0.613479", "0.613479...
0.6675193
5
Used for horizontal relative motion. Dir is 1 or 1 (left or right), unit can be "char", "column" (like char, but doesn't cross line boundaries), "word" (across next word), or "group" (to the start of next group of word or nonwordnonwhitespace chars). The visually param controls whether, in righttoleft text, direction 1 means to move towards the next index in the string, or towards the character to the right of the current position. The resulting position will have a hitSide=true property if it reached the end of the document.
function findPosH(doc, pos, dir, unit, visually) { var oldPos = pos; var origDir = dir; var lineObj = getLine(doc, pos.line); function findNextLine() { var l = pos.line + dir; if (l < doc.first || l >= doc.first + doc.size) { return false } pos = new Pos(l, pos.ch, pos.sticky); return lineObj = getLine(doc, l) } function moveOnce(boundToLine) { var next; if (visually) { next = moveVisually(doc.cm, lineObj, pos, dir); } else { next = moveLogically(lineObj, pos, dir); } if (next == null) { if (!boundToLine && findNextLine()) { pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir); } else { return false } } else { pos = next; } return true } if (unit == "char") { moveOnce(); } else if (unit == "column") { moveOnce(true); } else if (unit == "word" || unit == "group") { var sawType = null, group = unit == "group"; var helper = doc.cm && doc.cm.getHelper(pos, "wordChars"); for (var first = true;; first = false) { if (dir < 0 && !moveOnce(!first)) { break } var cur = lineObj.text.charAt(pos.ch) || "\n"; var type = isWordChar(cur, helper) ? "w" : group && cur == "\n" ? "n" : !group || /\s/.test(cur) ? null : "p"; if (group && !first && !type) { type = "s"; } if (sawType && sawType != type) { if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";} break } if (type) { sawType = type; } if (dir > 0 && !moveOnce(!first)) { break } } } var result = skipAtomic(doc, pos, oldPos, origDir, true); if (equalCursorPos(oldPos, result)) { result.hitSide = true; } return result }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function findPosH(doc, pos, dir, unit, visually) {\r\n var line = pos.line, ch = pos.ch, origDir = dir;\r\n var lineObj = getLine(doc, line);\r\n var possible = true;\r\n function findNextLine() {\r\n var l = line + dir;\r\n if (l < doc.first || l >= doc.first + doc.size) return (possible = f...
[ "0.6130519", "0.6126427", "0.6126427", "0.6126427", "0.6126427", "0.6126427", "0.6126427", "0.6123693", "0.60945994", "0.60565317", "0.6052235", "0.6028111", "0.60225946", "0.60225946", "0.60225946", "0.59996206", "0.59996206", "0.5997345", "0.59868014", "0.5910987", "0.59061...
0.5976428
24
For relative vertical movement. Dir may be 1 or 1. Unit can be "page" or "line". The resulting position will have a hitSide=true property if it reached the end of the document.
function findPosV(cm, pos, dir, unit) { var doc = cm.doc, x = pos.left, y; if (unit == "page") { var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight); var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3); y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount; } else if (unit == "line") { y = dir > 0 ? pos.bottom + 3 : pos.top - 3; } var target; for (;;) { target = coordsChar(cm, x, y); if (!target.outside) { break } if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break } y += dir * 5; } return target }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function findPosV(cm, pos, dir, unit) {\n var doc = cm.doc, x = pos.left, y;\n if (unit == \"page\") {\n var pageSize = Math.min(cm.display.wrapper.clientHeight, win(cm).innerHeight || doc(cm).documentElement.clientHeight);\n var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);\n ...
[ "0.69151056", "0.69151056", "0.6821693", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.6810372", "0.68065315", "0.68065315", "0.67795277", "0.67302203", "0.67302203", "0.67302203", "0.67302...
0.6870279
11
Selectall will be greyed out if there's nothing to select, so this adds a zerowidth space so that we can later check whether it got selected.
function prepareSelectAllHack() { if (te.selectionStart != null) { var selected = cm.somethingSelected(); var extval = "\u200b" + (selected ? te.value : ""); te.value = "\u21da"; // Used to catch context-menu undo te.value = extval; input.prevInput = selected ? "" : "\u200b"; te.selectionStart = 1; te.selectionEnd = extval.length; // Re-set this, in case some other handler touched the // selection in the meantime. display.selForContextMenu = cm.doc.sel; } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function selectAll()\r\n\t\t{\r\n\t\t\tthis.focus();\r\n\t\t\tthis.select();\r\n\t\t}", "function show_select_all(){\r\n var th = getPatternResult(PATTERN['select_all']).snapshotItem(0);\r\n if (th == null) \r\n return;\r\n th.innerHTML = '<input type=\"checkbox\"/>';\r\n th.setAttribute('titl...
[ "0.7962586", "0.68508226", "0.6849682", "0.6849682", "0.6849682", "0.6849682", "0.6849682", "0.6836901", "0.6795213", "0.67752296", "0.676283", "0.676283", "0.676283", "0.67515665", "0.67515665", "0.6742831", "0.6742831", "0.67361194", "0.6732308", "0.67188287", "0.67188287",...
0.67083514
47
Function to create the first processor.
function unified() { var attachers = [] var transformers = trough() var namespace = {} var frozen = false var freezeIndex = -1 /* Data management. */ processor.data = data /* Lock. */ processor.freeze = freeze /* Plug-ins. */ processor.attachers = attachers processor.use = use /* API. */ processor.parse = parse processor.stringify = stringify processor.run = run processor.runSync = runSync processor.process = process processor.processSync = processSync /* Expose. */ return processor /* Create a new processor based on the processor * in the current scope. */ function processor() { var destination = unified() var length = attachers.length var index = -1 while (++index < length) { destination.use.apply(null, attachers[index]) } destination.data(extend(true, {}, namespace)) return destination } /* Freeze: used to signal a processor that has finished * configuration. * * For example, take unified itself. It’s frozen. * Plug-ins should not be added to it. Rather, it should * be extended, by invoking it, before modifying it. * * In essence, always invoke this when exporting a * processor. */ function freeze() { var values var plugin var options var transformer if (frozen) { return processor } while (++freezeIndex < attachers.length) { values = attachers[freezeIndex] plugin = values[0] options = values[1] transformer = null if (options === false) { continue } if (options === true) { values[1] = undefined } transformer = plugin.apply(processor, values.slice(1)) if (typeof transformer === 'function') { transformers.use(transformer) } } frozen = true freezeIndex = Infinity return processor } /* Data management. * Getter / setter for processor-specific informtion. */ function data(key, value) { if (string(key)) { /* Set `key`. */ if (arguments.length === 2) { assertUnfrozen('data', frozen) namespace[key] = value return processor } /* Get `key`. */ return (own.call(namespace, key) && namespace[key]) || null } /* Set space. */ if (key) { assertUnfrozen('data', frozen) namespace = key return processor } /* Get space. */ return namespace } /* Plug-in management. * * Pass it: * * an attacher and options, * * a preset, * * a list of presets, attachers, and arguments (list * of attachers and options). */ function use(value) { var settings assertUnfrozen('use', frozen) if (value === null || value === undefined) { /* Empty */ } else if (typeof value === 'function') { addPlugin.apply(null, arguments) } else if (typeof value === 'object') { if ('length' in value) { addList(value) } else { addPreset(value) } } else { throw new Error('Expected usable value, not `' + value + '`') } if (settings) { namespace.settings = extend(namespace.settings || {}, settings) } return processor function addPreset(result) { addList(result.plugins) if (result.settings) { settings = extend(settings || {}, result.settings) } } function add(value) { if (typeof value === 'function') { addPlugin(value) } else if (typeof value === 'object') { if ('length' in value) { addPlugin.apply(null, value) } else { addPreset(value) } } else { throw new Error('Expected usable value, not `' + value + '`') } } function addList(plugins) { var length var index if (plugins === null || plugins === undefined) { /* Empty */ } else if (typeof plugins === 'object' && 'length' in plugins) { length = plugins.length index = -1 while (++index < length) { add(plugins[index]) } } else { throw new Error('Expected a list of plugins, not `' + plugins + '`') } } function addPlugin(plugin, value) { var entry = find(plugin) if (entry) { if (plain(entry[1]) && plain(value)) { value = extend(entry[1], value) } entry[1] = value } else { attachers.push(slice.call(arguments)) } } } function find(plugin) { var length = attachers.length var index = -1 var entry while (++index < length) { entry = attachers[index] if (entry[0] === plugin) { return entry } } } /* Parse a file (in string or VFile representation) * into a Unist node using the `Parser` on the * processor. */ function parse(doc) { var file = vfile(doc) var Parser freeze() Parser = processor.Parser assertParser('parse', Parser) if (newable(Parser)) { return new Parser(String(file), file).parse() } return Parser(String(file), file) // eslint-disable-line new-cap } /* Run transforms on a Unist node representation of a file * (in string or VFile representation), async. */ function run(node, file, cb) { assertNode(node) freeze() if (!cb && typeof file === 'function') { cb = file file = null } if (!cb) { return new Promise(executor) } executor(null, cb) function executor(resolve, reject) { transformers.run(node, vfile(file), done) function done(err, tree, file) { tree = tree || node if (err) { reject(err) } else if (resolve) { resolve(tree) } else { cb(null, tree, file) } } } } /* Run transforms on a Unist node representation of a file * (in string or VFile representation), sync. */ function runSync(node, file) { var complete = false var result run(node, file, done) assertDone('runSync', 'run', complete) return result function done(err, tree) { complete = true bail(err) result = tree } } /* Stringify a Unist node representation of a file * (in string or VFile representation) into a string * using the `Compiler` on the processor. */ function stringify(node, doc) { var file = vfile(doc) var Compiler freeze() Compiler = processor.Compiler assertCompiler('stringify', Compiler) assertNode(node) if (newable(Compiler)) { return new Compiler(node, file).compile() } return Compiler(node, file) // eslint-disable-line new-cap } /* Parse a file (in string or VFile representation) * into a Unist node using the `Parser` on the processor, * then run transforms on that node, and compile the * resulting node using the `Compiler` on the processor, * and store that result on the VFile. */ function process(doc, cb) { freeze() assertParser('process', processor.Parser) assertCompiler('process', processor.Compiler) if (!cb) { return new Promise(executor) } executor(null, cb) function executor(resolve, reject) { var file = vfile(doc) pipeline.run(processor, {file: file}, done) function done(err) { if (err) { reject(err) } else if (resolve) { resolve(file) } else { cb(null, file) } } } } /* Process the given document (in string or VFile * representation), sync. */ function processSync(doc) { var complete = false var file freeze() assertParser('processSync', processor.Parser) assertCompiler('processSync', processor.Compiler) file = vfile(doc) process(file, done) assertDone('processSync', 'process', complete) return file function done(err) { complete = true bail(err) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function DeviceProcessor() {\n\tvar builder = new processor.Chain();\n\tbuilder.Add(save_flags);\n\tbuilder.Add(strip_syslog_priority);\n\tbuilder.Add(chain1);\n\tbuilder.Add(populate_fields);\n\tbuilder.Add(restore_flags);\n\tvar chain = builder.Build();\n\treturn {\n\t\tprocess: chain.Run,\n\t}\n}", "function ...
[ "0.58117294", "0.58117294", "0.58117294", "0.5587444", "0.5587444", "0.55766463", "0.54808366", "0.54090774", "0.53975576", "0.53039163", "0.52645934", "0.51741904", "0.51741904", "0.51741904", "0.51689416", "0.50885534", "0.5075839", "0.5067456", "0.5064785", "0.5058559", "0...
0.5479166
10
Create a new processor based on the processor in the current scope.
function processor() { var destination = unified() var length = attachers.length var index = -1 while (++index < length) { destination.use.apply(null, attachers[index]) } destination.data(extend(true, {}, namespace)) return destination }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function unified() {\n var attachers = []\n var transformers = trough()\n var namespace = {}\n var freezeIndex = -1\n var frozen\n\n // Data management.\n processor.data = data\n\n // Lock.\n processor.freeze = freeze\n\n // Plugins.\n processor.attachers = attachers\n processor.use = use\n\n // API.\...
[ "0.6117301", "0.6117301", "0.60486126", "0.5904408", "0.5904408", "0.5904408", "0.5904408", "0.5904408", "0.58828163", "0.5800185", "0.5721235", "0.56447303", "0.5328679", "0.52514666", "0.52514666", "0.52514666", "0.5194525", "0.51114035", "0.51101834", "0.51099145", "0.5081...
0.48947236
32
Data management. Getter / setter for processorspecific informtion.
function data(key, value) { if (string(key)) { /* Set `key`. */ if (arguments.length === 2) { assertUnfrozen('data', frozen) namespace[key] = value return processor } /* Get `key`. */ return (own.call(namespace, key) && namespace[key]) || null } /* Set space. */ if (key) { assertUnfrozen('data', frozen) namespace = key return processor } /* Get space. */ return namespace }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "get data() {\n\t\treturn this.__data;\n\t}", "function processedSFData() {\n\t\tthis.moteid = idMote;\n\t\tthis.sensorType = sensorType;\n\t\tthis.lastTimestamp = lastTimeStamp;\n\t\tthis.lastValue = lastValue;\n\t\tthis.arrayValuesDay = valuesDay;\n\t\tthis.populationDay = populationDay;\n\t\tthis.arrayValuesWe...
[ "0.6882254", "0.68435836", "0.6732056", "0.6642908", "0.6597483", "0.65298647", "0.64972115", "0.64913255", "0.64820457", "0.64820457", "0.64820457", "0.6423674", "0.63416713", "0.63211304", "0.63187164", "0.63104314", "0.62410027", "0.6230067", "0.62212604", "0.6212552", "0....
0.0
-1
Plugin management. Pass it: an attacher and options, a preset, a list of presets, attachers, and arguments (list of attachers and options).
function use(value) { var settings assertUnfrozen('use', frozen) if (value === null || value === undefined) { /* Empty */ } else if (typeof value === 'function') { addPlugin.apply(null, arguments) } else if (typeof value === 'object') { if ('length' in value) { addList(value) } else { addPreset(value) } } else { throw new Error('Expected usable value, not `' + value + '`') } if (settings) { namespace.settings = extend(namespace.settings || {}, settings) } return processor function addPreset(result) { addList(result.plugins) if (result.settings) { settings = extend(settings || {}, result.settings) } } function add(value) { if (typeof value === 'function') { addPlugin(value) } else if (typeof value === 'object') { if ('length' in value) { addPlugin.apply(null, value) } else { addPreset(value) } } else { throw new Error('Expected usable value, not `' + value + '`') } } function addList(plugins) { var length var index if (plugins === null || plugins === undefined) { /* Empty */ } else if (typeof plugins === 'object' && 'length' in plugins) { length = plugins.length index = -1 while (++index < length) { add(plugins[index]) } } else { throw new Error('Expected a list of plugins, not `' + plugins + '`') } } function addPlugin(plugin, value) { var entry = find(plugin) if (entry) { if (plain(entry[1]) && plain(value)) { value = extend(entry[1], value) } entry[1] = value } else { attachers.push(slice.call(arguments)) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function registerPresets(newPresets) {\n Object.keys(newPresets).forEach(function (name) {\n return registerPreset(name, newPresets[name]);\n });\n } // All the plugins we should bundle", "function handlePlugins$1(inputs, calendar) {\n calendar.addPluginInputs(inputs); // will ...
[ "0.55727583", "0.55137944", "0.5491354", "0.5477057", "0.5477057", "0.5477057", "0.54474187", "0.5436628", "0.5425356", "0.54101443", "0.54101443", "0.5381722", "0.5378221", "0.53756124", "0.53603595", "0.53582263", "0.53397644", "0.53294885", "0.53237104", "0.5295137", "0.52...
0.5292157
23
Parse a file (in string or VFile representation) into a Unist node using the `Parser` on the processor.
function parse(doc) { var file = vfile(doc) var Parser freeze() Parser = processor.Parser assertParser('parse', Parser) if (newable(Parser)) { return new Parser(String(file), file).parse() } return Parser(String(file), file) // eslint-disable-line new-cap }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function Parser(doc, file) {\n this.file = file;\n this.offset = {};\n this.options = xtend(this.options);\n this.setOptions({});\n\n this.inList = false;\n this.inBlock = false;\n this.inLink = false;\n this.atStart = true;\n\n this.toOffset = vfileLocation(file).toOffset;\n this.unescape = unescape(thi...
[ "0.6035281", "0.599663", "0.59361535", "0.5814588", "0.57627934", "0.57627934", "0.57627934", "0.5695019", "0.565769", "0.5630263", "0.5630263", "0.5630263", "0.5630263", "0.5630263", "0.5630263", "0.5603139", "0.5554233", "0.533918", "0.52537864", "0.5195392", "0.5108613", ...
0.57612985
10
Run transforms on a Unist node representation of a file (in string or VFile representation), async.
function run(node, file, cb) { assertNode(node) freeze() if (!cb && typeof file === 'function') { cb = file file = null } if (!cb) { return new Promise(executor) } executor(null, cb) function executor(resolve, reject) { transformers.run(node, vfile(file), done) function done(err, tree, file) { tree = tree || node if (err) { reject(err) } else if (resolve) { resolve(tree) } else { cb(null, tree, file) } } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function run(node, file, cb) {\n assertNode(node)\n freeze()\n\n if (!cb && typeof file === 'function') {\n cb = file\n file = null\n }\n\n if (!cb) {\n return new Promise(executor)\n }\n\n executor(null, cb)\n\n function executor(resolve, reject) {\n transformers.run(no...
[ "0.65101844", "0.65101844", "0.6500248", "0.6294634", "0.57297754", "0.57229096", "0.5722432", "0.5682045", "0.5500241", "0.5500241", "0.54538906", "0.5404583", "0.53382605", "0.5318412", "0.5295097", "0.529395", "0.52614886", "0.51727426", "0.51727426", "0.51727426", "0.5172...
0.64889526
7
Run transforms on a Unist node representation of a file (in string or VFile representation), sync.
function runSync(node, file) { var complete = false var result run(node, file, done) assertDone('runSync', 'run', complete) return result function done(err, tree) { complete = true bail(err) result = tree } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function run(node, file, cb) {\n assertNode(node)\n freeze()\n\n if (!cb && typeof file === 'function') {\n cb = file\n file = null\n }\n\n if (!cb) {\n return new Promise(executor)\n }\n\n executor(null, cb)\n\n function executor(resolve, reject) {\n transformers.run(no...
[ "0.64591384", "0.64591384", "0.644205", "0.644205", "0.644205", "0.644205", "0.644205", "0.644205", "0.6432624", "0.61897737", "0.60022", "0.60022", "0.5855565", "0.57527465", "0.5723397", "0.5631104", "0.55550617", "0.5509079", "0.5498221", "0.53799146", "0.5358135", "0.53...
0.5191977
30
Stringify a Unist node representation of a file (in string or VFile representation) into a string using the `Compiler` on the processor.
function stringify(node, doc) { var file = vfile(doc) var Compiler freeze() Compiler = processor.Compiler assertCompiler('stringify', Compiler) assertNode(node) if (newable(Compiler)) { return new Compiler(node, file).compile() } return Compiler(node, file) // eslint-disable-line new-cap }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function stringify(node, doc) {\n var file = vfile(doc)\n var Compiler\n\n freeze()\n Compiler = processor.Compiler\n assertCompiler('stringify', Compiler)\n assertNode(node)\n\n if (newable(Compiler, 'compile')) {\n return new Compiler(node, file).compile()\n }\n\n return Compiler(...
[ "0.5808293", "0.5808293", "0.5808293", "0.58024395", "0.5792998", "0.57217157", "0.55632764", "0.5119388", "0.49445158", "0.49397016", "0.49352276", "0.48916024", "0.4888284", "0.47806638", "0.47707263", "0.47499153", "0.47473553", "0.46570024", "0.4651487", "0.46407887", "0....
0.5798637
7
Parse a file (in string or VFile representation) into a Unist node using the `Parser` on the processor, then run transforms on that node, and compile the resulting node using the `Compiler` on the processor, and store that result on the VFile.
function process(doc, cb) { freeze() assertParser('process', processor.Parser) assertCompiler('process', processor.Compiler) if (!cb) { return new Promise(executor) } executor(null, cb) function executor(resolve, reject) { var file = vfile(doc) pipeline.run(processor, {file: file}, done) function done(err) { if (err) { reject(err) } else if (resolve) { resolve(file) } else { cb(null, file) } } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function run(node, file, cb) {\n assertNode(node)\n freeze()\n\n if (!cb && typeof file === 'function') {\n cb = file\n file = null\n }\n\n if (!cb) {\n return new Promise(executor)\n }\n\n executor(null, cb)\n\n function executor(resolve, reject) {\n transformers.run(no...
[ "0.5783369", "0.5783369", "0.57678044", "0.57678044", "0.57678044", "0.57678044", "0.57678044", "0.57678044", "0.573477", "0.5524739", "0.5524739", "0.55166644", "0.5511736", "0.54946756", "0.5463103", "0.5417252", "0.5406631", "0.53526235", "0.53465986", "0.5324869", "0.5324...
0.55421233
14
Process the given document (in string or VFile representation), sync.
function processSync(doc) { var complete = false var file freeze() assertParser('processSync', processor.Parser) assertCompiler('processSync', processor.Compiler) file = vfile(doc) process(file, done) assertDone('processSync', 'process', complete) return file function done(err) { complete = true bail(err) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function processSync(doc) {\n var file;\n var complete;\n\n freeze();\n assertParser('processSync', processor.Parser);\n assertCompiler('processSync', processor.Compiler);\n file = vfile(doc);\n\n process(file, done);\n\n assertDone('processSync', 'process', complete);\n\n return file\n\...
[ "0.7181942", "0.7127588", "0.70959693", "0.70959693", "0.65708774", "0.6547708", "0.6525776", "0.6525776", "0.6525776", "0.6525776", "0.6525776", "0.6525776", "0.6501485", "0.6501485", "0.5860337", "0.5381363", "0.5375347", "0.5256774", "0.51226515", "0.5107933", "0.5096684",...
0.7046547
8
Check if `func` is a constructor.
function newable(value) { return typeof value === 'function' && keys(value.prototype) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function isConstructor(name, func) {\n return name[0] == name[0].toUpperCase();\n }", "function isCtor(constr) {\n return constr && !!constr.CONSTRUCTOR___;\n }", "function IsConstructor(o) {\n // Hacks for Safari 7 TypedArray XXXConstructor objects\n if (/Constructor/.test(Object.protot...
[ "0.78567946", "0.77828586", "0.72959", "0.7212019", "0.70982814", "0.70852464", "0.705966", "0.70311177", "0.7030553", "0.69598", "0.69360584", "0.6911233", "0.6753676", "0.66875815", "0.66067296", "0.6506227", "0.6431026", "0.6381115", "0.6379887", "0.62503326", "0.6193139",...
0.0
-1
Check if `value` is an object with keys.
function keys(value) { var key for (key in value) { return true } return false }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function isObject(value) {\n var type = typeof value;\n return !!value && (type == 'object');\n }", "function isKey(value, object) {\n if (Array.isArray(value)) {\n return false;\n }\n const type = typeof value;\n if (\n type === \"number\" ||\n type === \"boolean\" ||\n value ==...
[ "0.7191914", "0.71467626", "0.71403253", "0.71176916", "0.7086549", "0.7021256", "0.6997804", "0.6993788", "0.6949828", "0.6939899", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011", "0.693011...
0.6883021
27
Assert a parser is available.
function assertParser(name, Parser) { if (typeof Parser !== 'function') { throw new Error('Cannot `' + name + '` without `Parser`') } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertParser(name, Parser) {\n if (!func(Parser)) {\n throw new Error('Cannot `' + name + '` without `Parser`');\n }\n}", "async ensureParser() {\n if (!this.parser) {\n this.parser = await ASTParser.importASTParser();\n }\n }", "function _checkParser() {\n eval(Proce...
[ "0.7156712", "0.66241133", "0.62994504", "0.50442", "0.4859782", "0.4845704", "0.48403746", "0.48403746", "0.47225016", "0.47192085", "0.47178409", "0.47056007", "0.47056007", "0.47056007", "0.47056007", "0.47035977", "0.47035977", "0.47035977", "0.47035977", "0.46994075", "0...
0.7231354
6
Assert a compiler is available.
function assertCompiler(name, Compiler) { if (typeof Compiler !== 'function') { throw new Error('Cannot `' + name + '` without `Compiler`') } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertCompiler(name, Compiler) {\n if (!func(Compiler)) {\n throw new Error('Cannot `' + name + '` without `Compiler`');\n }\n}", "function startMyCompiler() {\n throw new Error('You have no compiler!');\n}", "function _isSupported() {\n _state = 1;\n if (typeof chai !== \"undefi...
[ "0.7280039", "0.6609343", "0.5701623", "0.55071414", "0.5359753", "0.5310645", "0.5287135", "0.5255695", "0.5185235", "0.51780653", "0.51780653", "0.510953", "0.50870246", "0.5071456", "0.5061714", "0.50458944", "0.50141674", "0.49524596", "0.49390462", "0.4907709", "0.490542...
0.7297869
6
Assert the processor is not frozen.
function assertUnfrozen(name, frozen) { if (frozen) { throw new Error( [ 'Cannot invoke `' + name + '` on a frozen processor.\nCreate a new ', 'processor first, by invoking it: use `processor()` instead of ', '`processor`.' ].join('') ) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertUnfrozen(name, frozen) {\n if (frozen) {\n throw new Error(\n 'Cannot invoke `' + name + '` on a frozen processor.\\n' +\n 'Create a new processor first, by invoking it: ' +\n 'use `processor()` instead of `processor`.'\n );\n }\n}", "function assertUnfrozen(name, frozen) {\...
[ "0.763147", "0.762365", "0.762365", "0.762365", "0.762365", "0.6224439", "0.6096795", "0.5899092", "0.5878287", "0.570214", "0.570214", "0.570214", "0.570214", "0.570214", "0.570214", "0.5657232", "0.5657232", "0.5657232", "0.5657232", "0.5657232", "0.56491834", "0.56472737...
0.7521065
8
Assert `node` is a Unist node.
function assertNode(node) { if (!node || !string(node.type)) { throw new Error('Expected node, got `' + node + '`') } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertNode(node) {\n if (!node || !string(node.type)) {\n throw new Error('Expected node, got `' + node + '`');\n }\n}", "function assertNode(node) {\n if (!node || typeof node.type !== 'string') {\n throw new Error('Expected node, got `' + node + '`')\n }\n}", "function assertNode(node) {\n...
[ "0.62221384", "0.61372936", "0.61372936", "0.61372936", "0.61372936", "0.5832636", "0.5832636", "0.5619439", "0.5619439", "0.55803466", "0.55803466", "0.55803466", "0.52470446", "0.52253616", "0.5197108", "0.5097337", "0.5097337", "0.5097337", "0.5097337", "0.5046135", "0.504...
0.62289256
3
Assert that `complete` is `true`.
function assertDone(name, asyncName, complete) { if (!complete) { throw new Error( '`' + name + '` finished async. Use `' + asyncName + '` instead' ) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertDone(name, asyncName, complete) {\n if (!complete) {\n throw new Error('`' + name + '` finished async. Use `' + asyncName + '` instead');\n }\n}", "isComplete() {\n return (this.title === this.titleComplete) &&\n (this.labo === this.laboComplete) &&\n (this.univ =...
[ "0.64496076", "0.62851554", "0.61078316", "0.6088317", "0.6086782", "0.6085638", "0.6077784", "0.60390526", "0.6015842", "0.59758866", "0.5937751", "0.58899134", "0.5833281", "0.57518196", "0.57095605", "0.55940217", "0.558774", "0.5580275", "0.55591047", "0.55531603", "0.554...
0.6452487
6
Create a message with `reason` at `position`. When an error is passed in as `reason`, copies the stack.
function message(reason, position, origin) { var filePath = this.path; var message = new VMessage(reason, position, origin); if (filePath) { message.name = filePath + ':' + message.name; message.file = filePath; } message.fatal = false; this.messages.push(message); return message; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function message(reason, position, ruleId) {\n var filePath = this.path;\n var range = stringify(position) || '1:1';\n var location;\n var err;\n\n location = {\n start: {line: null, column: null},\n end: {line: null, column: null}\n };\n\n if (position && position.position) {\n position = position...
[ "0.6381248", "0.5829679", "0.5817722", "0.5817722", "0.5817722", "0.5814672", "0.5766498", "0.5684867", "0.5679618", "0.54449147", "0.5392339", "0.5223852", "0.52174985", "0.50576764", "0.5057408", "0.5057408", "0.5032766", "0.5025934", "0.50057685", "0.4889266", "0.4858025",...
0.56966686
10
Fail. Creates a vmessage, associates it with the file, and throws it.
function fail() { var message = this.message.apply(this, arguments); message.fatal = true; throw message; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function fail(message) {\n throw new Error(message);\n }", "function fail(message) {\r\n\t throw new Error(message);\r\n\t}", "createFailureAtNode(node, message) {\n const sourceFile = node.getSourceFile();\n this.failures.push({\n filePath: this.fileSyst...
[ "0.62669474", "0.62532586", "0.6132922", "0.6082876", "0.5987928", "0.5987928", "0.5881269", "0.5881269", "0.5881269", "0.5881269", "0.5850965", "0.57309186", "0.57105887", "0.55708826", "0.55331993", "0.5513839", "0.5513839", "0.5513839", "0.5513839", "0.5513839", "0.5501027...
0.57952315
16
Info. Creates a vmessage, associates it with the file, and marks the fatality as null.
function info() { var message = this.message.apply(this, arguments); message.fatal = null; return message; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function info() {\n var message = this.message.apply(this, arguments)\n\n message.fatal = null\n\n return message\n}", "function info() {\n var message = this.message.apply(this, arguments)\n\n message.fatal = null\n\n return message\n}", "function info() {\n var message = this.message.apply(this, argum...
[ "0.65584934", "0.65584934", "0.65584934", "0.65584934", "0.6528591", "0.6275661", "0.61959714", "0.61930555", "0.61930555", "0.61930555", "0.61930555", "0.61930555", "0.6156254", "0.6156254", "0.6156254", "0.61109775", "0.58577347", "0.5675953", "0.5599736", "0.549691", "0.54...
0.6468086
8
Construct a new file.
function VFile(options) { var prop; var index; var length; if (!options) { options = {}; } else if (typeof options === 'string' || buffer(options)) { options = {contents: options}; } else if ('message' in options && 'messages' in options) { return options; } if (!(this instanceof VFile)) { return new VFile(options); } this.data = {}; this.messages = []; this.history = []; this.cwd = process.cwd(); /* Set path related properties in the correct order. */ index = -1; length = order.length; while (++index < length) { prop = order[index]; if (own.call(options, prop)) { this[prop] = options[prop]; } } /* Set non-path related properties. */ for (prop in options) { if (order.indexOf(prop) === -1) { this[prop] = options[prop]; } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function createFile() {\n var e = new emitter();\n\n fs.readFile('newdocument.txt', function (err) {\n if (err) throw err;\n e.emit('theProcess');\n });\n\n return e;\n}", "function createNewFile() {\n file = {\n name: 'novo-arquivo.txt',\n content: '',\n saved: ...
[ "0.6732228", "0.65486455", "0.6370457", "0.617571", "0.6127362", "0.6070642", "0.6070063", "0.6053265", "0.6018561", "0.5999493", "0.59618163", "0.5958732", "0.59435254", "0.58879983", "0.588575", "0.58559304", "0.58342546", "0.5803781", "0.5784671", "0.577569", "0.57531786",...
0.0
-1
Get the value of the file.
function toString(encoding) { var value = this.contents || ''; return buffer(value) ? value.toString(encoding) : String(value); }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function getFile(){\n\n\t\treturn this.file;\n\t}", "Get(filename)\n {\n return \"\";\n }", "getText() {\r\n return this.clone(File, \"$value\", false).get(new TextParser(), { headers: { \"binaryStringResponseBody\": \"true\" } });\r\n }", "get file () {\n return this._file\n }", "functi...
[ "0.711178", "0.68999565", "0.6691765", "0.66412055", "0.6439003", "0.64349145", "0.6405714", "0.637939", "0.6368529", "0.6368529", "0.6324943", "0.6303016", "0.6242697", "0.60756075", "0.59203756", "0.58928937", "0.58921486", "0.5867203", "0.5867203", "0.5792994", "0.5783152"...
0.0
-1
Assert that `part` is not a path (i.e., does not contain `path.sep`).
function assertPart(part, name) { if (part.indexOf(path.sep) !== -1) { throw new Error('`' + name + '` cannot be a path: did not expect `' + path.sep + '`'); } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertPart(part, name) {\n if (part.indexOf(path.sep) !== -1) {\n throw new Error(\n '`' + name + '` cannot be a path: did not expect `' + path.sep + '`'\n )\n }\n}", "function assertPart(part, name) {\n if (part.indexOf(path.sep) !== -1) {\n throw new Error(\n '`' + name + '` cann...
[ "0.8634517", "0.86085933", "0.85808706", "0.85808706", "0.85808706", "0.83589625", "0.6666308", "0.6666308", "0.6666308", "0.6666308", "0.6664525", "0.6664525", "0.6664525", "0.6664525", "0.6664525", "0.6664525", "0.6664525", "0.6614382", "0.5684847", "0.56838113", "0.5673563...
0.86380607
4
Assert that `part` is not empty.
function assertNonEmpty(part, name) { if (!part) { throw new Error('`' + name + '` cannot be empty'); } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function assertNonEmpty(part, name) {\n if (!part) {\n throw new Error('`' + name + '` cannot be empty')\n }\n}", "function assertNonEmpty(part, name) {\n if (!part) {\n throw new Error('`' + name + '` cannot be empty')\n }\n}", "function assertNonEmpty(part, name) {\n if (!part) {\n throw new Er...
[ "0.82078385", "0.82078385", "0.82078385", "0.82078385", "0.8098381", "0.6483384", "0.6483384", "0.6483384", "0.6483384", "0.6483384", "0.6483384", "0.64686406", "0.6467794", "0.64403224", "0.6432958", "0.6432958", "0.6432958", "0.62206465", "0.60916746", "0.5781566", "0.57726...
0.82067513
9
For Node v0.10 support. Remove this eventually.
function isSlowBuffer (obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function _node_p(){\n\tvar ret = false;\n\tif( anchor.environment() == 'Node.js' ){ ret = true; }\n\treturn ret;\n }", "function node_error(err) {\r\n node.error(err, err);\r\n }", "private public function m246() {}", "function NodeFsHandler() {}", "function NodeFsHandler() {}", "static reset(...
[ "0.5863474", "0.5705808", "0.568645", "0.55544066", "0.55544066", "0.5446477", "0.5434516", "0.5381192", "0.5356294", "0.53282356", "0.53189546", "0.52043676", "0.51996946", "0.5156968", "0.51501393", "0.51281303", "0.51281303", "0.51281303", "0.5112595", "0.5100047", "0.5090...
0.0
-1
Run `fns`. Last argument must be a completion handler.
function run() { var index = -1 var input = slice.call(arguments, 0, -1) var done = arguments[arguments.length - 1] if (typeof done !== 'function') { throw new Error('Expected function as last argument, not ' + done) } next.apply(null, [null].concat(input)) /* Run the next `fn`, if any. */ function next(err) { var fn = fns[++index] var params = slice.call(arguments, 0) var values = params.slice(1) var length = input.length var pos = -1 if (err) { done(err) return } /* Copy non-nully input into values. */ while (++pos < length) { if (values[pos] === null || values[pos] === undefined) { values[pos] = input[pos] } } input = values /* Next or done. */ if (fn) { wrap(fn, next).apply(null, input) } else { done.apply(null, [null].concat(input)) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function runAll(whenFn, fns, resolveIdx) {\n //var deferred = when.defer();\n return whenFn(fns)\n .then(\n function(results) {\n return results[resolveIdx];\n },\n function(err) {\n return when.reject(err);\n }\n );\n}", "function run() {\n var index = -1;\n var inp...
[ "0.68478644", "0.66488874", "0.65061486", "0.65061486", "0.65061486", "0.65061486", "0.65061486", "0.65061486", "0.6376086", "0.617489", "0.59881306", "0.5942612", "0.5926571", "0.58897847", "0.5781694", "0.57793677", "0.56860965", "0.56757015", "0.5613648", "0.5584616", "0.5...
0.65281355
3
Run the next `fn`, if any.
function next(err) { var fn = fns[++index] var params = slice.call(arguments, 0) var values = params.slice(1) var length = input.length var pos = -1 if (err) { done(err) return } /* Copy non-nully input into values. */ while (++pos < length) { if (values[pos] === null || values[pos] === undefined) { values[pos] = input[pos] } } input = values /* Next or done. */ if (fn) { wrap(fn, next).apply(null, input) } else { done.apply(null, [null].concat(input)) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function run(fn) {\n if (fn)\n fn(next);\n else\n callback(null, results);\n }", "function next(err, result) {\n if (err)\n return callback(err, results);\n results.push(result);\n if (fns.length)\n run(fns.shift());\n else\n callback(null, results);\n }", "function...
[ "0.78941613", "0.7258772", "0.66877997", "0.6568779", "0.6472971", "0.6472971", "0.6464633", "0.6464633", "0.6464633", "0.6464633", "0.6464633", "0.6464633", "0.64020425", "0.6374047", "0.6338008", "0.6277549", "0.62038606", "0.61732835", "0.61340165", "0.61340165", "0.613401...
0.6171807
19
Add `fn` to the list.
function use(fn) { if (typeof fn !== 'function') { throw new Error('Expected `fn` to be a function, not ' + fn) } fns.push(fn) return middleware }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function addWithFunction(list, item, hashFunction) {\n if (findWithFunction(list, hashFunction) === -1) {\n list.push(item);\n }\n }", "custom(fn) {\r\n\t\treturn this.push('fn', [...arguments]);\r\n\t}", "function addToQueue(fn) {\n if (working) {\n queue.push(fn);\n }...
[ "0.6937784", "0.6697556", "0.62223893", "0.620402", "0.6063277", "0.60530466", "0.5974585", "0.5911953", "0.58088225", "0.58088225", "0.58088225", "0.58088225", "0.58088225", "0.58088225", "0.58088225", "0.5778424", "0.5762916", "0.5737459", "0.5720332", "0.5718001", "0.56721...
0.5733852
23
Wrap `fn`. Can be sync or async; return a promise, receive a completion handler, return new values and errors.
function wrap(fn, callback) { var invoked return wrapped function wrapped() { var params = slice.call(arguments, 0) var callback = fn.length > params.length var result if (callback) { params.push(done) } try { result = fn.apply(null, params) } catch (err) { /* Well, this is quite the pickle. `fn` received * a callback and invoked it (thus continuing the * pipeline), but later also threw an error. * We’re not about to restart the pipeline again, * so the only thing left to do is to throw the * thing instea. */ if (callback && invoked) { throw err } return done(err) } if (!callback) { if (result && typeof result.then === 'function') { result.then(then, done) } else if (result instanceof Error) { done(result) } else { then(result) } } } /* Invoke `next`, only once. */ function done() { if (!invoked) { invoked = true callback.apply(null, arguments) } } /* Invoke `done` with one value. * Tracks if an error is passed, too. */ function then(value) { done(null, value) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function wrap_sync (fn) {\n return function (params) {\n var val = fn(params)\n if (val && !isPromise(val)) throw val\n return val\n }\n}", "async function thenify(fn) {\n return await new Promise(function(resolve, reject) {\n function callback(err, res) {\n if (err) return reject(err);\n ...
[ "0.75723845", "0.6946835", "0.6856506", "0.68295383", "0.6647942", "0.65730035", "0.6559632", "0.6465274", "0.6465274", "0.64327705", "0.63656604", "0.6305889", "0.6305889", "0.6305889", "0.6305889", "0.6305889", "0.6305889", "0.62676936", "0.6259724", "0.625207", "0.6248762"...
0.6257096
20
Invoke `next`, only once.
function done() { if (!invoked) { invoked = true callback.apply(null, arguments) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "next () {}", "next() {}", "next() {\n this._next();\n }", "Next() {}", "function next() {\n subject = context.stack.tail.head;\n index = 0;\n test( subject );\n }", "async next() {\n this._executing = false;\n await this._execute();\n }", "function _next() {\n...
[ "0.78337926", "0.7766705", "0.742107", "0.7365195", "0.6899227", "0.6799684", "0.6630355", "0.6603183", "0.65826726", "0.6529928", "0.6470122", "0.6434803", "0.6434803", "0.6420854", "0.6374825", "0.6374825", "0.6349096", "0.63221407", "0.631236", "0.63065857", "0.63003343", ...
0.0
-1
Invoke `done` with one value. Tracks if an error is passed, too.
function then(value) { done(null, value) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function then(value) {\n done(null, value);\n }", "function finish (err) {\n if (!calledDone) {\n calledDone = true;\n done(err);\n }\n }", "function done() {}", "function done ( error ) {\n if (error) {\n that.error = error\n }\n if ( cb ) cb( error )\n }", "done() {}",...
[ "0.6571373", "0.6488745", "0.6473631", "0.6420267", "0.6381803", "0.6373509", "0.63661045", "0.63661045", "0.63661045", "0.63661045", "0.63661045", "0.63661045", "0.63661045", "0.63661045", "0.6287417", "0.6274371", "0.62423915", "0.6176341", "0.6172195", "0.60484797", "0.604...
0.6636376
7
Create a custom constructor which can be modified without affecting the original class.
function unherit(Super) { var result var key var value inherits(Of, Super) inherits(From, Of) /* Clone values. */ result = Of.prototype for (key in result) { value = result[key] if (value && typeof value === 'object') { result[key] = 'concat' in value ? value.concat() : xtend(value) } } return Of /* Constructor accepting a single argument, * which itself is an `arguments` object. */ function From(parameters) { return Super.apply(this, parameters) } /* Constructor accepting variadic arguments. */ function Of() { if (!(this instanceof Of)) { return new From(arguments) } return Super.apply(this, arguments) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function temporaryConstructor() {}", "function Constructor() {}", "function Constructor() {}", "function Constructor() {}", "constructor() {\n copy(this, create());\n }", "new() {\n let newInstance = Object.create(this);\n\n newInstance.init(...arguments);\n\n return newInstance;\n }"...
[ "0.7258686", "0.7070626", "0.7070626", "0.7070626", "0.7062644", "0.70268816", "0.69127655", "0.68617797", "0.6758441", "0.6758441", "0.67081964", "0.67081964", "0.67081964", "0.67081964", "0.67081964", "0.67081964", "0.6666097", "0.6631405", "0.6616296", "0.66080546", "0.654...
0.0
-1
Constructor accepting a single argument, which itself is an `arguments` object.
function From(parameters) { return Super.apply(this, parameters) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function C(arg) {\n this.args = arguments;\n}", "constructor(args) {\n super(args);\n }", "constructor(args) {\n super(args);\n }", "constructor(args) {\n super();\n args = args || {}\n this.CONSTRUCTOR_ID = 0x99c1d49d;\n this.SUBCLASS_OF_ID = 0xeb9987b3;\n\n this....
[ "0.6960877", "0.64379203", "0.64379203", "0.63124055", "0.62877387", "0.62737846", "0.6272634", "0.62375265", "0.62284786", "0.62265486", "0.6200758", "0.6163937", "0.6160433", "0.6148898", "0.61483806", "0.6135509", "0.61281246", "0.61076164", "0.60998803", "0.60958815", "0....
0.0
-1
Constructor accepting variadic arguments.
function Of() { if (!(this instanceof Of)) { return new From(arguments) } return Super.apply(this, arguments) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "static create(...args /* :Array<*> */) {\n\t\treturn new this(...args)\n\t}", "construct (target, args) {\n return new target(...args)\n }", "constructor(args) {\n super();\n args = args || {}\n this.CONSTRUCTOR_ID = 0x09333afb;\n this.SUBCLASS_OF_ID = 0xf1163490;\n\n thi...
[ "0.7136816", "0.6953033", "0.692598", "0.69021624", "0.69021624", "0.6878798", "0.6776414", "0.67102474", "0.6695473", "0.66910213", "0.6659877", "0.66535336", "0.6645595", "0.6640925", "0.6639501", "0.6638436", "0.66289335", "0.66243696", "0.66028565", "0.6594345", "0.658970...
0.0
-1
Get all keys in `value`.
function keys(value) { var result = []; var key; for (key in value) { result.push(key); } return result; }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function keys(value) {\n var result = []\n var key\n\n for (key in value) {\n result.push(key)\n }\n\n return result\n}", "function keys(value) {\n var key\n for (key in value) {\n return true\n }\n return false\n}", "function keys(value) {\n var key\n for (key in value) {\n return true\n ...
[ "0.83654433", "0.6577015", "0.6577015", "0.6577015", "0.6577015", "0.6577015", "0.6546291", "0.65166605", "0.65166605", "0.65166605", "0.6439548", "0.63332194", "0.62305605", "0.61524576", "0.6028577", "0.5955654", "0.57845986", "0.57845986", "0.569534", "0.56586033", "0.5628...
0.8280043
6
Construct a state `toggler`: a function which inverses `property` in context based on its current value. The by `toggler` returned function restores that value.
function factory(key, state, ctx) { return enter function enter() { var context = ctx || this var current = context[key] context[key] = !state return exit function exit() { context[key] = current } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function toggleable_factory(prop = 'value', event = 'input') {\n return external_commonjs_vue_commonjs2_vue_root_Vue_default.a.extend({\n name: 'toggleable',\n model: {\n prop,\n event\n },\n props: {\n [prop]: {\n required: false\n }\n },\n\n data() {\n return {\...
[ "0.5624407", "0.5624407", "0.5624407", "0.56162673", "0.52129716", "0.51249146", "0.5085456", "0.50650775", "0.5043587", "0.5028423", "0.49811652", "0.49747854", "0.4938197", "0.49364012", "0.49305844", "0.49178904", "0.4913725", "0.48937052", "0.48874176", "0.4885378", "0.48...
0.0
-1
Factory to get the line and columnbased `position` for `offset` in the bound indices.
function offsetToPositionFactory(indices) { return offsetToPosition /* Get the line and column-based `position` for * `offset` in the bound indices. */ function offsetToPosition(offset) { var index = -1 var length = indices.length if (offset < 0) { return {} } while (++index < length) { if (indices[index] > offset) { return { line: index + 1, column: offset - (indices[index - 1] || 0) + 1, offset: offset } } } return {} } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "function positionToOffsetFactory(indices) {\n return positionToOffset\n\n // Get the `offset` for a line and column-based `position` in the bound\n // indices.\n function positionToOffset(position) {\n var line = position && position.line\n var column = position && position.column\n\n if (!isNaN(line)...
[ "0.70763355", "0.70763355", "0.70763355", "0.7004144", "0.7004144", "0.7004144", "0.6975304", "0.6975304", "0.68680584", "0.68680584", "0.68680584", "0.68680584", "0.68680584", "0.6756796", "0.661255", "0.6544451", "0.6493372", "0.64535576", "0.64535576", "0.64453626", "0.644...
0.6980898
7
Get the line and columnbased `position` for `offset` in the bound indices.
function offsetToPosition(offset) { var index = -1 var length = indices.length if (offset < 0) { return {} } while (++index < length) { if (indices[index] > offset) { return { line: index + 1, column: offset - (indices[index - 1] || 0) + 1, offset: offset } } } return {} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "getLineAndColumnFromChunk(offset) {\r\n\t\t\t\tvar column, columnCompensation, compensation, lastLine, lineCount, previousLinesCompensation, ref, string;\r\n\t\t\t\tcompensation = this.getLocationDataCompensation(this.chunkOffset, this.chunkOffset + offset);\r\n\t\t\t\tif (offset === 0) {\r\n\t\t\t\t\treturn [this...
[ "0.66768277", "0.6669494", "0.6658669", "0.6658669", "0.6652049", "0.6435141", "0.6435141", "0.6435141", "0.6418775", "0.63339", "0.6331776", "0.6331776", "0.6272726", "0.6272726", "0.6272726", "0.6272628", "0.6261748", "0.6261748", "0.62456626", "0.6239385", "0.6239385", "...
0.7061033
3