_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q26200
extractPropertiesFromSource
train
function extractPropertiesFromSource(source, offset) { offset = offset || 0; source = source.replace(reSpaceEnd, ''); var out = []; if (!source) { return out; } var tokens = cssParser.parse(source); var it = tokenIterator.create(tokens); var property; while ((property = consumeSingleProperty(it, source))) { out.push({ nameText: property.name.substring(source), name: property.name.shift(offset), valueText: property.value.substring(source), value: property.value.shift(offset), endText: property.end.substring(source), end: property.end.shift(offset) }); } return out; }
javascript
{ "resource": "" }
q26201
train
function(name, value, pos) { var list = this.list(); var start = this._positions.contentStart; var styles = utils.pick(this.options, 'styleBefore', 'styleSeparator'); if (typeof pos === 'undefined') { pos = list.length; } /** @type CSSEditProperty */ var donor = list[pos]; if (donor) { start = donor.fullRange().start; } else if ((donor = list[pos - 1])) { // make sure that donor has terminating semicolon donor.end(';'); start = donor.range().end; } if (donor) { styles = utils.pick(donor, 'styleBefore', 'styleSeparator'); } var nameToken = editTree.createToken(start + styles.styleBefore.length, name); var valueToken = editTree.createToken(nameToken.end + styles.styleSeparator.length, value); var property = new CSSEditElement(this, nameToken, valueToken, editTree.createToken(valueToken.end, ';')); utils.extend(property, styles); // write new property into the source this._updateSource(property.styleBefore + property.toString(), start); // insert new property this._children.splice(pos, 0, property); return property; }
javascript
{ "resource": "" }
q26202
train
function(isAbsolute) { var parts = findParts(this.value()); if (isAbsolute) { var offset = this.valuePosition(true); parts.forEach(function(p) { p.shift(offset); }); } return parts; }
javascript
{ "resource": "" }
q26203
train
function(val) { var isUpdating = typeof val !== 'undefined'; var allItems = this.parent.list(); if (isUpdating && this.isIncomplete()) { var self = this; var donor = utils.find(allItems, function(item) { return item !== self && !item.isIncomplete(); }); this.styleSeparator = donor ? donor.styleSeparator : this.parent.options.styleSeparator; this.parent._updateSource(this.styleSeparator, range(this.valueRange().start, 0)); } var value = this.constructor.__super__.value.apply(this, arguments); if (isUpdating) { // make sure current property has terminating semi-colon // if it’s not the last one var ix = allItems.indexOf(this); if (ix !== allItems.length - 1 && !this.end()) { this.end(';'); } } return value; }
javascript
{ "resource": "" }
q26204
train
function(css, pos) { var cssProp = null; /** @type EditContainer */ var cssRule = typeof css === 'string' ? this.parseFromPosition(css, pos, true) : css; if (cssRule) { cssProp = cssRule.itemFromPosition(pos, true); if (!cssProp) { // in case user just started writing CSS property // and didn't include semicolon–try another approach cssProp = utils.find(cssRule.list(), function(elem) { return elem.range(true).end == pos; }); } } return cssProp; }
javascript
{ "resource": "" }
q26205
train
function(range) { if (this.overlap(range)) { var start = Math.max(range.start, this.start); var end = Math.min(range.end, this.end); return new Range(start, end - start); } return null; }
javascript
{ "resource": "" }
q26206
train
function(loc, left, right) { var a, b; if (loc instanceof Range) { a = loc.start; b = loc.end; } else { a = b = loc; } return cmp(this.start, a, left || '<=') && cmp(this.end, b, right || '>'); }
javascript
{ "resource": "" }
q26207
train
function(strings) { var lengths = strings.map(function(s) { return typeof s === 'string' ? s.length : +s; }); var max = lengths.reduce(function(prev, cur) { return typeof prev === 'undefined' ? cur : Math.max(prev, cur); }); return lengths.map(function(l) { var pad = max - l; return pad ? this.repeatString(' ', pad) : ''; }, this); }
javascript
{ "resource": "" }
q26208
train
function(text, pad) { var result = []; var lines = this.splitByLines(text); var nl = '\n'; result.push(lines[0]); for (var j = 1; j < lines.length; j++) result.push(nl + pad + lines[j]); return result.join(''); }
javascript
{ "resource": "" }
q26209
train
function(str, pad) { var padding = ''; var il = str.length; while (pad > il++) padding += '0'; return padding + str; }
javascript
{ "resource": "" }
q26210
train
function(text, pad) { var lines = this.splitByLines(text); var pl = pad.length; for (var i = 0, il = lines.length, line; i < il; i++) { line = lines[i]; if (line.substr(0, pl) === pad) { lines[i] = line.substr(pl); } } return lines.join('\n'); }
javascript
{ "resource": "" }
q26211
train
function(content, ranges, ch, noRepeat) { if (ranges.length) { var offset = 0, fragments = []; ranges.forEach(function(r) { var repl = noRepeat ? ch : this.repeatString(ch, r[1] - r[0]); fragments.push(content.substring(offset, r[0]), repl); offset = r[1]; }, this); content = fragments.join('') + content.substring(offset); } return content; }
javascript
{ "resource": "" }
q26212
train
function(text, start, end) { var rng = range.create(start, end); var reSpace = /[\s\n\r\u00a0]/; // narrow down selection until first non-space character while (rng.start < rng.end) { if (!reSpace.test(text.charAt(rng.start))) break; rng.start++; } while (rng.end > rng.start) { rng.end--; if (!reSpace.test(text.charAt(rng.end))) { rng.end++; break; } } return rng; }
javascript
{ "resource": "" }
q26213
train
function(node, offset) { var maxNum = 0; var options = { tabstop: function(data) { var group = parseInt(data.group, 10); if (group > maxNum) maxNum = group; if (data.placeholder) return '${' + (group + offset) + ':' + data.placeholder + '}'; else return '${' + (group + offset) + '}'; } }; ['start', 'end', 'content'].forEach(function(p) { node[p] = this.processText(node[p], options); }, this); return maxNum; }
javascript
{ "resource": "" }
q26214
train
function(text, node, type) { var maxNum = 0; var that = this; var tsOptions = { tabstop: function(data) { var group = parseInt(data.group, 10); if (group === 0) return '${0}'; if (group > maxNum) maxNum = group; if (data.placeholder) { // respect nested placeholders var ix = group + tabstopIndex; var placeholder = that.processText(data.placeholder, tsOptions); return '${' + ix + ':' + placeholder + '}'; } else { return '${' + (group + tabstopIndex) + '}'; } } }; // upgrade tabstops text = this.processText(text, tsOptions); // resolve variables text = this.replaceVariables(text, this.variablesResolver(node)); tabstopIndex += maxNum + 1; return text; }
javascript
{ "resource": "" }
q26215
makeAttributesString
train
function makeAttributesString(node, profile) { var attrQuote = profile.attributeQuote(); var cursor = profile.cursor(); return node.attributeList().map(function(a) { var isBoolean = profile.isBoolean(a.name, a.value); var attrName = profile.attributeName(a.name); var attrValue = isBoolean ? attrName : a.value; if (isBoolean && profile.allowCompactBoolean()) { return ' ' + attrName; } return ' ' + attrName + '=' + attrQuote + (attrValue || cursor) + attrQuote; }).join(''); }
javascript
{ "resource": "" }
q26216
train
function(str) { var curOffset = str.length; var startIndex = -1; var groupCount = 0; var braceCount = 0; var textCount = 0; while (true) { curOffset--; if (curOffset < 0) { // moved to the beginning of the line startIndex = 0; break; } var ch = str.charAt(curOffset); if (ch == ']') { braceCount++; } else if (ch == '[') { if (!braceCount) { // unexpected brace startIndex = curOffset + 1; break; } braceCount--; } else if (ch == '}') { textCount++; } else if (ch == '{') { if (!textCount) { // unexpected brace startIndex = curOffset + 1; break; } textCount--; } else if (ch == ')') { groupCount++; } else if (ch == '(') { if (!groupCount) { // unexpected brace startIndex = curOffset + 1; break; } groupCount--; } else { if (braceCount || textCount) // respect all characters inside attribute sets or text nodes continue; else if (!abbreviationParser.isAllowedChar(ch) || (ch == '>' && utils.endsWithTag(str.substring(0, curOffset + 1)))) { // found stop symbol startIndex = curOffset + 1; break; } } } if (startIndex != -1 && !textCount && !braceCount && !groupCount) // found something, remove some invalid symbols from the // beginning and return abbreviation return str.substring(startIndex).replace(/^[\*\+\>\^]+/, ''); else return ''; }
javascript
{ "resource": "" }
q26217
train
function(stream) { var pngMagicNum = "\211PNG\r\n\032\n", jpgMagicNum = "\377\330", gifMagicNum = "GIF8", pos = 0, nextByte = function() { return stream.charCodeAt(pos++); }; if (stream.substr(0, 8) === pngMagicNum) { // PNG. Easy peasy. pos = stream.indexOf('IHDR') + 4; return { width: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte(), height: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte() }; } else if (stream.substr(0, 4) === gifMagicNum) { pos = 6; return { width: nextByte() | (nextByte() << 8), height: nextByte() | (nextByte() << 8) }; } else if (stream.substr(0, 2) === jpgMagicNum) { pos = 2; var l = stream.length; while (pos < l) { if (nextByte() != 0xFF) return; var marker = nextByte(); if (marker == 0xDA) break; var size = (nextByte() << 8) | nextByte(); if (marker >= 0xC0 && marker <= 0xCF && !(marker & 0x4) && !(marker & 0x8)) { pos += 1; return { height: (nextByte() << 8) | nextByte(), width: (nextByte() << 8) | nextByte() }; } else { pos += size - 2; } } } }
javascript
{ "resource": "" }
q26218
train
function(editor, pos) { var allowedSyntaxes = {'html': 1, 'xml': 1, 'xsl': 1, 'jsx': 1}; var syntax = editor.getSyntax(); if (syntax in allowedSyntaxes) { var content = editor.getContent(); if (typeof pos === 'undefined') { pos = editor.getCaretPos(); } var tag = htmlMatcher.find(content, pos); if (tag && tag.type == 'tag') { var startTag = tag.open; var contextNode = { name: startTag.name, attributes: [], match: tag }; // parse attributes var tagTree = xmlEditTree.parse(startTag.range.substring(content)); if (tagTree) { contextNode.attributes = tagTree.getAll().map(function(item) { return { name: item.name(), value: item.value() }; }); } return contextNode; } } return null; }
javascript
{ "resource": "" }
q26219
tokener
train
function tokener(value, type) { session.tokens.push({ value: value, type: type || value, start: null, end: null }); }
javascript
{ "resource": "" }
q26220
tokenize
train
function tokenize() { var ch = walker.ch; if (ch === " " || ch === "\t") { return white(); } if (ch === '/') { return comment(); } if (ch === '"' || ch === "'") { return str(); } if (ch === '(') { return brace(); } if (ch === '-' || ch === '.' || isDigit(ch)) { // tricky - char: minus (-1px) or dash (-moz-stuff) return num(); } if (isNameChar(ch)) { return identifier(); } if (isOp(ch)) { return op(); } if (ch === '\r') { if (walker.peek() === '\n') { ch += walker.nextChar(); } tokener(ch, 'line'); walker.nextChar(); return; } if (ch === '\n') { tokener(ch, 'line'); walker.nextChar(); return; } raiseError("Unrecognized character '" + ch + "'"); }
javascript
{ "resource": "" }
q26221
train
function (source) { walker.init(source); session.tokens = []; // for empty source, return single space token if (!source) { session.tokens.push(this.white()); } else { while (walker.ch !== '') { tokenize(); } } var tokens = session.tokens; session.tokens = null; return tokens; }
javascript
{ "resource": "" }
q26222
paragraph
train
function paragraph(lang, wordCount, startWithCommon) { var data = langs[lang]; if (!data) { return ''; } var result = []; var totalWords = 0; var words; wordCount = parseInt(wordCount, 10); if (startWithCommon && data.common) { words = data.common.slice(0, wordCount); if (words.length > 5) { words[4] += ','; } totalWords += words.length; result.push(sentence(words, '.')); } while (totalWords < wordCount) { words = sample(data.words, Math.min(randint(2, 30), wordCount - totalWords)); totalWords += words.length; insertCommas(words); result.push(sentence(words)); } return result.join(' '); }
javascript
{ "resource": "" }
q26223
train
function(lang, data) { if (typeof data === 'string') { data = { words: data.split(' ').filter(function(item) { return !!item; }) }; } else if (Array.isArray(data)) { data = {words: data}; } langs[lang] = data; }
javascript
{ "resource": "" }
q26224
train
function(path, size, callback) { var params = this._parseParams(arguments); this._read(params, function(err, buf) { params.callback(err, err ? '' : bts(buf)); }); }
javascript
{ "resource": "" }
q26225
train
function(editor) { var info = editorUtils.outputInfo(editor); var caretPos = editor.getCaretPos(); var nl = '\n'; var pad = '\t'; if (~xmlSyntaxes.indexOf(info.syntax)) { // let's see if we're breaking newly created tag var tag = htmlMatcher.tag(info.content, caretPos); if (tag && !tag.innerRange.length()) { editor.replaceContent(nl + pad + utils.getCaretPlaceholder() + nl, caretPos); return true; } } else if (info.syntax == 'css') { /** @type String */ var content = info.content; if (caretPos && content.charAt(caretPos - 1) == '{') { var append = prefs.get('css.closeBraceIndentation'); var hasCloseBrace = content.charAt(caretPos) == '}'; if (!hasCloseBrace) { // do we really need special formatting here? // check if this is really a newly created rule, // look ahead for a closing brace for (var i = caretPos, il = content.length, ch; i < il; i++) { ch = content.charAt(i); if (ch == '{') { // ok, this is a new rule without closing brace break; } if (ch == '}') { // not a new rule, just add indentation append = ''; hasCloseBrace = true; break; } } } if (!hasCloseBrace) { append += '}'; } // defining rule set var insValue = nl + pad + utils.getCaretPlaceholder() + append; editor.replaceContent(insValue, caretPos); return true; } } return false; }
javascript
{ "resource": "" }
q26226
EditContainer
train
function EditContainer(source, options) { this.options = utils.extend({offset: 0}, options); /** * Source code of edited structure. All changes in the structure are * immediately reflected into this property */ this.source = source; /** * List of all editable children * @private */ this._children = []; /** * Hash of all positions of container * @private */ this._positions = { name: 0 }; this.initialize.apply(this, arguments); }
javascript
{ "resource": "" }
q26227
train
function(value, start, end) { // create modification range var r = range.create(start, typeof end === 'undefined' ? 0 : end - start); var delta = value.length - r.length(); var update = function(obj) { Object.keys(obj).forEach(function(k) { if (obj[k] >= r.end) { obj[k] += delta; } }); }; // update affected positions of current container update(this._positions); // update affected positions of children var recursiveUpdate = function(items) { items.forEach(function(item) { update(item._positions); if (item.type == 'container') { recursiveUpdate(item.list()); } }); }; recursiveUpdate(this.list()); this.source = utils.replaceSubstring(this.source, value, r); }
javascript
{ "resource": "" }
q26228
train
function(items) { items.forEach(function(item) { update(item._positions); if (item.type == 'container') { recursiveUpdate(item.list()); } }); }
javascript
{ "resource": "" }
q26229
train
function(name, value, pos) { // this is abstract implementation var item = new EditElement(name, value); this._children.push(item); return item; }
javascript
{ "resource": "" }
q26230
train
function(name) { if (typeof name === 'number') { return this.list()[name]; } if (typeof name === 'string') { return utils.find(this.list(), function(prop) { return prop.name() === name; }); } return name; }
javascript
{ "resource": "" }
q26231
train
function(name) { if (!Array.isArray(name)) name = [name]; // split names and indexes var names = [], indexes = []; name.forEach(function(item) { if (typeof item === 'string') { names.push(item); } else if (typeof item === 'number') { indexes.push(item); } }); return this.list().filter(function(attribute, i) { return ~indexes.indexOf(i) || ~names.indexOf(attribute.name()); }); }
javascript
{ "resource": "" }
q26232
train
function(name) { var element = this.get(name); if (element) { this._updateSource('', element.fullRange()); var ix = this._children.indexOf(element); if (~ix) { this._children.splice(ix, 1); } } }
javascript
{ "resource": "" }
q26233
train
function(name, value, pos) { var element = this.get(name); if (element) return element.value(value); if (typeof value !== 'undefined') { // no such element — create it return this.add(name, value, pos); } }
javascript
{ "resource": "" }
q26234
train
function(val) { if (typeof val !== 'undefined' && this._name !== (val = String(val))) { this._updateSource(val, this._positions.name, this._positions.name + this._name.length); this._name = val; } return this._name; }
javascript
{ "resource": "" }
q26235
train
function(pos, isAbsolute) { return utils.find(this.list(), function(elem) { return elem.range(isAbsolute).inside(pos); }); }
javascript
{ "resource": "" }
q26236
train
function(val) { if (typeof val !== 'undefined' && this._value !== (val = String(val))) { this.parent._updateSource(val, this.valueRange()); this._value = val; } return this._value; }
javascript
{ "resource": "" }
q26237
train
function(val) { if (typeof val !== 'undefined' && this._name !== (val = String(val))) { this.parent._updateSource(val, this.nameRange()); this._name = val; } return this._name; }
javascript
{ "resource": "" }
q26238
train
function(colorStop) { colorStop = normalizeSpace(colorStop); // find color declaration // first, try complex color declaration, like rgb(0,0,0) var color = null; colorStop = colorStop.replace(/^(\w+\(.+?\))\s*/, function(str, c) { color = c; return ''; }); if (!color) { // try simple declaration, like yellow, #fco, #ffffff, etc. var parts = colorStop.split(' '); color = parts[0]; colorStop = parts[1] || ''; } var result = { color: color }; if (colorStop) { // there's position in color stop definition colorStop.replace(/^(\-?[\d\.]+)([a-z%]+)?$/, function(str, pos, unit) { result.position = pos; if (~pos.indexOf('.')) { unit = ''; } else if (!unit) { unit = '%'; } if (unit) { result.unit = unit; } }); } return result; }
javascript
{ "resource": "" }
q26239
train
function(colorStops) { var from = 0; colorStops.forEach(function(cs, i) { // make sure that first and last positions are defined if (!i) { return cs.position = cs.position || 0; } if (i == colorStops.length - 1 && !('position' in cs)) { cs.position = 1; } if ('position' in cs) { var start = colorStops[from].position || 0; var step = (cs.position - start) / (i - from); colorStops.slice(from, i).forEach(function(cs2, j) { cs2.position = start + step * j; }); from = i; } }); }
javascript
{ "resource": "" }
q26240
resolveDirection
train
function resolveDirection(dir) { if (typeof dir == 'number') { return dir; } dir = normalizeSpace(dir).toLowerCase(); if (reDeg.test(dir)) { return +RegExp.$1; } var prefix = /^to\s/.test(dir) ? 'to ' : ''; var left = ~dir.indexOf('left') && 'left'; var right = ~dir.indexOf('right') && 'right'; var top = ~dir.indexOf('top') && 'top'; var bottom = ~dir.indexOf('bottom') && 'bottom'; var key = normalizeSpace(prefix + (top || bottom || '') + ' ' + (left || right || '')); return directions[key] || 0; }
javascript
{ "resource": "" }
q26241
stringifyDirection
train
function stringifyDirection(dir, oldStyle) { var reNewStyle = /^to\s/; var keys = Object.keys(directions).filter(function(k) { var hasPrefix = reNewStyle.test(k); return oldStyle ? !hasPrefix : hasPrefix; }); for (var i = 0; i < keys.length; i++) { if (directions[keys[i]] == dir) { return keys[i]; } } if (oldStyle) { dir = (dir + 270) % 360; } return dir + 'deg'; }
javascript
{ "resource": "" }
q26242
train
function(gradient) { // cut out all redundant data if (this.isLinearGradient(gradient)) { gradient = gradient.replace(/^\s*[\-a-z]+\s*\(|\)\s*$/ig, ''); } else { throw 'Invalid linear gradient definition:\n' + gradient; } return new LinearGradient(gradient); }
javascript
{ "resource": "" }
q26243
parseAbbreviation
train
function parseAbbreviation(key, value) { key = utils.trim(key); var m; if ((m = reTag.exec(value))) { return elements.create('element', m[1], m[2], m[4] == '/'); } else { // assume it's reference to another abbreviation return elements.create('reference', value); } }
javascript
{ "resource": "" }
q26244
train
function(data, type) { cache = {}; // sections like "snippets" and "abbreviations" could have // definitions like `"f|fs": "fieldset"` which is the same as distinct // "f" and "fs" keys both equals to "fieldset". // We should parse these definitions first var voc = {}; each(data, function(section, syntax) { var _section = {}; each(section, function(subsection, name) { if (name == 'abbreviations' || name == 'snippets') { subsection = expandSnippetsDefinition(subsection); } _section[name] = subsection; }); voc[syntax] = _section; }); if (type == VOC_SYSTEM) { systemSettings = voc; } else { userSettings = voc; } }
javascript
{ "resource": "" }
q26245
train
function(name, value){ var voc = this.getVocabulary('user') || {}; if (!('variables' in voc)) voc.variables = {}; voc.variables[name] = value; this.setVocabulary(voc, 'user'); }
javascript
{ "resource": "" }
q26246
train
function(name) { if (!name) return null; if (!(name in cache)) { cache[name] = utils.deepMerge({}, systemSettings[name], userSettings[name]); } var data = cache[name], subsections = utils.toArray(arguments, 1), key; while (data && (key = subsections.shift())) { if (key in data) { data = data[key]; } else { return null; } } return data; }
javascript
{ "resource": "" }
q26247
train
function(syntax, name, minScore) { var result = this.fuzzyFindMatches(syntax, name, minScore)[0]; if (result) { return result.value.parsedValue; } }
javascript
{ "resource": "" }
q26248
train
function(syntax) { var cacheKey = 'all-' + syntax; if (!cache[cacheKey]) { var stack = [], sectionKey = syntax; var memo = []; do { var section = this.getSection(sectionKey); if (!section) break; ['snippets', 'abbreviations'].forEach(function(sectionName) { var stackItem = {}; each(section[sectionName] || null, function(v, k) { stackItem[k] = { nk: normalizeName(k), value: v, parsedValue: parseItem(k, v, sectionName), type: sectionName }; }); stack.push(stackItem); }); memo.push(sectionKey); sectionKey = section['extends']; } while (sectionKey && !~memo.indexOf(sectionKey)); cache[cacheKey] = utils.extend.apply(utils, stack.reverse()); } return cache[cacheKey]; }
javascript
{ "resource": "" }
q26249
findAbbreviation
train
function findAbbreviation(editor) { var r = range(editor.getSelectionRange()); var content = String(editor.getContent()); if (r.length()) { // abbreviation is selected by user return r.substring(content); } // search for new abbreviation from current caret position var curLine = editor.getCurrentLineRange(); return actionUtils.extractAbbreviation(content.substring(curLine.start, r.start)); }
javascript
{ "resource": "" }
q26250
train
function(html, caretPos) { var reTag = /^<\/?\w[\w\:\-]*.*?>/; // search left to find opening brace var pos = caretPos; while (pos > -1) { if (html.charAt(pos) == '<') break; pos--; } if (pos != -1) { var m = reTag.exec(html.substring(pos)); if (m && caretPos > pos && caretPos < pos + m[0].length) return true; } return false; }
javascript
{ "resource": "" }
q26251
train
function(editor, syntax, profile) { // most of this code makes sense for Java/Rhino environment // because string that comes from Java are not actually JS string // but Java String object so the have to be explicitly converted // to native string profile = profile || editor.getProfileName(); return { /** @memberOf outputInfo */ syntax: String(syntax || editor.getSyntax()), profile: profile || null, content: String(editor.getContent()) }; }
javascript
{ "resource": "" }
q26252
getReflectedCSSName
train
function getReflectedCSSName(name) { name = cssEditTree.baseName(name); var vendorPrefix = '^(?:\\-\\w+\\-)?', m; if ((name == 'opacity' || name == 'filter') && prefs.get('css.reflect.oldIEOpacity')) { return new RegExp(vendorPrefix + '(?:opacity|filter)$'); } else if ((m = name.match(/^border-radius-(top|bottom)(left|right)/))) { // Mozilla-style border radius return new RegExp(vendorPrefix + '(?:' + name + '|border-' + m[1] + '-' + m[2] + '-radius)$'); } else if ((m = name.match(/^border-(top|bottom)-(left|right)-radius/))) { return new RegExp(vendorPrefix + '(?:' + name + '|border-radius-' + m[1] + m[2] + ')$'); } return new RegExp(vendorPrefix + name + '$'); }
javascript
{ "resource": "" }
q26253
findNewEditPoint
train
function findNewEditPoint(editor, inc, offset) { inc = inc || 1; offset = offset || 0; var curPoint = editor.getCaretPos() + offset; var content = String(editor.getContent()); var maxLen = content.length; var nextPoint = -1; var reEmptyLine = /^\s+$/; function getLine(ix) { var start = ix; while (start >= 0) { var c = content.charAt(start); if (c == '\n' || c == '\r') break; start--; } return content.substring(start, ix); } while (curPoint <= maxLen && curPoint >= 0) { curPoint += inc; var curChar = content.charAt(curPoint); var nextChar = content.charAt(curPoint + 1); var prevChar = content.charAt(curPoint - 1); switch (curChar) { case '"': case '\'': if (nextChar == curChar && prevChar == '=') { // empty attribute nextPoint = curPoint + 1; } break; case '>': if (nextChar == '<') { // between tags nextPoint = curPoint + 1; } break; case '\n': case '\r': // empty line if (reEmptyLine.test(getLine(curPoint - 1))) { nextPoint = curPoint; } break; } if (nextPoint != -1) break; } return nextPoint; }
javascript
{ "resource": "" }
q26254
train
function(editor, syntax, profile) { var curPos = editor.getCaretPos(); var newPoint = findNewEditPoint(editor, -1); if (newPoint == curPos) // we're still in the same point, try searching from the other place newPoint = findNewEditPoint(editor, -1, -2); if (newPoint != -1) { editor.setCaretPos(newPoint); return true; } return false; }
javascript
{ "resource": "" }
q26255
train
function(editor, syntax, profile) { var newPoint = findNewEditPoint(editor, 1); if (newPoint != -1) { editor.setCaretPos(newPoint); return true; } return false; }
javascript
{ "resource": "" }
q26256
makeAttributesString
train
function makeAttributesString(tag, profile) { var attrs = ''; var otherAttrs = []; var attrQuote = profile.attributeQuote(); var cursor = profile.cursor(); tag.attributeList().forEach(function(a) { var attrName = profile.attributeName(a.name); switch (attrName.toLowerCase()) { // use short notation for ID and CLASS attributes case 'id': attrs += '#' + (a.value || cursor); break; case 'class': attrs += '.' + transformClassName(a.value || cursor); break; // process other attributes default: otherAttrs.push({ name: attrName, value: a.value || cursor, isBoolean: profile.isBoolean(a.name, a.value) }); } }); if (otherAttrs.length) { attrs += stringifyAttrs(condenseDataAttrs(otherAttrs), profile); } return attrs; }
javascript
{ "resource": "" }
q26257
updateImageSizeHTML
train
function updateImageSizeHTML(editor) { var offset = editor.getCaretPos(); // find tag from current caret position var info = editorUtils.outputInfo(editor); var xmlElem = xmlEditTree.parseFromPosition(info.content, offset, true); if (xmlElem && (xmlElem.name() || '').toLowerCase() == 'img') { getImageSizeForSource(editor, xmlElem.value('src'), function(size) { if (size) { var compoundData = xmlElem.range(true); xmlElem.value('width', size.width); xmlElem.value('height', size.height, xmlElem.indexOf('width') + 1); actionUtils.compoundUpdate(editor, utils.extend(compoundData, { data: xmlElem.toString(), caret: offset })); } }); } }
javascript
{ "resource": "" }
q26258
getImageSizeForSource
train
function getImageSizeForSource(editor, src, callback) { var fileContent; if (src) { // check if it is data:url if (/^data:/.test(src)) { fileContent = base64.decode( src.replace(/^data\:.+?;.+?,/, '') ); return callback(actionUtils.getImageSize(fileContent)); } var filePath = editor.getFilePath(); file.locateFile(filePath, src, function(absPath) { if (absPath === null) { throw "Can't find " + src + ' file'; } file.read(absPath, function(err, content) { if (err) { throw 'Unable to read ' + absPath + ': ' + err; } content = String(content); callback(actionUtils.getImageSize(content)); }); }); } }
javascript
{ "resource": "" }
q26259
train
function(tree, filters, profileName) { profileName = profile.get(profileName); list(filters).forEach(function(filter) { var name = utils.trim(filter.toLowerCase()); if (name && name in registeredFilters) { tree = registeredFilters[name](tree, profileName); } }); return tree; }
javascript
{ "resource": "" }
q26260
train
function(syntax, profileName, additionalFilters) { profileName = profile.get(profileName); var filters = list(profileName.filters || resources.findItem(syntax, 'filters') || basicFilters); if (profileName.extraFilters) { filters = filters.concat(list(profileName.extraFilters)); } if (additionalFilters) { filters = filters.concat(list(additionalFilters)); } if (!filters || !filters.length) { // looks like unknown syntax, apply basic filters filters = list(basicFilters); } return filters; }
javascript
{ "resource": "" }
q26261
train
function(abbr) { var filters = ''; abbr = abbr.replace(/\|([\w\|\-]+)$/, function(str, p1){ filters = p1; return ''; }); return [abbr, list(filters)]; }
javascript
{ "resource": "" }
q26262
train
function(i) { var key = 'p' + i; if (!(key in memo)) { memo[key] = false; if (text.charAt(i) == '<') { var substr = text.slice(i); if ((m = substr.match(reOpenTag))) { memo[key] = openTag(i, m); } else if ((m = substr.match(reCloseTag))) { memo[key] = closeTag(i, m); } } } return memo[key]; }
javascript
{ "resource": "" }
q26263
findClosingPair
train
function findClosingPair(open, matcher) { var stack = [], tag = null; var text = matcher.text(); for (var pos = open.range.end, len = text.length; pos < len; pos++) { if (matches(text, pos, '<!--')) { // skip to end of comment for (var j = pos; j < len; j++) { if (matches(text, j, '-->')) { pos = j + 3; break; } } } if ((tag = matcher.matches(pos))) { if (tag.type == 'open' && !tag.selfClose) { stack.push(tag.name); } else if (tag.type == 'close') { if (!stack.length) { // found valid pair? return tag.name == open.name ? tag : null; } // check if current closing tag matches previously opened one if (stack[stack.length - 1] == tag.name) { stack.pop(); } else { var found = false; while (stack.length && !found) { var last = stack.pop(); if (last == tag.name) { found = true; } } if (!stack.length && !found) { return tag.name == open.name ? tag : null; } } } pos = tag.range.end - 1; } } }
javascript
{ "resource": "" }
q26264
train
function(child, position) { child = child || new AbbreviationNode(); child.parent = this; if (typeof position === 'undefined') { this.children.push(child); } else { this.children.splice(position, 0, child); } return child; }
javascript
{ "resource": "" }
q26265
train
function() { var node = new AbbreviationNode(); var attrs = ['abbreviation', 'counter', '_name', '_text', 'repeatCount', 'hasImplicitRepeat', 'start', 'end', 'content', 'padding']; attrs.forEach(function(a) { node[a] = this[a]; }, this); // clone attributes node._attributes = this._attributes.map(function(attr) { return utils.extend({}, attr); }); node._data = utils.extend({}, this._data); // clone children node.children = this.children.map(function(child) { child = child.clone(); child.parent = node; return child; }); return node; }
javascript
{ "resource": "" }
q26266
train
function(name, value) { if (arguments.length == 2) { if (value === null) { // remove attribute var vals = this._attributes.filter(function(attr) { return attr.name === name; }); var that = this; vals.forEach(function(attr) { var ix = that._attributes.indexOf(attr); if (~ix) { that._attributes.splice(ix, 1); } }); return; } // modify attribute var attrNames = this._attributes.map(function(attr) { return attr.name; }); var ix = attrNames.indexOf(name.toLowerCase()); if (~ix) { this._attributes[ix].value = value; } else { this._attributes.push({ name: name, value: value }); } } return (utils.find(this.attributeList(), function(attr) { return attr.name == name; }) || {}).value; }
javascript
{ "resource": "" }
q26267
train
function(abbr) { abbr = abbr || ''; var that = this; // find multiplier abbr = abbr.replace(/\*(\d+)?$/, function(str, repeatCount) { that._setRepeat(repeatCount); return ''; }); this.abbreviation = abbr; var abbrText = extractText(abbr); if (abbrText) { abbr = abbrText.element; this.content = this._text = abbrText.text; } var abbrAttrs = parseAttributes(abbr); if (abbrAttrs) { abbr = abbrAttrs.element; this._attributes = abbrAttrs.attributes; } this._name = abbr; // validate name if (this._name && !reValidName.test(this._name)) { throw new Error('Invalid abbreviation'); } }
javascript
{ "resource": "" }
q26268
train
function() { var start = this.start; var end = this.end; var content = this.content; // apply output processors var node = this; outputProcessors.forEach(function(fn) { start = fn(start, node, 'start'); content = fn(content, node, 'content'); end = fn(end, node, 'end'); }); var innerContent = this.children.map(function(child) { return child.valueOf(); }).join(''); content = abbreviationUtils.insertChildContent(content, innerContent, { keepVariable: false }); return start + utils.padString(content, this.padding) + end; }
javascript
{ "resource": "" }
q26269
train
function() { if (!this.children.length) return null; var deepestChild = this; while (deepestChild.children.length) { deepestChild = deepestChild.children[deepestChild.children.length - 1]; } return deepestChild; }
javascript
{ "resource": "" }
q26270
splitAttributes
train
function splitAttributes(attrSet) { attrSet = utils.trim(attrSet); var parts = []; // split attribute set by spaces var stream = stringStream(attrSet), ch; while ((ch = stream.next())) { if (ch == ' ') { parts.push(utils.trim(stream.current())); // skip spaces while (stream.peek() == ' ') { stream.next(); } stream.start = stream.pos; } else if (ch == '"' || ch == "'") { // skip values in strings if (!stream.skipString(ch)) { throw new Error('Invalid attribute set'); } } } parts.push(utils.trim(stream.current())); return parts; }
javascript
{ "resource": "" }
q26271
unquote
train
function unquote(str) { var ch = str.charAt(0); if (ch == '"' || ch == "'") { str = str.substr(1); var last = str.charAt(str.length - 1); if (last === ch) { str = str.substr(0, str.length - 1); } } return str; }
javascript
{ "resource": "" }
q26272
train
function(abbr, options) { if (!abbr) return ''; if (typeof options == 'string') { throw new Error('Deprecated use of `expand` method: `options` must be object'); } options = options || {}; if (!options.syntax) { options.syntax = utils.defaultSyntax(); } var p = profile.get(options.profile, options.syntax); tabStops.resetTabstopIndex(); var data = filters.extract(abbr); var outputTree = this.parse(data[0], options); var filtersList = filters.composeList(options.syntax, p, data[1]); filters.apply(outputTree, filtersList, p); return outputTree.valueOf(); }
javascript
{ "resource": "" }
q26273
findItem
train
function findItem(editor, isBackward, extractFn, rangeFn) { var content = editorUtils.outputInfo(editor).content; var contentLength = content.length; var itemRange, rng; /** @type Range */ var prevRange = range(-1, 0); /** @type Range */ var sel = range(editor.getSelectionRange()); var searchPos = sel.start, loop = 100000; // endless loop protection while (searchPos >= 0 && searchPos < contentLength && --loop > 0) { if ( (itemRange = extractFn(content, searchPos, isBackward)) ) { if (prevRange.equal(itemRange)) { break; } prevRange = itemRange.clone(); rng = rangeFn(itemRange.substring(content), itemRange.start, sel.clone()); if (rng) { editor.createSelection(rng.start, rng.end); return true; } else { searchPos = isBackward ? itemRange.start : itemRange.end - 1; } } searchPos += isBackward ? -1 : 1; } return false; }
javascript
{ "resource": "" }
q26274
findNextHTMLItem
train
function findNextHTMLItem(editor) { var isFirst = true; return findItem(editor, false, function(content, searchPos){ if (isFirst) { isFirst = false; return findOpeningTagFromPosition(content, searchPos); } else { return getOpeningTagFromPosition(content, searchPos); } }, function(tag, offset, selRange) { return getRangeForHTMLItem(tag, offset, selRange, false); }); }
javascript
{ "resource": "" }
q26275
findPrevHTMLItem
train
function findPrevHTMLItem(editor) { return findItem(editor, true, getOpeningTagFromPosition, function (tag, offset, selRange) { return getRangeForHTMLItem(tag, offset, selRange, true); }); }
javascript
{ "resource": "" }
q26276
makePossibleRangesHTML
train
function makePossibleRangesHTML(source, tokens, offset) { offset = offset || 0; var result = []; var attrStart = -1, attrName = '', attrValue = '', attrValueRange, tagName; tokens.forEach(function(tok) { switch (tok.type) { case 'tag': tagName = source.substring(tok.start, tok.end); if (/^<[\w\:\-]/.test(tagName)) { // add tag name result.push(range({ start: tok.start + 1, end: tok.end })); } break; case 'attribute': attrStart = tok.start; attrName = source.substring(tok.start, tok.end); break; case 'string': // attribute value // push full attribute first result.push(range(attrStart, tok.end - attrStart)); attrValueRange = range(tok); attrValue = attrValueRange.substring(source); // is this a quoted attribute? if (isQuote(attrValue.charAt(0))) attrValueRange.start++; if (isQuote(attrValue.charAt(attrValue.length - 1))) attrValueRange.end--; result.push(attrValueRange); if (attrName == 'class') { result = result.concat(classNameRanges(attrValueRange.substring(source), attrValueRange.start)); } break; } }); // offset ranges result = result.filter(function(item) { if (item.length()) { item.shift(offset); return true; } }); // remove duplicates return utils.unique(result, function(item) { return item.toString(); }); }
javascript
{ "resource": "" }
q26277
getRangeForHTMLItem
train
function getRangeForHTMLItem(tag, offset, selRange, isBackward) { var ranges = makePossibleRangesHTML(tag, xmlParser.parse(tag), offset); if (isBackward) ranges.reverse(); // try to find selected range var curRange = utils.find(ranges, function(r) { return r.equal(selRange); }); if (curRange) { var ix = ranges.indexOf(curRange); if (ix < ranges.length - 1) return ranges[ix + 1]; return null; } // no selected range, find nearest one if (isBackward) // search backward return utils.find(ranges, function(r) { return r.start < selRange.start; }); // search forward // to deal with overlapping ranges (like full attribute definition // and attribute value) let's find range under caret first if (!curRange) { var matchedRanges = ranges.filter(function(r) { return r.inside(selRange.end); }); if (matchedRanges.length > 1) return matchedRanges[1]; } return utils.find(ranges, function(r) { return r.end > selRange.end; }); }
javascript
{ "resource": "" }
q26278
findOpeningTagFromPosition
train
function findOpeningTagFromPosition(html, pos) { var tag; while (pos >= 0) { if ((tag = getOpeningTagFromPosition(html, pos))) return tag; pos--; } return null; }
javascript
{ "resource": "" }
q26279
findInnerRanges
train
function findInnerRanges(rule) { // rule selector var ranges = [rule.nameRange(true)]; // find nested sections, keep selectors only var nestedSections = cssSections.nestedSectionsInRule(rule); nestedSections.forEach(function(section) { ranges.push(range.create2(section.start, section._selectorEnd)); }); // add full property ranges and values rule.list().forEach(function(property) { ranges = ranges.concat(makePossibleRangesCSS(property)); }); ranges = range.sort(ranges); // optimize result: remove empty ranges and duplicates ranges = ranges.filter(function(item) { return !!item.length(); }); return utils.unique(ranges, function(item) { return item.toString(); }); }
javascript
{ "resource": "" }
q26280
matchedRangeForCSSProperty
train
function matchedRangeForCSSProperty(rule, selRange, isBackward) { var ranges = findInnerRanges(rule); if (isBackward) { ranges.reverse(); } // return next to selected range, if possible var r = utils.find(ranges, function(item) { return item.equal(selRange); }); if (r) { return ranges[ranges.indexOf(r) + 1]; } // find matched and (possibly) overlapping ranges var nested = ranges.filter(function(item) { return item.inside(selRange.end); }); if (nested.length) { return nested.sort(function(a, b) { return a.length() - b.length(); })[0]; } // return range next to caret var test = r = utils.find(ranges, isBackward ? function(item) {return item.end < selRange.start;} : function(item) {return item.end > selRange.start;} ); if (!r) { // can’t find anything, just pick first one r = ranges[0]; } return r; }
javascript
{ "resource": "" }
q26281
train
function(editor, abbr) { abbr = abbr || editor.prompt("Enter abbreviation"); if (!abbr) { return false; } var content = editor.getContent(); var ctx = actionUtils.captureContext(editor); var tag = this.getUpdatedTag(abbr, ctx, content); if (!tag) { // nothing to update return false; } // check if tag name was updated if (tag.name() != ctx.name && ctx.match.close) { editor.replaceContent('</' + tag.name() + '>', ctx.match.close.range.start, ctx.match.close.range.end, true); } editor.replaceContent(tag.source, ctx.match.open.range.start, ctx.match.open.range.end, true); return true; }
javascript
{ "resource": "" }
q26282
train
function(abbr, ctx, content, options) { if (!ctx) { // nothing to update return null; } var tree = parser.parse(abbr, options || {}); // for this action some characters in abbreviation has special // meaning. For example, `.-c2` means “remove `c2` class from // element” and `.+c3` means “append class `c3` to exising one. // // But `.+c3` abbreviation will actually produce two elements: // <div class=""> and <c3>. Thus, we have to walk on each element // of parsed tree and use their definitions to update current element var tag = xmlEditTree.parse(ctx.match.open.range.substring(content), { offset: ctx.match.outerRange.start }); tree.children.forEach(function(node, i) { updateAttributes(tag, node, i); }); // if tag name was resolved by implicit tag name resolver, // then user omitted it in abbreviation and wants to keep // original tag name var el = tree.children[0]; if (!el.data('nameResolved')) { tag.name(el.name()); } return tag; }
javascript
{ "resource": "" }
q26283
encodeToBase64
train
function encodeToBase64(editor, imgPath, pos) { var editorFile = editor.getFilePath(); var defaultMimeType = 'application/octet-stream'; if (editorFile === null) { throw "You should save your file before using this action"; } // locate real image path file.locateFile(editorFile, imgPath, function(realImgPath) { if (realImgPath === null) { throw "Can't find " + imgPath + ' file'; } file.read(realImgPath, function(err, content) { if (err) { throw 'Unable to read ' + realImgPath + ': ' + err; } var b64 = base64.encode(String(content)); if (!b64) { throw "Can't encode file content to base64"; } b64 = 'data:' + (actionUtils.mimeTypes[String(file.getExt(realImgPath))] || defaultMimeType) + ';base64,' + b64; editor.replaceContent('$0' + b64, pos, pos + imgPath.length); }); }); return true; }
javascript
{ "resource": "" }
q26284
decodeFromBase64
train
function decodeFromBase64(editor, filePath, data, pos) { // ask user to enter path to file filePath = filePath || String(editor.prompt('Enter path to file (absolute or relative)')); if (!filePath) { return false; } var editorFile = editor.getFilePath(); file.createPath(editorFile, filePath, function(err, absPath) { if (err || !absPath) { throw "Can't save file"; } var content = data.replace(/^data\:.+?;.+?,/, ''); file.save(absPath, base64.decode(content), function(err) { if (err) { throw 'Unable to save ' + absPath + ': ' + err; } editor.replaceContent('$0' + filePath, pos, pos + data.length); }); }); return true; }
javascript
{ "resource": "" }
q26285
getCSSRanges
train
function getCSSRanges(content, pos) { var rule; if (typeof content === 'string') { var ruleRange = cssSections.matchEnclosingRule(content, pos); if (ruleRange) { rule = cssEditTree.parse(ruleRange.substring(content), { offset: ruleRange.start }); } } else { // passed parsed CSS rule rule = content; } if (!rule) { return null; } // find all possible ranges var ranges = rangesForCSSRule(rule, pos); // remove empty ranges ranges = ranges.filter(function(item) { return !!item.length; }); return utils.unique(ranges, function(item) { return item.valueOf(); }); }
javascript
{ "resource": "" }
q26286
train
function(editor, direction) { direction = String((direction || 'out').toLowerCase()); var info = editorUtils.outputInfo(editor); if (actionUtils.isSupportedCSS(info.syntax)) { return balanceCSS(editor, direction); } return balanceHTML(editor, direction); }
javascript
{ "resource": "" }
q26287
getGradientPrefixes
train
function getGradientPrefixes(type) { var prefixes = cssResolver.vendorPrefixes(type); if (!prefixes) { // disabled Can I Use, fallback to property list prefixes = prefs.getArray('css.gradient.prefixes'); } return prefixes || []; }
javascript
{ "resource": "" }
q26288
getPropertiesForGradient
train
function getPropertiesForGradient(gradients, property) { var props = []; var propertyName = property.name(); var omitDir = prefs.get('css.gradient.omitDefaultDirection'); if (prefs.get('css.gradient.fallback') && ~propertyName.toLowerCase().indexOf('background')) { props.push({ name: 'background-color', value: '${1:' + gradients[0].gradient.colorStops[0].color + '}' }); } var value = property.value(); getGradientPrefixes('linear-gradient').forEach(function(prefix) { var name = cssResolver.prefixed(propertyName, prefix); if (prefix == 'webkit' && prefs.get('css.gradient.oldWebkit')) { try { props.push({ name: name, value: insertGradientsIntoCSSValue(gradients, value, { prefix: prefix, oldWebkit: true, omitDefaultDirection: omitDir }) }); } catch(e) {} } props.push({ name: name, value: insertGradientsIntoCSSValue(gradients, value, { prefix: prefix, omitDefaultDirection: omitDir }) }); }); return props.sort(function(a, b) { return b.name.length - a.name.length; }); }
javascript
{ "resource": "" }
q26289
insertGradientsIntoCSSValue
train
function insertGradientsIntoCSSValue(gradients, value, options) { // gradients *should* passed in order they actually appear in CSS property // iterate over it in backward direction to preserve gradient locations options = options || {}; gradients = utils.clone(gradients); gradients.reverse().forEach(function(item, i) { var suffix = !i && options.placeholder ? options.placeholder : ''; var str = options.oldWebkit ? item.gradient.stringifyOldWebkit(options) : item.gradient.stringify(options); value = utils.replaceSubstring(value, str + suffix, item.matchedPart); }); return value; }
javascript
{ "resource": "" }
q26290
pasteGradient
train
function pasteGradient(property, gradients) { var rule = property.parent; var alignVendor = prefs.get('css.alignVendor'); var omitDir = prefs.get('css.gradient.omitDefaultDirection'); // we may have aligned gradient definitions: find the smallest value // separator var sep = property.styleSeparator; var before = property.styleBefore; // first, remove all properties within CSS rule with the same name and // gradient definition rule.getAll(similarPropertyNames(property)).forEach(function(item) { if (item != property && /gradient/i.test(item.value())) { if (item.styleSeparator.length < sep.length) { sep = item.styleSeparator; } if (item.styleBefore.length < before.length) { before = item.styleBefore; } rule.remove(item); } }); if (alignVendor) { // update prefix if (before != property.styleBefore) { var fullRange = property.fullRange(); rule._updateSource(before, fullRange.start, fullRange.start + property.styleBefore.length); property.styleBefore = before; } // update separator value if (sep != property.styleSeparator) { rule._updateSource(sep, property.nameRange().end, property.valueRange().start); property.styleSeparator = sep; } } var value = property.value(); // create list of properties to insert var propsToInsert = getPropertiesForGradient(gradients, property); // align prefixed values if (alignVendor) { var names = [], values = []; propsToInsert.forEach(function(item) { names.push(item.name); values.push(item.value); }); values.push(property.value()); names.push(property.name()); var valuePads = utils.getStringsPads(values.map(function(v) { return v.substring(0, v.indexOf('(')); })); var namePads = utils.getStringsPads(names); property.name(namePads[namePads.length - 1] + property.name()); propsToInsert.forEach(function(prop, i) { prop.name = namePads[i] + prop.name; prop.value = valuePads[i] + prop.value; }); property.value(valuePads[valuePads.length - 1] + property.value()); } // put vendor-prefixed definitions before current rule propsToInsert.forEach(function(prop) { rule.add(prop.name, prop.value, rule.indexOf(property)); }); // put vanilla-clean gradient definition into current rule property.value(insertGradientsIntoCSSValue(gradients, value, { placeholder: '${2}', omitDefaultDirection: omitDir })); }
javascript
{ "resource": "" }
q26291
train
function(cssProp) { var value = cssProp.value(); var gradients = []; var that = this; cssProp.valueParts().forEach(function(part) { var partValue = part.substring(value); if (linearGradient.isLinearGradient(partValue)) { var gradient = linearGradient.parse(partValue); if (gradient) { gradients.push({ gradient: gradient, matchedPart: part }); } } }); return gradients.length ? gradients : null; }
javascript
{ "resource": "" }
q26292
train
function(editor, syntax) { var propertyName = prefs.get('css.gradient.defaultProperty'); var omitDir = prefs.get('css.gradient.omitDefaultDirection'); if (!propertyName) { return false; } // assuming that gradient definition is written on new line, // do a simplified parsing var content = String(editor.getContent()); /** @type Range */ var lineRange = range.create(editor.getCurrentLineRange()); // get line content and adjust range with padding var line = lineRange.substring(content) .replace(/^\s+/, function(pad) { lineRange.start += pad.length; return ''; }) .replace(/\s+$/, function(pad) { lineRange.end -= pad.length; return ''; }); // trick parser: make it think that we’re parsing actual CSS property var fakeCSS = 'a{' + propertyName + ': ' + line + ';}'; var gradients = this.gradientsFromCSSProperty(fakeCSS, fakeCSS.length - 2); if (gradients) { var props = getPropertiesForGradient(gradients.gradients, gradients.property); props.push({ name: gradients.property.name(), value: insertGradientsIntoCSSValue(gradients.gradients, gradients.property.value(), { placeholder: '${2}', omitDefaultDirection: omitDir }) }); var sep = cssResolver.getSyntaxPreference('valueSeparator', syntax); var end = cssResolver.getSyntaxPreference('propertyEnd', syntax); if (prefs.get('css.alignVendor')) { var pads = utils.getStringsPads(props.map(function(prop) { return prop.value.substring(0, prop.value.indexOf('(')); })); props.forEach(function(prop, i) { prop.value = pads[i] + prop.value; }); } props = props.map(function(item) { return item.name + sep + item.value + end; }); editor.replaceContent(props.join('\n'), lineRange.start, lineRange.end); return true; } return false; }
javascript
{ "resource": "" }
q26293
train
function(fn, options) { // TODO hack for stable sort, remove after fixing `list()` var order = this._list.length; if (options && 'order' in options) { order = options.order * 10000; } this._list.push(utils.extend({}, options, {order: order, fn: fn})); }
javascript
{ "resource": "" }
q26294
train
function(fn) { var item = utils.find(this._list, function(item) { return item.fn === fn; }); if (item) { this._list.splice(this._list.indexOf(item), 1); } }
javascript
{ "resource": "" }
q26295
getFileName
train
function getFileName(path) { var re = /([\w\.\-]+)$/i; var m = re.exec(path); return m ? m[1] : ''; }
javascript
{ "resource": "" }
q26296
train
function(abbr, syntax, profile, contextNode) { return parser.expand(abbr, { syntax: syntax, profile: profile, contextNode: contextNode }); }
javascript
{ "resource": "" }
q26297
train
function(profiles) { profiles = utils.parseJSON(profiles); var snippets = {}; Object.keys(profiles).forEach(function(syntax) { var options = profiles[syntax]; if (!(syntax in snippets)) { snippets[syntax] = {}; } snippets[syntax].profile = normalizeProfile(options); }); this.loadSnippets(snippets); }
javascript
{ "resource": "" }
q26298
train
function(profiles) { profiles = utils.parseJSON(profiles); Object.keys(profiles).forEach(function(name) { profile.create(name, normalizeProfile(profiles[name])); }); }
javascript
{ "resource": "" }
q26299
train
function(node) { return (this.hasTagsInContent(node) && this.isBlock(node)) || node.children.some(function(child) { return this.isBlock(child); }, this); }
javascript
{ "resource": "" }