repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
adobe/brackets
|
src/preferences/PreferencesDialogs.js
|
_validateBaseUrl
|
function _validateBaseUrl(url) {
var result = "";
// Empty url means "no server mapping; use file directly"
if (url === "") {
return result;
}
var obj = PathUtils.parseUrl(url);
if (!obj) {
result = Strings.BASEURL_ERROR_UNKNOWN_ERROR;
} else if (obj.href.search(/^(http|https):\/\//i) !== 0) {
result = StringUtils.format(Strings.BASEURL_ERROR_INVALID_PROTOCOL, obj.href.substring(0, obj.href.indexOf("//")));
} else if (obj.search !== "") {
result = StringUtils.format(Strings.BASEURL_ERROR_SEARCH_DISALLOWED, obj.search);
} else if (obj.hash !== "") {
result = StringUtils.format(Strings.BASEURL_ERROR_HASH_DISALLOWED, obj.hash);
} else {
var index = url.search(/[ \^\[\]\{\}<>\\"\?]+/);
if (index !== -1) {
result = StringUtils.format(Strings.BASEURL_ERROR_INVALID_CHAR, url[index]);
}
}
return result;
}
|
javascript
|
function _validateBaseUrl(url) {
var result = "";
// Empty url means "no server mapping; use file directly"
if (url === "") {
return result;
}
var obj = PathUtils.parseUrl(url);
if (!obj) {
result = Strings.BASEURL_ERROR_UNKNOWN_ERROR;
} else if (obj.href.search(/^(http|https):\/\//i) !== 0) {
result = StringUtils.format(Strings.BASEURL_ERROR_INVALID_PROTOCOL, obj.href.substring(0, obj.href.indexOf("//")));
} else if (obj.search !== "") {
result = StringUtils.format(Strings.BASEURL_ERROR_SEARCH_DISALLOWED, obj.search);
} else if (obj.hash !== "") {
result = StringUtils.format(Strings.BASEURL_ERROR_HASH_DISALLOWED, obj.hash);
} else {
var index = url.search(/[ \^\[\]\{\}<>\\"\?]+/);
if (index !== -1) {
result = StringUtils.format(Strings.BASEURL_ERROR_INVALID_CHAR, url[index]);
}
}
return result;
}
|
[
"function",
"_validateBaseUrl",
"(",
"url",
")",
"{",
"var",
"result",
"=",
"\"\"",
";",
"if",
"(",
"url",
"===",
"\"\"",
")",
"{",
"return",
"result",
";",
"}",
"var",
"obj",
"=",
"PathUtils",
".",
"parseUrl",
"(",
"url",
")",
";",
"if",
"(",
"!",
"obj",
")",
"{",
"result",
"=",
"Strings",
".",
"BASEURL_ERROR_UNKNOWN_ERROR",
";",
"}",
"else",
"if",
"(",
"obj",
".",
"href",
".",
"search",
"(",
"/",
"^(http|https):\\/\\/",
"/",
"i",
")",
"!==",
"0",
")",
"{",
"result",
"=",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"BASEURL_ERROR_INVALID_PROTOCOL",
",",
"obj",
".",
"href",
".",
"substring",
"(",
"0",
",",
"obj",
".",
"href",
".",
"indexOf",
"(",
"\"//\"",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"obj",
".",
"search",
"!==",
"\"\"",
")",
"{",
"result",
"=",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"BASEURL_ERROR_SEARCH_DISALLOWED",
",",
"obj",
".",
"search",
")",
";",
"}",
"else",
"if",
"(",
"obj",
".",
"hash",
"!==",
"\"\"",
")",
"{",
"result",
"=",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"BASEURL_ERROR_HASH_DISALLOWED",
",",
"obj",
".",
"hash",
")",
";",
"}",
"else",
"{",
"var",
"index",
"=",
"url",
".",
"search",
"(",
"/",
"[ \\^\\[\\]\\{\\}<>\\\\\"\\?]+",
"/",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"result",
"=",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"BASEURL_ERROR_INVALID_CHAR",
",",
"url",
"[",
"index",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Validate that text string is a valid base url which should map to a server folder
@param {string} url
@return {string} Empty string if valid, otherwise error string
|
[
"Validate",
"that",
"text",
"string",
"is",
"a",
"valid",
"base",
"url",
"which",
"should",
"map",
"to",
"a",
"server",
"folder"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesDialogs.js#L45-L69
|
train
|
adobe/brackets
|
src/preferences/PreferencesDialogs.js
|
showProjectPreferencesDialog
|
function showProjectPreferencesDialog(baseUrl, errorMessage) {
var $baseUrlControl,
dialog;
// Title
var projectName = "",
projectRoot = ProjectManager.getProjectRoot(),
title;
if (projectRoot) {
projectName = projectRoot.name;
}
title = StringUtils.format(Strings.PROJECT_SETTINGS_TITLE, projectName);
var templateVars = {
title : title,
baseUrl : baseUrl,
errorMessage : errorMessage,
Strings : Strings
};
dialog = Dialogs.showModalDialogUsingTemplate(Mustache.render(SettingsDialogTemplate, templateVars));
dialog.done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK) {
var baseUrlValue = $baseUrlControl.val();
var result = _validateBaseUrl(baseUrlValue);
if (result === "") {
// Send analytics data when url is set in project settings
HealthLogger.sendAnalyticsData(
"projectSettingsLivepreview",
"usage",
"projectSettings",
"use"
);
ProjectManager.setBaseUrl(baseUrlValue);
} else {
// Re-invoke dialog with result (error message)
showProjectPreferencesDialog(baseUrlValue, result);
}
}
});
// Give focus to first control
$baseUrlControl = dialog.getElement().find(".url");
$baseUrlControl.focus();
return dialog;
}
|
javascript
|
function showProjectPreferencesDialog(baseUrl, errorMessage) {
var $baseUrlControl,
dialog;
// Title
var projectName = "",
projectRoot = ProjectManager.getProjectRoot(),
title;
if (projectRoot) {
projectName = projectRoot.name;
}
title = StringUtils.format(Strings.PROJECT_SETTINGS_TITLE, projectName);
var templateVars = {
title : title,
baseUrl : baseUrl,
errorMessage : errorMessage,
Strings : Strings
};
dialog = Dialogs.showModalDialogUsingTemplate(Mustache.render(SettingsDialogTemplate, templateVars));
dialog.done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK) {
var baseUrlValue = $baseUrlControl.val();
var result = _validateBaseUrl(baseUrlValue);
if (result === "") {
// Send analytics data when url is set in project settings
HealthLogger.sendAnalyticsData(
"projectSettingsLivepreview",
"usage",
"projectSettings",
"use"
);
ProjectManager.setBaseUrl(baseUrlValue);
} else {
// Re-invoke dialog with result (error message)
showProjectPreferencesDialog(baseUrlValue, result);
}
}
});
// Give focus to first control
$baseUrlControl = dialog.getElement().find(".url");
$baseUrlControl.focus();
return dialog;
}
|
[
"function",
"showProjectPreferencesDialog",
"(",
"baseUrl",
",",
"errorMessage",
")",
"{",
"var",
"$baseUrlControl",
",",
"dialog",
";",
"var",
"projectName",
"=",
"\"\"",
",",
"projectRoot",
"=",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
",",
"title",
";",
"if",
"(",
"projectRoot",
")",
"{",
"projectName",
"=",
"projectRoot",
".",
"name",
";",
"}",
"title",
"=",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"PROJECT_SETTINGS_TITLE",
",",
"projectName",
")",
";",
"var",
"templateVars",
"=",
"{",
"title",
":",
"title",
",",
"baseUrl",
":",
"baseUrl",
",",
"errorMessage",
":",
"errorMessage",
",",
"Strings",
":",
"Strings",
"}",
";",
"dialog",
"=",
"Dialogs",
".",
"showModalDialogUsingTemplate",
"(",
"Mustache",
".",
"render",
"(",
"SettingsDialogTemplate",
",",
"templateVars",
")",
")",
";",
"dialog",
".",
"done",
"(",
"function",
"(",
"id",
")",
"{",
"if",
"(",
"id",
"===",
"Dialogs",
".",
"DIALOG_BTN_OK",
")",
"{",
"var",
"baseUrlValue",
"=",
"$baseUrlControl",
".",
"val",
"(",
")",
";",
"var",
"result",
"=",
"_validateBaseUrl",
"(",
"baseUrlValue",
")",
";",
"if",
"(",
"result",
"===",
"\"\"",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"\"projectSettingsLivepreview\"",
",",
"\"usage\"",
",",
"\"projectSettings\"",
",",
"\"use\"",
")",
";",
"ProjectManager",
".",
"setBaseUrl",
"(",
"baseUrlValue",
")",
";",
"}",
"else",
"{",
"showProjectPreferencesDialog",
"(",
"baseUrlValue",
",",
"result",
")",
";",
"}",
"}",
"}",
")",
";",
"$baseUrlControl",
"=",
"dialog",
".",
"getElement",
"(",
")",
".",
"find",
"(",
"\".url\"",
")",
";",
"$baseUrlControl",
".",
"focus",
"(",
")",
";",
"return",
"dialog",
";",
"}"
] |
Show a dialog that shows the project preferences
@param {string} baseUrl Initial value
@param {string} errorMessage Error to display
@return {Dialog} A Dialog object with an internal promise that will be resolved with the ID
of the clicked button when the dialog is dismissed. Never rejected.
|
[
"Show",
"a",
"dialog",
"that",
"shows",
"the",
"project",
"preferences"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesDialogs.js#L78-L125
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
_validEvent
|
function _validEvent(event) {
if (window.navigator.platform.substr(0, 3) === "Mac") {
// Mac
return event.metaKey;
} else {
// Windows
return event.ctrlKey;
}
}
|
javascript
|
function _validEvent(event) {
if (window.navigator.platform.substr(0, 3) === "Mac") {
// Mac
return event.metaKey;
} else {
// Windows
return event.ctrlKey;
}
}
|
[
"function",
"_validEvent",
"(",
"event",
")",
"{",
"if",
"(",
"window",
".",
"navigator",
".",
"platform",
".",
"substr",
"(",
"0",
",",
"3",
")",
"===",
"\"Mac\"",
")",
"{",
"return",
"event",
".",
"metaKey",
";",
"}",
"else",
"{",
"return",
"event",
".",
"ctrlKey",
";",
"}",
"}"
] |
Keep alive timeout value, in milliseconds determine whether an event should be processed for Live Development
|
[
"Keep",
"alive",
"timeout",
"value",
"in",
"milliseconds",
"determine",
"whether",
"an",
"event",
"should",
"be",
"processed",
"for",
"Live",
"Development"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L66-L74
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
_screenOffset
|
function _screenOffset(element) {
var elemBounds = element.getBoundingClientRect(),
body = window.document.body,
offsetTop,
offsetLeft;
if (window.getComputedStyle(body).position === "static") {
offsetLeft = elemBounds.left + window.pageXOffset;
offsetTop = elemBounds.top + window.pageYOffset;
} else {
var bodyBounds = body.getBoundingClientRect();
offsetLeft = elemBounds.left - bodyBounds.left;
offsetTop = elemBounds.top - bodyBounds.top;
}
return { left: offsetLeft, top: offsetTop };
}
|
javascript
|
function _screenOffset(element) {
var elemBounds = element.getBoundingClientRect(),
body = window.document.body,
offsetTop,
offsetLeft;
if (window.getComputedStyle(body).position === "static") {
offsetLeft = elemBounds.left + window.pageXOffset;
offsetTop = elemBounds.top + window.pageYOffset;
} else {
var bodyBounds = body.getBoundingClientRect();
offsetLeft = elemBounds.left - bodyBounds.left;
offsetTop = elemBounds.top - bodyBounds.top;
}
return { left: offsetLeft, top: offsetTop };
}
|
[
"function",
"_screenOffset",
"(",
"element",
")",
"{",
"var",
"elemBounds",
"=",
"element",
".",
"getBoundingClientRect",
"(",
")",
",",
"body",
"=",
"window",
".",
"document",
".",
"body",
",",
"offsetTop",
",",
"offsetLeft",
";",
"if",
"(",
"window",
".",
"getComputedStyle",
"(",
"body",
")",
".",
"position",
"===",
"\"static\"",
")",
"{",
"offsetLeft",
"=",
"elemBounds",
".",
"left",
"+",
"window",
".",
"pageXOffset",
";",
"offsetTop",
"=",
"elemBounds",
".",
"top",
"+",
"window",
".",
"pageYOffset",
";",
"}",
"else",
"{",
"var",
"bodyBounds",
"=",
"body",
".",
"getBoundingClientRect",
"(",
")",
";",
"offsetLeft",
"=",
"elemBounds",
".",
"left",
"-",
"bodyBounds",
".",
"left",
";",
"offsetTop",
"=",
"elemBounds",
".",
"top",
"-",
"bodyBounds",
".",
"top",
";",
"}",
"return",
"{",
"left",
":",
"offsetLeft",
",",
"top",
":",
"offsetTop",
"}",
";",
"}"
] |
compute the screen offset of an element
|
[
"compute",
"the",
"screen",
"offset",
"of",
"an",
"element"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L91-L106
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
_trigger
|
function _trigger(element, name, value, autoRemove) {
var key = "data-ld-" + name;
if (value !== undefined && value !== null) {
element.setAttribute(key, value);
if (autoRemove) {
window.setTimeout(element.removeAttribute.bind(element, key));
}
} else {
element.removeAttribute(key);
}
}
|
javascript
|
function _trigger(element, name, value, autoRemove) {
var key = "data-ld-" + name;
if (value !== undefined && value !== null) {
element.setAttribute(key, value);
if (autoRemove) {
window.setTimeout(element.removeAttribute.bind(element, key));
}
} else {
element.removeAttribute(key);
}
}
|
[
"function",
"_trigger",
"(",
"element",
",",
"name",
",",
"value",
",",
"autoRemove",
")",
"{",
"var",
"key",
"=",
"\"data-ld-\"",
"+",
"name",
";",
"if",
"(",
"value",
"!==",
"undefined",
"&&",
"value",
"!==",
"null",
")",
"{",
"element",
".",
"setAttribute",
"(",
"key",
",",
"value",
")",
";",
"if",
"(",
"autoRemove",
")",
"{",
"window",
".",
"setTimeout",
"(",
"element",
".",
"removeAttribute",
".",
"bind",
"(",
"element",
",",
"key",
")",
")",
";",
"}",
"}",
"else",
"{",
"element",
".",
"removeAttribute",
"(",
"key",
")",
";",
"}",
"}"
] |
set an event on a element
|
[
"set",
"an",
"event",
"on",
"a",
"element"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L109-L119
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
isInViewport
|
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = window.document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
}
|
javascript
|
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = window.document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
}
|
[
"function",
"isInViewport",
"(",
"element",
")",
"{",
"var",
"rect",
"=",
"element",
".",
"getBoundingClientRect",
"(",
")",
";",
"var",
"html",
"=",
"window",
".",
"document",
".",
"documentElement",
";",
"return",
"(",
"rect",
".",
"top",
">=",
"0",
"&&",
"rect",
".",
"left",
">=",
"0",
"&&",
"rect",
".",
"bottom",
"<=",
"(",
"window",
".",
"innerHeight",
"||",
"html",
".",
"clientHeight",
")",
"&&",
"rect",
".",
"right",
"<=",
"(",
"window",
".",
"innerWidth",
"||",
"html",
".",
"clientWidth",
")",
")",
";",
"}"
] |
Checks if the element is in Viewport in the client browser
|
[
"Checks",
"if",
"the",
"element",
"is",
"in",
"Viewport",
"in",
"the",
"client",
"browser"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L122-L131
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
Menu
|
function Menu(element) {
this.element = element;
_trigger(this.element, "showgoto", 1, true);
window.setTimeout(window.remoteShowGoto);
this.remove = this.remove.bind(this);
}
|
javascript
|
function Menu(element) {
this.element = element;
_trigger(this.element, "showgoto", 1, true);
window.setTimeout(window.remoteShowGoto);
this.remove = this.remove.bind(this);
}
|
[
"function",
"Menu",
"(",
"element",
")",
"{",
"this",
".",
"element",
"=",
"element",
";",
"_trigger",
"(",
"this",
".",
"element",
",",
"\"showgoto\"",
",",
"1",
",",
"true",
")",
";",
"window",
".",
"setTimeout",
"(",
"window",
".",
"remoteShowGoto",
")",
";",
"this",
".",
"remove",
"=",
"this",
".",
"remove",
".",
"bind",
"(",
"this",
")",
";",
"}"
] |
construct the info menu
|
[
"construct",
"the",
"info",
"menu"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L139-L144
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
highlight
|
function highlight(node, clear) {
if (!_remoteHighlight) {
_remoteHighlight = new Highlight("#cfc");
}
if (clear) {
_remoteHighlight.clear();
}
_remoteHighlight.add(node, true);
}
|
javascript
|
function highlight(node, clear) {
if (!_remoteHighlight) {
_remoteHighlight = new Highlight("#cfc");
}
if (clear) {
_remoteHighlight.clear();
}
_remoteHighlight.add(node, true);
}
|
[
"function",
"highlight",
"(",
"node",
",",
"clear",
")",
"{",
"if",
"(",
"!",
"_remoteHighlight",
")",
"{",
"_remoteHighlight",
"=",
"new",
"Highlight",
"(",
"\"#cfc\"",
")",
";",
"}",
"if",
"(",
"clear",
")",
"{",
"_remoteHighlight",
".",
"clear",
"(",
")",
";",
"}",
"_remoteHighlight",
".",
"add",
"(",
"node",
",",
"true",
")",
";",
"}"
] |
highlight a node
|
[
"highlight",
"a",
"node"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L664-L672
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
highlightRule
|
function highlightRule(rule) {
hideHighlight();
var i, nodes = window.document.querySelectorAll(rule);
for (i = 0; i < nodes.length; i++) {
highlight(nodes[i]);
}
_remoteHighlight.selector = rule;
}
|
javascript
|
function highlightRule(rule) {
hideHighlight();
var i, nodes = window.document.querySelectorAll(rule);
for (i = 0; i < nodes.length; i++) {
highlight(nodes[i]);
}
_remoteHighlight.selector = rule;
}
|
[
"function",
"highlightRule",
"(",
"rule",
")",
"{",
"hideHighlight",
"(",
")",
";",
"var",
"i",
",",
"nodes",
"=",
"window",
".",
"document",
".",
"querySelectorAll",
"(",
"rule",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"length",
";",
"i",
"++",
")",
"{",
"highlight",
"(",
"nodes",
"[",
"i",
"]",
")",
";",
"}",
"_remoteHighlight",
".",
"selector",
"=",
"rule",
";",
"}"
] |
highlight a rule
|
[
"highlight",
"a",
"rule"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L675-L682
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/RemoteFunctions.js
|
_scrollHandler
|
function _scrollHandler(e) {
// Document scrolls can be updated immediately. Any other scrolls
// need to be updated on a timer to ensure the layout is correct.
if (e.target === window.document) {
redrawHighlights();
} else {
if (_remoteHighlight || _localHighlight) {
window.setTimeout(redrawHighlights, 0);
}
}
}
|
javascript
|
function _scrollHandler(e) {
// Document scrolls can be updated immediately. Any other scrolls
// need to be updated on a timer to ensure the layout is correct.
if (e.target === window.document) {
redrawHighlights();
} else {
if (_remoteHighlight || _localHighlight) {
window.setTimeout(redrawHighlights, 0);
}
}
}
|
[
"function",
"_scrollHandler",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"target",
"===",
"window",
".",
"document",
")",
"{",
"redrawHighlights",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"_remoteHighlight",
"||",
"_localHighlight",
")",
"{",
"window",
".",
"setTimeout",
"(",
"redrawHighlights",
",",
"0",
")",
";",
"}",
"}",
"}"
] |
Add a capture-phase scroll listener to update highlights when any element scrolls.
|
[
"Add",
"a",
"capture",
"-",
"phase",
"scroll",
"listener",
"to",
"update",
"highlights",
"when",
"any",
"element",
"scrolls",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/RemoteFunctions.js#L695-L705
|
train
|
adobe/brackets
|
src/utils/StringMatch.js
|
findMatchingSpecial
|
function findMatchingSpecial() {
// used to loop through the specials
var i;
for (i = specialsCounter; i < specials.length; i++) {
// short circuit this search when we know there are no matches following
if (specials[i] >= deadBranches[queryCounter]) {
break;
}
// First, ensure that we're not comparing specials that
// come earlier in the string than our current search position.
// This can happen when the string position changes elsewhere.
if (specials[i] < strCounter) {
specialsCounter = i;
} else if (query[queryCounter] === str[specials[i]]) {
// we have a match! do the required tracking
strCounter = specials[i];
// Upper case match check:
// If the query and original string matched, but the original string
// and the lower case version did not, that means that the original
// was upper case.
var upper = originalQuery[queryCounter] === originalStr[strCounter] && originalStr[strCounter] !== str[strCounter];
result.push(new SpecialMatch(strCounter, upper));
specialsCounter = i;
queryCounter++;
strCounter++;
return true;
}
}
return false;
}
|
javascript
|
function findMatchingSpecial() {
// used to loop through the specials
var i;
for (i = specialsCounter; i < specials.length; i++) {
// short circuit this search when we know there are no matches following
if (specials[i] >= deadBranches[queryCounter]) {
break;
}
// First, ensure that we're not comparing specials that
// come earlier in the string than our current search position.
// This can happen when the string position changes elsewhere.
if (specials[i] < strCounter) {
specialsCounter = i;
} else if (query[queryCounter] === str[specials[i]]) {
// we have a match! do the required tracking
strCounter = specials[i];
// Upper case match check:
// If the query and original string matched, but the original string
// and the lower case version did not, that means that the original
// was upper case.
var upper = originalQuery[queryCounter] === originalStr[strCounter] && originalStr[strCounter] !== str[strCounter];
result.push(new SpecialMatch(strCounter, upper));
specialsCounter = i;
queryCounter++;
strCounter++;
return true;
}
}
return false;
}
|
[
"function",
"findMatchingSpecial",
"(",
")",
"{",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"specialsCounter",
";",
"i",
"<",
"specials",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"specials",
"[",
"i",
"]",
">=",
"deadBranches",
"[",
"queryCounter",
"]",
")",
"{",
"break",
";",
"}",
"if",
"(",
"specials",
"[",
"i",
"]",
"<",
"strCounter",
")",
"{",
"specialsCounter",
"=",
"i",
";",
"}",
"else",
"if",
"(",
"query",
"[",
"queryCounter",
"]",
"===",
"str",
"[",
"specials",
"[",
"i",
"]",
"]",
")",
"{",
"strCounter",
"=",
"specials",
"[",
"i",
"]",
";",
"var",
"upper",
"=",
"originalQuery",
"[",
"queryCounter",
"]",
"===",
"originalStr",
"[",
"strCounter",
"]",
"&&",
"originalStr",
"[",
"strCounter",
"]",
"!==",
"str",
"[",
"strCounter",
"]",
";",
"result",
".",
"push",
"(",
"new",
"SpecialMatch",
"(",
"strCounter",
",",
"upper",
")",
")",
";",
"specialsCounter",
"=",
"i",
";",
"queryCounter",
"++",
";",
"strCounter",
"++",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Compares the current character from the query string against the special characters in str. Returns true if a match was found, false otherwise.
|
[
"Compares",
"the",
"current",
"character",
"from",
"the",
"query",
"string",
"against",
"the",
"special",
"characters",
"in",
"str",
".",
"Returns",
"true",
"if",
"a",
"match",
"was",
"found",
"false",
"otherwise",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/StringMatch.js#L255-L288
|
train
|
adobe/brackets
|
src/utils/StringMatch.js
|
backtrack
|
function backtrack() {
// The idea is to pull matches off of our match list, rolling back
// characters from the query. We pay special attention to the special
// characters since they are searched first.
while (result.length > 0) {
var item = result.pop();
// nothing in the list? there's no possible match then.
if (!item) {
return false;
}
// we pulled off a match, which means that we need to put a character
// back into our query. strCounter is going to be set once we've pulled
// off the right special character and know where we're going to restart
// searching from.
queryCounter--;
if (item instanceof SpecialMatch) {
// pulled off a special, which means we need to make that special available
// for matching again
specialsCounter--;
// check to see if we've gone back as far as we need to
if (item.index < deadBranches[queryCounter]) {
// we now know that this part of the query does not match beyond this
// point
deadBranches[queryCounter] = item.index - 1;
// since we failed with the specials along this track, we're
// going to reset to looking for matches consecutively.
state = ANY_MATCH;
// we figure out where to start looking based on the new
// last item in the list. If there isn't anything else
// in the match list, we'll start over at the starting special
// (which is generally the beginning of the string, or the
// beginning of the last segment of the string)
item = result[result.length - 1];
if (!item) {
strCounter = specials[startingSpecial] + 1;
return true;
}
strCounter = item.index + 1;
return true;
}
}
}
return false;
}
|
javascript
|
function backtrack() {
// The idea is to pull matches off of our match list, rolling back
// characters from the query. We pay special attention to the special
// characters since they are searched first.
while (result.length > 0) {
var item = result.pop();
// nothing in the list? there's no possible match then.
if (!item) {
return false;
}
// we pulled off a match, which means that we need to put a character
// back into our query. strCounter is going to be set once we've pulled
// off the right special character and know where we're going to restart
// searching from.
queryCounter--;
if (item instanceof SpecialMatch) {
// pulled off a special, which means we need to make that special available
// for matching again
specialsCounter--;
// check to see if we've gone back as far as we need to
if (item.index < deadBranches[queryCounter]) {
// we now know that this part of the query does not match beyond this
// point
deadBranches[queryCounter] = item.index - 1;
// since we failed with the specials along this track, we're
// going to reset to looking for matches consecutively.
state = ANY_MATCH;
// we figure out where to start looking based on the new
// last item in the list. If there isn't anything else
// in the match list, we'll start over at the starting special
// (which is generally the beginning of the string, or the
// beginning of the last segment of the string)
item = result[result.length - 1];
if (!item) {
strCounter = specials[startingSpecial] + 1;
return true;
}
strCounter = item.index + 1;
return true;
}
}
}
return false;
}
|
[
"function",
"backtrack",
"(",
")",
"{",
"while",
"(",
"result",
".",
"length",
">",
"0",
")",
"{",
"var",
"item",
"=",
"result",
".",
"pop",
"(",
")",
";",
"if",
"(",
"!",
"item",
")",
"{",
"return",
"false",
";",
"}",
"queryCounter",
"--",
";",
"if",
"(",
"item",
"instanceof",
"SpecialMatch",
")",
"{",
"specialsCounter",
"--",
";",
"if",
"(",
"item",
".",
"index",
"<",
"deadBranches",
"[",
"queryCounter",
"]",
")",
"{",
"deadBranches",
"[",
"queryCounter",
"]",
"=",
"item",
".",
"index",
"-",
"1",
";",
"state",
"=",
"ANY_MATCH",
";",
"item",
"=",
"result",
"[",
"result",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"item",
")",
"{",
"strCounter",
"=",
"specials",
"[",
"startingSpecial",
"]",
"+",
"1",
";",
"return",
"true",
";",
"}",
"strCounter",
"=",
"item",
".",
"index",
"+",
"1",
";",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
This function implements the backtracking that is done when we fail to find a match with the query using the "search for specials first" approach. returns false when it is not able to backtrack successfully
|
[
"This",
"function",
"implements",
"the",
"backtracking",
"that",
"is",
"done",
"when",
"we",
"fail",
"to",
"find",
"a",
"match",
"with",
"the",
"query",
"using",
"the",
"search",
"for",
"specials",
"first",
"approach",
".",
"returns",
"false",
"when",
"it",
"is",
"not",
"able",
"to",
"backtrack",
"successfully"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/StringMatch.js#L294-L344
|
train
|
adobe/brackets
|
src/utils/StringMatch.js
|
closeRangeGap
|
function closeRangeGap(c) {
// Close the current range
if (currentRange) {
currentRange.includesLastSegment = lastMatchIndex >= lastSegmentStart;
if (currentRange.matched && currentRange.includesLastSegment) {
if (DEBUG_SCORES) {
scoreDebug.lastSegment += lastSegmentScore * LAST_SEGMENT_BOOST;
}
score += lastSegmentScore * LAST_SEGMENT_BOOST;
}
if (currentRange.matched && !currentRangeStartedOnSpecial) {
if (DEBUG_SCORES) {
scoreDebug.notStartingOnSpecial -= NOT_STARTING_ON_SPECIAL_PENALTY;
}
score -= NOT_STARTING_ON_SPECIAL_PENALTY;
}
ranges.push(currentRange);
}
// If there was space between the new range and the last,
// add a new unmatched range before the new range can be added.
if (lastMatchIndex + 1 < c) {
ranges.push({
text: str.substring(lastMatchIndex + 1, c),
matched: false,
includesLastSegment: c > lastSegmentStart
});
}
currentRange = null;
lastSegmentScore = 0;
}
|
javascript
|
function closeRangeGap(c) {
// Close the current range
if (currentRange) {
currentRange.includesLastSegment = lastMatchIndex >= lastSegmentStart;
if (currentRange.matched && currentRange.includesLastSegment) {
if (DEBUG_SCORES) {
scoreDebug.lastSegment += lastSegmentScore * LAST_SEGMENT_BOOST;
}
score += lastSegmentScore * LAST_SEGMENT_BOOST;
}
if (currentRange.matched && !currentRangeStartedOnSpecial) {
if (DEBUG_SCORES) {
scoreDebug.notStartingOnSpecial -= NOT_STARTING_ON_SPECIAL_PENALTY;
}
score -= NOT_STARTING_ON_SPECIAL_PENALTY;
}
ranges.push(currentRange);
}
// If there was space between the new range and the last,
// add a new unmatched range before the new range can be added.
if (lastMatchIndex + 1 < c) {
ranges.push({
text: str.substring(lastMatchIndex + 1, c),
matched: false,
includesLastSegment: c > lastSegmentStart
});
}
currentRange = null;
lastSegmentScore = 0;
}
|
[
"function",
"closeRangeGap",
"(",
"c",
")",
"{",
"if",
"(",
"currentRange",
")",
"{",
"currentRange",
".",
"includesLastSegment",
"=",
"lastMatchIndex",
">=",
"lastSegmentStart",
";",
"if",
"(",
"currentRange",
".",
"matched",
"&&",
"currentRange",
".",
"includesLastSegment",
")",
"{",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"lastSegment",
"+=",
"lastSegmentScore",
"*",
"LAST_SEGMENT_BOOST",
";",
"}",
"score",
"+=",
"lastSegmentScore",
"*",
"LAST_SEGMENT_BOOST",
";",
"}",
"if",
"(",
"currentRange",
".",
"matched",
"&&",
"!",
"currentRangeStartedOnSpecial",
")",
"{",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"notStartingOnSpecial",
"-=",
"NOT_STARTING_ON_SPECIAL_PENALTY",
";",
"}",
"score",
"-=",
"NOT_STARTING_ON_SPECIAL_PENALTY",
";",
"}",
"ranges",
".",
"push",
"(",
"currentRange",
")",
";",
"}",
"if",
"(",
"lastMatchIndex",
"+",
"1",
"<",
"c",
")",
"{",
"ranges",
".",
"push",
"(",
"{",
"text",
":",
"str",
".",
"substring",
"(",
"lastMatchIndex",
"+",
"1",
",",
"c",
")",
",",
"matched",
":",
"false",
",",
"includesLastSegment",
":",
"c",
">",
"lastSegmentStart",
"}",
")",
";",
"}",
"currentRange",
"=",
"null",
";",
"lastSegmentScore",
"=",
"0",
";",
"}"
] |
Records the current range and adds any additional ranges required to get to character index c. This function is called before starting a new range or returning from the function.
|
[
"Records",
"the",
"current",
"range",
"and",
"adds",
"any",
"additional",
"ranges",
"required",
"to",
"get",
"to",
"character",
"index",
"c",
".",
"This",
"function",
"is",
"called",
"before",
"starting",
"a",
"new",
"range",
"or",
"returning",
"from",
"the",
"function",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/StringMatch.js#L534-L565
|
train
|
adobe/brackets
|
src/utils/StringMatch.js
|
addMatch
|
function addMatch(match) {
// Pull off the character index
var c = match.index;
var newPoints = 0;
// A match means that we need to do some scoring bookkeeping.
// Start with points added for any match
if (DEBUG_SCORES) {
scoreDebug.match += MATCH_POINTS;
}
newPoints += MATCH_POINTS;
if (match.upper) {
if (DEBUG_SCORES) {
scoreDebug.upper += UPPER_CASE_MATCH;
}
newPoints += UPPER_CASE_MATCH;
}
// A bonus is given for characters that match at the beginning
// of the filename
if (c === lastSegmentStart) {
if (DEBUG_SCORES) {
scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
}
newPoints += BEGINNING_OF_NAME_POINTS;
}
// If the new character immediately follows the last matched character,
// we award the consecutive matches bonus. The check for score > 0
// handles the initial value of lastMatchIndex which is used for
// constructing ranges but we don't yet have a true match.
if (score > 0 && lastMatchIndex + 1 === c) {
// Continue boosting for each additional match at the beginning
// of the name
if (c - numConsecutive === lastSegmentStart) {
if (DEBUG_SCORES) {
scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
}
newPoints += BEGINNING_OF_NAME_POINTS;
}
numConsecutive++;
var boost = CONSECUTIVE_MATCHES_POINTS * numConsecutive;
// Consecutive matches that started on a special are a
// good indicator of intent, so we award an added bonus there.
if (currentRangeStartedOnSpecial) {
boost = boost * 2;
}
if (DEBUG_SCORES) {
scoreDebug.consecutive += boost;
}
newPoints += boost;
} else {
numConsecutive = 1;
}
// add points for "special" character matches
if (match instanceof SpecialMatch) {
if (DEBUG_SCORES) {
scoreDebug.special += SPECIAL_POINTS;
}
newPoints += SPECIAL_POINTS;
}
score += newPoints;
// points accumulated in the last segment get an extra bonus
if (c >= lastSegmentStart) {
lastSegmentScore += newPoints;
}
// if the last range wasn't a match or there's a gap, we need to close off
// the range to start a new one.
if ((currentRange && !currentRange.matched) || c > lastMatchIndex + 1) {
closeRangeGap(c);
}
lastMatchIndex = c;
// set up a new match range or add to the current one
if (!currentRange) {
currentRange = {
text: str[c],
matched: true
};
// Check to see if this new matched range is starting on a special
// character. We penalize those ranges that don't, because most
// people will search on the logical boundaries of the name
currentRangeStartedOnSpecial = match instanceof SpecialMatch;
} else {
currentRange.text += str[c];
}
}
|
javascript
|
function addMatch(match) {
// Pull off the character index
var c = match.index;
var newPoints = 0;
// A match means that we need to do some scoring bookkeeping.
// Start with points added for any match
if (DEBUG_SCORES) {
scoreDebug.match += MATCH_POINTS;
}
newPoints += MATCH_POINTS;
if (match.upper) {
if (DEBUG_SCORES) {
scoreDebug.upper += UPPER_CASE_MATCH;
}
newPoints += UPPER_CASE_MATCH;
}
// A bonus is given for characters that match at the beginning
// of the filename
if (c === lastSegmentStart) {
if (DEBUG_SCORES) {
scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
}
newPoints += BEGINNING_OF_NAME_POINTS;
}
// If the new character immediately follows the last matched character,
// we award the consecutive matches bonus. The check for score > 0
// handles the initial value of lastMatchIndex which is used for
// constructing ranges but we don't yet have a true match.
if (score > 0 && lastMatchIndex + 1 === c) {
// Continue boosting for each additional match at the beginning
// of the name
if (c - numConsecutive === lastSegmentStart) {
if (DEBUG_SCORES) {
scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
}
newPoints += BEGINNING_OF_NAME_POINTS;
}
numConsecutive++;
var boost = CONSECUTIVE_MATCHES_POINTS * numConsecutive;
// Consecutive matches that started on a special are a
// good indicator of intent, so we award an added bonus there.
if (currentRangeStartedOnSpecial) {
boost = boost * 2;
}
if (DEBUG_SCORES) {
scoreDebug.consecutive += boost;
}
newPoints += boost;
} else {
numConsecutive = 1;
}
// add points for "special" character matches
if (match instanceof SpecialMatch) {
if (DEBUG_SCORES) {
scoreDebug.special += SPECIAL_POINTS;
}
newPoints += SPECIAL_POINTS;
}
score += newPoints;
// points accumulated in the last segment get an extra bonus
if (c >= lastSegmentStart) {
lastSegmentScore += newPoints;
}
// if the last range wasn't a match or there's a gap, we need to close off
// the range to start a new one.
if ((currentRange && !currentRange.matched) || c > lastMatchIndex + 1) {
closeRangeGap(c);
}
lastMatchIndex = c;
// set up a new match range or add to the current one
if (!currentRange) {
currentRange = {
text: str[c],
matched: true
};
// Check to see if this new matched range is starting on a special
// character. We penalize those ranges that don't, because most
// people will search on the logical boundaries of the name
currentRangeStartedOnSpecial = match instanceof SpecialMatch;
} else {
currentRange.text += str[c];
}
}
|
[
"function",
"addMatch",
"(",
"match",
")",
"{",
"var",
"c",
"=",
"match",
".",
"index",
";",
"var",
"newPoints",
"=",
"0",
";",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"match",
"+=",
"MATCH_POINTS",
";",
"}",
"newPoints",
"+=",
"MATCH_POINTS",
";",
"if",
"(",
"match",
".",
"upper",
")",
"{",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"upper",
"+=",
"UPPER_CASE_MATCH",
";",
"}",
"newPoints",
"+=",
"UPPER_CASE_MATCH",
";",
"}",
"if",
"(",
"c",
"===",
"lastSegmentStart",
")",
"{",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"beginning",
"+=",
"BEGINNING_OF_NAME_POINTS",
";",
"}",
"newPoints",
"+=",
"BEGINNING_OF_NAME_POINTS",
";",
"}",
"if",
"(",
"score",
">",
"0",
"&&",
"lastMatchIndex",
"+",
"1",
"===",
"c",
")",
"{",
"if",
"(",
"c",
"-",
"numConsecutive",
"===",
"lastSegmentStart",
")",
"{",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"beginning",
"+=",
"BEGINNING_OF_NAME_POINTS",
";",
"}",
"newPoints",
"+=",
"BEGINNING_OF_NAME_POINTS",
";",
"}",
"numConsecutive",
"++",
";",
"var",
"boost",
"=",
"CONSECUTIVE_MATCHES_POINTS",
"*",
"numConsecutive",
";",
"if",
"(",
"currentRangeStartedOnSpecial",
")",
"{",
"boost",
"=",
"boost",
"*",
"2",
";",
"}",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"consecutive",
"+=",
"boost",
";",
"}",
"newPoints",
"+=",
"boost",
";",
"}",
"else",
"{",
"numConsecutive",
"=",
"1",
";",
"}",
"if",
"(",
"match",
"instanceof",
"SpecialMatch",
")",
"{",
"if",
"(",
"DEBUG_SCORES",
")",
"{",
"scoreDebug",
".",
"special",
"+=",
"SPECIAL_POINTS",
";",
"}",
"newPoints",
"+=",
"SPECIAL_POINTS",
";",
"}",
"score",
"+=",
"newPoints",
";",
"if",
"(",
"c",
">=",
"lastSegmentStart",
")",
"{",
"lastSegmentScore",
"+=",
"newPoints",
";",
"}",
"if",
"(",
"(",
"currentRange",
"&&",
"!",
"currentRange",
".",
"matched",
")",
"||",
"c",
">",
"lastMatchIndex",
"+",
"1",
")",
"{",
"closeRangeGap",
"(",
"c",
")",
";",
"}",
"lastMatchIndex",
"=",
"c",
";",
"if",
"(",
"!",
"currentRange",
")",
"{",
"currentRange",
"=",
"{",
"text",
":",
"str",
"[",
"c",
"]",
",",
"matched",
":",
"true",
"}",
";",
"currentRangeStartedOnSpecial",
"=",
"match",
"instanceof",
"SpecialMatch",
";",
"}",
"else",
"{",
"currentRange",
".",
"text",
"+=",
"str",
"[",
"c",
"]",
";",
"}",
"}"
] |
Adds a matched character to the appropriate range
|
[
"Adds",
"a",
"matched",
"character",
"to",
"the",
"appropriate",
"range"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/StringMatch.js#L572-L668
|
train
|
adobe/brackets
|
src/editor/InlineTextEditor.js
|
_syncGutterWidths
|
function _syncGutterWidths(hostEditor) {
var allHostedEditors = EditorManager.getInlineEditors(hostEditor);
// add the host itself to the list too
allHostedEditors.push(hostEditor);
var maxWidth = 0;
allHostedEditors.forEach(function (editor) {
var $gutter = $(editor._codeMirror.getGutterElement()).find(".CodeMirror-linenumbers");
$gutter.css("min-width", "");
var curWidth = $gutter.width();
if (curWidth > maxWidth) {
maxWidth = curWidth;
}
});
if (allHostedEditors.length === 1) {
//There's only the host, just refresh the gutter
allHostedEditors[0]._codeMirror.setOption("gutters", allHostedEditors[0]._codeMirror.getOption("gutters"));
return;
}
maxWidth = maxWidth + "px";
allHostedEditors.forEach(function (editor) {
$(editor._codeMirror.getGutterElement()).find(".CodeMirror-linenumbers").css("min-width", maxWidth);
// Force CodeMirror to refresh the gutter
editor._codeMirror.setOption("gutters", editor._codeMirror.getOption("gutters"));
});
}
|
javascript
|
function _syncGutterWidths(hostEditor) {
var allHostedEditors = EditorManager.getInlineEditors(hostEditor);
// add the host itself to the list too
allHostedEditors.push(hostEditor);
var maxWidth = 0;
allHostedEditors.forEach(function (editor) {
var $gutter = $(editor._codeMirror.getGutterElement()).find(".CodeMirror-linenumbers");
$gutter.css("min-width", "");
var curWidth = $gutter.width();
if (curWidth > maxWidth) {
maxWidth = curWidth;
}
});
if (allHostedEditors.length === 1) {
//There's only the host, just refresh the gutter
allHostedEditors[0]._codeMirror.setOption("gutters", allHostedEditors[0]._codeMirror.getOption("gutters"));
return;
}
maxWidth = maxWidth + "px";
allHostedEditors.forEach(function (editor) {
$(editor._codeMirror.getGutterElement()).find(".CodeMirror-linenumbers").css("min-width", maxWidth);
// Force CodeMirror to refresh the gutter
editor._codeMirror.setOption("gutters", editor._codeMirror.getOption("gutters"));
});
}
|
[
"function",
"_syncGutterWidths",
"(",
"hostEditor",
")",
"{",
"var",
"allHostedEditors",
"=",
"EditorManager",
".",
"getInlineEditors",
"(",
"hostEditor",
")",
";",
"allHostedEditors",
".",
"push",
"(",
"hostEditor",
")",
";",
"var",
"maxWidth",
"=",
"0",
";",
"allHostedEditors",
".",
"forEach",
"(",
"function",
"(",
"editor",
")",
"{",
"var",
"$gutter",
"=",
"$",
"(",
"editor",
".",
"_codeMirror",
".",
"getGutterElement",
"(",
")",
")",
".",
"find",
"(",
"\".CodeMirror-linenumbers\"",
")",
";",
"$gutter",
".",
"css",
"(",
"\"min-width\"",
",",
"\"\"",
")",
";",
"var",
"curWidth",
"=",
"$gutter",
".",
"width",
"(",
")",
";",
"if",
"(",
"curWidth",
">",
"maxWidth",
")",
"{",
"maxWidth",
"=",
"curWidth",
";",
"}",
"}",
")",
";",
"if",
"(",
"allHostedEditors",
".",
"length",
"===",
"1",
")",
"{",
"allHostedEditors",
"[",
"0",
"]",
".",
"_codeMirror",
".",
"setOption",
"(",
"\"gutters\"",
",",
"allHostedEditors",
"[",
"0",
"]",
".",
"_codeMirror",
".",
"getOption",
"(",
"\"gutters\"",
")",
")",
";",
"return",
";",
"}",
"maxWidth",
"=",
"maxWidth",
"+",
"\"px\"",
";",
"allHostedEditors",
".",
"forEach",
"(",
"function",
"(",
"editor",
")",
"{",
"$",
"(",
"editor",
".",
"_codeMirror",
".",
"getGutterElement",
"(",
")",
")",
".",
"find",
"(",
"\".CodeMirror-linenumbers\"",
")",
".",
"css",
"(",
"\"min-width\"",
",",
"maxWidth",
")",
";",
"editor",
".",
"_codeMirror",
".",
"setOption",
"(",
"\"gutters\"",
",",
"editor",
".",
"_codeMirror",
".",
"getOption",
"(",
"\"gutters\"",
")",
")",
";",
"}",
")",
";",
"}"
] |
Given a host editor and its inline editors, find the widest gutter and make all the others match
@param {!Editor} hostEditor Host editor containing all the inline editors to sync
@private
|
[
"Given",
"a",
"host",
"editor",
"and",
"its",
"inline",
"editors",
"find",
"the",
"widest",
"gutter",
"and",
"make",
"all",
"the",
"others",
"match"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/InlineTextEditor.js#L96-L125
|
train
|
adobe/brackets
|
src/extensions/default/StaticServer/node/StaticServerDomain.js
|
init
|
function init(domainManager) {
_domainManager = domainManager;
if (!domainManager.hasDomain("staticServer")) {
domainManager.registerDomain("staticServer", {major: 0, minor: 1});
}
_domainManager.registerCommand(
"staticServer",
"_setRequestFilterTimeout",
_cmdSetRequestFilterTimeout,
false,
"Unit tests only. Set timeout value for filtered requests.",
[{
name: "timeout",
type: "number",
description: "Duration to wait before passing a filtered request to the static file server."
}],
[]
);
_domainManager.registerCommand(
"staticServer",
"getServer",
_cmdGetServer,
true,
"Starts or returns an existing server for the given path.",
[
{
name: "path",
type: "string",
description: "Absolute filesystem path for root of server."
},
{
name: "port",
type: "number",
description: "Port number to use for HTTP server. Pass zero to assign a random port."
}
],
[{
name: "address",
type: "{address: string, family: string, port: number}",
description: "hostname (stored in 'address' parameter), port, and socket type (stored in 'family' parameter) for the server. Currently, 'family' will always be 'IPv4'."
}]
);
_domainManager.registerCommand(
"staticServer",
"closeServer",
_cmdCloseServer,
false,
"Closes the server for the given path.",
[{
name: "path",
type: "string",
description: "absolute filesystem path for root of server"
}],
[{
name: "result",
type: "boolean",
description: "indicates whether a server was found for the specific path then closed"
}]
);
_domainManager.registerCommand(
"staticServer",
"setRequestFilterPaths",
_cmdSetRequestFilterPaths,
false,
"Defines a set of paths from a server's root path to watch and fire 'requestFilter' events for.",
[
{
name: "root",
type: "string",
description: "absolute filesystem path for root of server"
},
{
name: "paths",
type: "Array",
description: "path to notify"
}
],
[]
);
_domainManager.registerCommand(
"staticServer",
"writeFilteredResponse",
_cmdWriteFilteredResponse,
false,
"Overrides the server response from static middleware with the provided response data. This should be called only in response to a filtered request.",
[
{
name: "root",
type: "string",
description: "absolute filesystem path for root of server"
},
{
name: "path",
type: "string",
description: "path to rewrite"
},
{
name: "resData",
type: "{body: string, headers: Array}",
description: "TODO"
}
],
[]
);
_domainManager.registerEvent(
"staticServer",
"requestFilter",
[{
name: "location",
type: "{hostname: string, pathname: string, port: number, root: string: id: number}",
description: "request path"
}]
);
}
|
javascript
|
function init(domainManager) {
_domainManager = domainManager;
if (!domainManager.hasDomain("staticServer")) {
domainManager.registerDomain("staticServer", {major: 0, minor: 1});
}
_domainManager.registerCommand(
"staticServer",
"_setRequestFilterTimeout",
_cmdSetRequestFilterTimeout,
false,
"Unit tests only. Set timeout value for filtered requests.",
[{
name: "timeout",
type: "number",
description: "Duration to wait before passing a filtered request to the static file server."
}],
[]
);
_domainManager.registerCommand(
"staticServer",
"getServer",
_cmdGetServer,
true,
"Starts or returns an existing server for the given path.",
[
{
name: "path",
type: "string",
description: "Absolute filesystem path for root of server."
},
{
name: "port",
type: "number",
description: "Port number to use for HTTP server. Pass zero to assign a random port."
}
],
[{
name: "address",
type: "{address: string, family: string, port: number}",
description: "hostname (stored in 'address' parameter), port, and socket type (stored in 'family' parameter) for the server. Currently, 'family' will always be 'IPv4'."
}]
);
_domainManager.registerCommand(
"staticServer",
"closeServer",
_cmdCloseServer,
false,
"Closes the server for the given path.",
[{
name: "path",
type: "string",
description: "absolute filesystem path for root of server"
}],
[{
name: "result",
type: "boolean",
description: "indicates whether a server was found for the specific path then closed"
}]
);
_domainManager.registerCommand(
"staticServer",
"setRequestFilterPaths",
_cmdSetRequestFilterPaths,
false,
"Defines a set of paths from a server's root path to watch and fire 'requestFilter' events for.",
[
{
name: "root",
type: "string",
description: "absolute filesystem path for root of server"
},
{
name: "paths",
type: "Array",
description: "path to notify"
}
],
[]
);
_domainManager.registerCommand(
"staticServer",
"writeFilteredResponse",
_cmdWriteFilteredResponse,
false,
"Overrides the server response from static middleware with the provided response data. This should be called only in response to a filtered request.",
[
{
name: "root",
type: "string",
description: "absolute filesystem path for root of server"
},
{
name: "path",
type: "string",
description: "path to rewrite"
},
{
name: "resData",
type: "{body: string, headers: Array}",
description: "TODO"
}
],
[]
);
_domainManager.registerEvent(
"staticServer",
"requestFilter",
[{
name: "location",
type: "{hostname: string, pathname: string, port: number, root: string: id: number}",
description: "request path"
}]
);
}
|
[
"function",
"init",
"(",
"domainManager",
")",
"{",
"_domainManager",
"=",
"domainManager",
";",
"if",
"(",
"!",
"domainManager",
".",
"hasDomain",
"(",
"\"staticServer\"",
")",
")",
"{",
"domainManager",
".",
"registerDomain",
"(",
"\"staticServer\"",
",",
"{",
"major",
":",
"0",
",",
"minor",
":",
"1",
"}",
")",
";",
"}",
"_domainManager",
".",
"registerCommand",
"(",
"\"staticServer\"",
",",
"\"_setRequestFilterTimeout\"",
",",
"_cmdSetRequestFilterTimeout",
",",
"false",
",",
"\"Unit tests only. Set timeout value for filtered requests.\"",
",",
"[",
"{",
"name",
":",
"\"timeout\"",
",",
"type",
":",
"\"number\"",
",",
"description",
":",
"\"Duration to wait before passing a filtered request to the static file server.\"",
"}",
"]",
",",
"[",
"]",
")",
";",
"_domainManager",
".",
"registerCommand",
"(",
"\"staticServer\"",
",",
"\"getServer\"",
",",
"_cmdGetServer",
",",
"true",
",",
"\"Starts or returns an existing server for the given path.\"",
",",
"[",
"{",
"name",
":",
"\"path\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"Absolute filesystem path for root of server.\"",
"}",
",",
"{",
"name",
":",
"\"port\"",
",",
"type",
":",
"\"number\"",
",",
"description",
":",
"\"Port number to use for HTTP server. Pass zero to assign a random port.\"",
"}",
"]",
",",
"[",
"{",
"name",
":",
"\"address\"",
",",
"type",
":",
"\"{address: string, family: string, port: number}\"",
",",
"description",
":",
"\"hostname (stored in 'address' parameter), port, and socket type (stored in 'family' parameter) for the server. Currently, 'family' will always be 'IPv4'.\"",
"}",
"]",
")",
";",
"_domainManager",
".",
"registerCommand",
"(",
"\"staticServer\"",
",",
"\"closeServer\"",
",",
"_cmdCloseServer",
",",
"false",
",",
"\"Closes the server for the given path.\"",
",",
"[",
"{",
"name",
":",
"\"path\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"absolute filesystem path for root of server\"",
"}",
"]",
",",
"[",
"{",
"name",
":",
"\"result\"",
",",
"type",
":",
"\"boolean\"",
",",
"description",
":",
"\"indicates whether a server was found for the specific path then closed\"",
"}",
"]",
")",
";",
"_domainManager",
".",
"registerCommand",
"(",
"\"staticServer\"",
",",
"\"setRequestFilterPaths\"",
",",
"_cmdSetRequestFilterPaths",
",",
"false",
",",
"\"Defines a set of paths from a server's root path to watch and fire 'requestFilter' events for.\"",
",",
"[",
"{",
"name",
":",
"\"root\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"absolute filesystem path for root of server\"",
"}",
",",
"{",
"name",
":",
"\"paths\"",
",",
"type",
":",
"\"Array\"",
",",
"description",
":",
"\"path to notify\"",
"}",
"]",
",",
"[",
"]",
")",
";",
"_domainManager",
".",
"registerCommand",
"(",
"\"staticServer\"",
",",
"\"writeFilteredResponse\"",
",",
"_cmdWriteFilteredResponse",
",",
"false",
",",
"\"Overrides the server response from static middleware with the provided response data. This should be called only in response to a filtered request.\"",
",",
"[",
"{",
"name",
":",
"\"root\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"absolute filesystem path for root of server\"",
"}",
",",
"{",
"name",
":",
"\"path\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"path to rewrite\"",
"}",
",",
"{",
"name",
":",
"\"resData\"",
",",
"type",
":",
"\"{body: string, headers: Array}\"",
",",
"description",
":",
"\"TODO\"",
"}",
"]",
",",
"[",
"]",
")",
";",
"_domainManager",
".",
"registerEvent",
"(",
"\"staticServer\"",
",",
"\"requestFilter\"",
",",
"[",
"{",
"name",
":",
"\"location\"",
",",
"type",
":",
"\"{hostname: string, pathname: string, port: number, root: string: id: number}\"",
",",
"description",
":",
"\"request path\"",
"}",
"]",
")",
";",
"}"
] |
Initializes the StaticServer domain with its commands.
@param {DomainManager} domainManager The DomainManager for the server
|
[
"Initializes",
"the",
"StaticServer",
"domain",
"with",
"its",
"commands",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/StaticServer/node/StaticServerDomain.js#L361-L475
|
train
|
adobe/brackets
|
src/search/FindUtils.js
|
_doReplaceInDocument
|
function _doReplaceInDocument(doc, matchInfo, replaceText, isRegexp) {
// Double-check that the open document's timestamp matches the one we recorded. This
// should normally never go out of sync, because if it did we wouldn't start the
// replace in the first place (due to the fact that we immediately close the search
// results panel whenever we detect a filesystem change that affects the results),
// but we want to double-check in case we don't happen to get the change in time.
// This will *not* handle cases where the document has been edited in memory since
// the matchInfo was generated.
if (doc.diskTimestamp.getTime() !== matchInfo.timestamp.getTime()) {
return new $.Deferred().reject(exports.ERROR_FILE_CHANGED).promise();
}
// Do the replacements in reverse document order so the offsets continue to be correct.
doc.batchOperation(function () {
matchInfo.matches.reverse().forEach(function (match) {
if (match.isChecked) {
doc.replaceRange(isRegexp ? parseDollars(replaceText, match.result) : replaceText, match.start, match.end);
}
});
});
return new $.Deferred().resolve().promise();
}
|
javascript
|
function _doReplaceInDocument(doc, matchInfo, replaceText, isRegexp) {
// Double-check that the open document's timestamp matches the one we recorded. This
// should normally never go out of sync, because if it did we wouldn't start the
// replace in the first place (due to the fact that we immediately close the search
// results panel whenever we detect a filesystem change that affects the results),
// but we want to double-check in case we don't happen to get the change in time.
// This will *not* handle cases where the document has been edited in memory since
// the matchInfo was generated.
if (doc.diskTimestamp.getTime() !== matchInfo.timestamp.getTime()) {
return new $.Deferred().reject(exports.ERROR_FILE_CHANGED).promise();
}
// Do the replacements in reverse document order so the offsets continue to be correct.
doc.batchOperation(function () {
matchInfo.matches.reverse().forEach(function (match) {
if (match.isChecked) {
doc.replaceRange(isRegexp ? parseDollars(replaceText, match.result) : replaceText, match.start, match.end);
}
});
});
return new $.Deferred().resolve().promise();
}
|
[
"function",
"_doReplaceInDocument",
"(",
"doc",
",",
"matchInfo",
",",
"replaceText",
",",
"isRegexp",
")",
"{",
"if",
"(",
"doc",
".",
"diskTimestamp",
".",
"getTime",
"(",
")",
"!==",
"matchInfo",
".",
"timestamp",
".",
"getTime",
"(",
")",
")",
"{",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"reject",
"(",
"exports",
".",
"ERROR_FILE_CHANGED",
")",
".",
"promise",
"(",
")",
";",
"}",
"doc",
".",
"batchOperation",
"(",
"function",
"(",
")",
"{",
"matchInfo",
".",
"matches",
".",
"reverse",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"match",
")",
"{",
"if",
"(",
"match",
".",
"isChecked",
")",
"{",
"doc",
".",
"replaceRange",
"(",
"isRegexp",
"?",
"parseDollars",
"(",
"replaceText",
",",
"match",
".",
"result",
")",
":",
"replaceText",
",",
"match",
".",
"start",
",",
"match",
".",
"end",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"resolve",
"(",
")",
".",
"promise",
"(",
")",
";",
"}"
] |
Does a set of replacements in a single document in memory.
@param {!Document} doc The document to do the replacements in.
@param {Object} matchInfo The match info for this file, as returned by `_addSearchMatches()`. Might be mutated.
@param {string} replaceText The text to replace each result with.
@param {boolean=} isRegexp Whether the original query was a regexp.
@return {$.Promise} A promise that's resolved when the replacement is finished or rejected with an error if there were one or more errors.
|
[
"Does",
"a",
"set",
"of",
"replacements",
"in",
"a",
"single",
"document",
"in",
"memory",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindUtils.js#L113-L135
|
train
|
adobe/brackets
|
src/search/FindUtils.js
|
_doReplaceOnDisk
|
function _doReplaceOnDisk(fullPath, matchInfo, replaceText, isRegexp) {
var file = FileSystem.getFileForPath(fullPath);
return DocumentManager.getDocumentText(file, true).then(function (contents, timestamp, lineEndings) {
if (timestamp.getTime() !== matchInfo.timestamp.getTime()) {
// Return a promise that we'll reject immediately. (We can't just return the
// error since this is the success handler.)
return new $.Deferred().reject(exports.ERROR_FILE_CHANGED).promise();
}
// Note that this assumes that the matches are sorted.
// TODO: is there a more efficient way to do this in a large string?
var result = [],
lastIndex = 0;
matchInfo.matches.forEach(function (match) {
if (match.isChecked) {
result.push(contents.slice(lastIndex, match.startOffset));
result.push(isRegexp ? parseDollars(replaceText, match.result) : replaceText);
lastIndex = match.endOffset;
}
});
result.push(contents.slice(lastIndex));
var newContents = result.join("");
// TODO: duplicated logic from Document - should refactor this?
if (lineEndings === FileUtils.LINE_ENDINGS_CRLF) {
newContents = newContents.replace(/\n/g, "\r\n");
}
return Async.promisify(file, "write", newContents);
});
}
|
javascript
|
function _doReplaceOnDisk(fullPath, matchInfo, replaceText, isRegexp) {
var file = FileSystem.getFileForPath(fullPath);
return DocumentManager.getDocumentText(file, true).then(function (contents, timestamp, lineEndings) {
if (timestamp.getTime() !== matchInfo.timestamp.getTime()) {
// Return a promise that we'll reject immediately. (We can't just return the
// error since this is the success handler.)
return new $.Deferred().reject(exports.ERROR_FILE_CHANGED).promise();
}
// Note that this assumes that the matches are sorted.
// TODO: is there a more efficient way to do this in a large string?
var result = [],
lastIndex = 0;
matchInfo.matches.forEach(function (match) {
if (match.isChecked) {
result.push(contents.slice(lastIndex, match.startOffset));
result.push(isRegexp ? parseDollars(replaceText, match.result) : replaceText);
lastIndex = match.endOffset;
}
});
result.push(contents.slice(lastIndex));
var newContents = result.join("");
// TODO: duplicated logic from Document - should refactor this?
if (lineEndings === FileUtils.LINE_ENDINGS_CRLF) {
newContents = newContents.replace(/\n/g, "\r\n");
}
return Async.promisify(file, "write", newContents);
});
}
|
[
"function",
"_doReplaceOnDisk",
"(",
"fullPath",
",",
"matchInfo",
",",
"replaceText",
",",
"isRegexp",
")",
"{",
"var",
"file",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"fullPath",
")",
";",
"return",
"DocumentManager",
".",
"getDocumentText",
"(",
"file",
",",
"true",
")",
".",
"then",
"(",
"function",
"(",
"contents",
",",
"timestamp",
",",
"lineEndings",
")",
"{",
"if",
"(",
"timestamp",
".",
"getTime",
"(",
")",
"!==",
"matchInfo",
".",
"timestamp",
".",
"getTime",
"(",
")",
")",
"{",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"reject",
"(",
"exports",
".",
"ERROR_FILE_CHANGED",
")",
".",
"promise",
"(",
")",
";",
"}",
"var",
"result",
"=",
"[",
"]",
",",
"lastIndex",
"=",
"0",
";",
"matchInfo",
".",
"matches",
".",
"forEach",
"(",
"function",
"(",
"match",
")",
"{",
"if",
"(",
"match",
".",
"isChecked",
")",
"{",
"result",
".",
"push",
"(",
"contents",
".",
"slice",
"(",
"lastIndex",
",",
"match",
".",
"startOffset",
")",
")",
";",
"result",
".",
"push",
"(",
"isRegexp",
"?",
"parseDollars",
"(",
"replaceText",
",",
"match",
".",
"result",
")",
":",
"replaceText",
")",
";",
"lastIndex",
"=",
"match",
".",
"endOffset",
";",
"}",
"}",
")",
";",
"result",
".",
"push",
"(",
"contents",
".",
"slice",
"(",
"lastIndex",
")",
")",
";",
"var",
"newContents",
"=",
"result",
".",
"join",
"(",
"\"\"",
")",
";",
"if",
"(",
"lineEndings",
"===",
"FileUtils",
".",
"LINE_ENDINGS_CRLF",
")",
"{",
"newContents",
"=",
"newContents",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"\"\\r\\n\"",
")",
";",
"}",
"\\r",
"}",
")",
";",
"}"
] |
Does a set of replacements in a single file on disk.
@param {string} fullPath The full path to the file.
@param {Object} matchInfo The match info for this file, as returned by `_addSearchMatches()`.
@param {string} replaceText The text to replace each result with.
@param {boolean=} isRegexp Whether the original query was a regexp.
@return {$.Promise} A promise that's resolved when the replacement is finished or rejected with an error if there were one or more errors.
|
[
"Does",
"a",
"set",
"of",
"replacements",
"in",
"a",
"single",
"file",
"on",
"disk",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindUtils.js#L145-L175
|
train
|
adobe/brackets
|
src/search/FindUtils.js
|
_doReplaceInOneFile
|
function _doReplaceInOneFile(fullPath, matchInfo, replaceText, options) {
var doc = DocumentManager.getOpenDocumentForPath(fullPath);
options = options || {};
// If we're forcing files open, or if the document is in the working set but not actually open
// yet, we want to open the file and do the replacement in memory.
if (!doc && (options.forceFilesOpen || MainViewManager.findInWorkingSet(MainViewManager.ALL_PANES, fullPath) !== -1)) {
return DocumentManager.getDocumentForPath(fullPath).then(function (newDoc) {
return _doReplaceInDocument(newDoc, matchInfo, replaceText, options.isRegexp);
});
} else if (doc) {
return _doReplaceInDocument(doc, matchInfo, replaceText, options.isRegexp);
} else {
return _doReplaceOnDisk(fullPath, matchInfo, replaceText, options.isRegexp);
}
}
|
javascript
|
function _doReplaceInOneFile(fullPath, matchInfo, replaceText, options) {
var doc = DocumentManager.getOpenDocumentForPath(fullPath);
options = options || {};
// If we're forcing files open, or if the document is in the working set but not actually open
// yet, we want to open the file and do the replacement in memory.
if (!doc && (options.forceFilesOpen || MainViewManager.findInWorkingSet(MainViewManager.ALL_PANES, fullPath) !== -1)) {
return DocumentManager.getDocumentForPath(fullPath).then(function (newDoc) {
return _doReplaceInDocument(newDoc, matchInfo, replaceText, options.isRegexp);
});
} else if (doc) {
return _doReplaceInDocument(doc, matchInfo, replaceText, options.isRegexp);
} else {
return _doReplaceOnDisk(fullPath, matchInfo, replaceText, options.isRegexp);
}
}
|
[
"function",
"_doReplaceInOneFile",
"(",
"fullPath",
",",
"matchInfo",
",",
"replaceText",
",",
"options",
")",
"{",
"var",
"doc",
"=",
"DocumentManager",
".",
"getOpenDocumentForPath",
"(",
"fullPath",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"doc",
"&&",
"(",
"options",
".",
"forceFilesOpen",
"||",
"MainViewManager",
".",
"findInWorkingSet",
"(",
"MainViewManager",
".",
"ALL_PANES",
",",
"fullPath",
")",
"!==",
"-",
"1",
")",
")",
"{",
"return",
"DocumentManager",
".",
"getDocumentForPath",
"(",
"fullPath",
")",
".",
"then",
"(",
"function",
"(",
"newDoc",
")",
"{",
"return",
"_doReplaceInDocument",
"(",
"newDoc",
",",
"matchInfo",
",",
"replaceText",
",",
"options",
".",
"isRegexp",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"doc",
")",
"{",
"return",
"_doReplaceInDocument",
"(",
"doc",
",",
"matchInfo",
",",
"replaceText",
",",
"options",
".",
"isRegexp",
")",
";",
"}",
"else",
"{",
"return",
"_doReplaceOnDisk",
"(",
"fullPath",
",",
"matchInfo",
",",
"replaceText",
",",
"options",
".",
"isRegexp",
")",
";",
"}",
"}"
] |
Does a set of replacements in a single file. If the file is already open in a Document in memory,
will do the replacement there, otherwise does it directly on disk.
@param {string} fullPath The full path to the file.
@param {Object} matchInfo The match info for this file, as returned by `_addSearchMatches()`.
@param {string} replaceText The text to replace each result with.
@param {Object=} options An options object:
forceFilesOpen: boolean - Whether to open the file in an editor and do replacements there rather than doing the
replacements on disk. Note that even if this is false, files that are already open in editors will have replacements
done in memory.
isRegexp: boolean - Whether the original query was a regexp. If true, $-substitution is performed on the replaceText.
@return {$.Promise} A promise that's resolved when the replacement is finished or rejected with an error if there were one or more errors.
|
[
"Does",
"a",
"set",
"of",
"replacements",
"in",
"a",
"single",
"file",
".",
"If",
"the",
"file",
"is",
"already",
"open",
"in",
"a",
"Document",
"in",
"memory",
"will",
"do",
"the",
"replacement",
"there",
"otherwise",
"does",
"it",
"directly",
"on",
"disk",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindUtils.js#L190-L204
|
train
|
adobe/brackets
|
src/search/FindUtils.js
|
labelForScope
|
function labelForScope(scope) {
if (scope) {
return StringUtils.format(
Strings.FIND_IN_FILES_SCOPED,
StringUtils.breakableUrl(
ProjectManager.makeProjectRelativeIfPossible(scope.fullPath)
)
);
} else {
return Strings.FIND_IN_FILES_NO_SCOPE;
}
}
|
javascript
|
function labelForScope(scope) {
if (scope) {
return StringUtils.format(
Strings.FIND_IN_FILES_SCOPED,
StringUtils.breakableUrl(
ProjectManager.makeProjectRelativeIfPossible(scope.fullPath)
)
);
} else {
return Strings.FIND_IN_FILES_NO_SCOPE;
}
}
|
[
"function",
"labelForScope",
"(",
"scope",
")",
"{",
"if",
"(",
"scope",
")",
"{",
"return",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"FIND_IN_FILES_SCOPED",
",",
"StringUtils",
".",
"breakableUrl",
"(",
"ProjectManager",
".",
"makeProjectRelativeIfPossible",
"(",
"scope",
".",
"fullPath",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"Strings",
".",
"FIND_IN_FILES_NO_SCOPE",
";",
"}",
"}"
] |
Returns label text to indicate the search scope. Already HTML-escaped.
@param {?Entry} scope
@return {string}
|
[
"Returns",
"label",
"text",
"to",
"indicate",
"the",
"search",
"scope",
".",
"Already",
"HTML",
"-",
"escaped",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindUtils.js#L286-L297
|
train
|
adobe/brackets
|
src/search/FindUtils.js
|
parseQueryInfo
|
function parseQueryInfo(queryInfo) {
var queryExpr;
if (!queryInfo || !queryInfo.query) {
return {empty: true};
}
// For now, treat all matches as multiline (i.e. ^/$ match on every line, not the whole
// document). This is consistent with how single-file find works. Eventually we should add
// an option for this.
var flags = "gm";
if (!queryInfo.isCaseSensitive) {
flags += "i";
}
// Is it a (non-blank) regex?
if (queryInfo.isRegexp) {
try {
queryExpr = new RegExp(queryInfo.query, flags);
} catch (e) {
return {valid: false, error: e.message};
}
} else {
// Query is a plain string. Turn it into a regexp
queryExpr = new RegExp(StringUtils.regexEscape(queryInfo.query), flags);
}
return {valid: true, queryExpr: queryExpr};
}
|
javascript
|
function parseQueryInfo(queryInfo) {
var queryExpr;
if (!queryInfo || !queryInfo.query) {
return {empty: true};
}
// For now, treat all matches as multiline (i.e. ^/$ match on every line, not the whole
// document). This is consistent with how single-file find works. Eventually we should add
// an option for this.
var flags = "gm";
if (!queryInfo.isCaseSensitive) {
flags += "i";
}
// Is it a (non-blank) regex?
if (queryInfo.isRegexp) {
try {
queryExpr = new RegExp(queryInfo.query, flags);
} catch (e) {
return {valid: false, error: e.message};
}
} else {
// Query is a plain string. Turn it into a regexp
queryExpr = new RegExp(StringUtils.regexEscape(queryInfo.query), flags);
}
return {valid: true, queryExpr: queryExpr};
}
|
[
"function",
"parseQueryInfo",
"(",
"queryInfo",
")",
"{",
"var",
"queryExpr",
";",
"if",
"(",
"!",
"queryInfo",
"||",
"!",
"queryInfo",
".",
"query",
")",
"{",
"return",
"{",
"empty",
":",
"true",
"}",
";",
"}",
"var",
"flags",
"=",
"\"gm\"",
";",
"if",
"(",
"!",
"queryInfo",
".",
"isCaseSensitive",
")",
"{",
"flags",
"+=",
"\"i\"",
";",
"}",
"if",
"(",
"queryInfo",
".",
"isRegexp",
")",
"{",
"try",
"{",
"queryExpr",
"=",
"new",
"RegExp",
"(",
"queryInfo",
".",
"query",
",",
"flags",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"{",
"valid",
":",
"false",
",",
"error",
":",
"e",
".",
"message",
"}",
";",
"}",
"}",
"else",
"{",
"queryExpr",
"=",
"new",
"RegExp",
"(",
"StringUtils",
".",
"regexEscape",
"(",
"queryInfo",
".",
"query",
")",
",",
"flags",
")",
";",
"}",
"return",
"{",
"valid",
":",
"true",
",",
"queryExpr",
":",
"queryExpr",
"}",
";",
"}"
] |
Parses the given query into a regexp, and returns whether it was valid or not.
@param {{query: string, caseSensitive: boolean, isRegexp: boolean}} queryInfo
@return {{queryExpr: RegExp, valid: boolean, empty: boolean, error: string}}
queryExpr - the regexp representing the query
valid - set to true if query is a nonempty string or a valid regexp.
empty - set to true if query was empty.
error - set to an error string if valid is false and query is nonempty.
|
[
"Parses",
"the",
"given",
"query",
"into",
"a",
"regexp",
"and",
"returns",
"whether",
"it",
"was",
"valid",
"or",
"not",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindUtils.js#L308-L335
|
train
|
adobe/brackets
|
src/search/FindUtils.js
|
prioritizeOpenFile
|
function prioritizeOpenFile(files, firstFile) {
var workingSetFiles = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES),
workingSetFileFound = {},
fileSetWithoutWorkingSet = [],
startingWorkingFileSet = [],
propertyName = "",
i = 0;
firstFile = firstFile || "";
// Create a working set path map which indicates if a file in working set is found in file list
for (i = 0; i < workingSetFiles.length; i++) {
workingSetFileFound[workingSetFiles[i].fullPath] = false;
}
// Remove all the working set files from the filtration list
fileSetWithoutWorkingSet = files.filter(function (key) {
if (workingSetFileFound[key] !== undefined) {
workingSetFileFound[key] = true;
return false;
}
return true;
});
//push in the first file
if (workingSetFileFound[firstFile] === true) {
startingWorkingFileSet.push(firstFile);
workingSetFileFound[firstFile] = false;
}
//push in the rest of working set files already present in file list
for (propertyName in workingSetFileFound) {
if (workingSetFileFound.hasOwnProperty(propertyName) && workingSetFileFound[propertyName]) {
startingWorkingFileSet.push(propertyName);
}
}
return startingWorkingFileSet.concat(fileSetWithoutWorkingSet);
}
|
javascript
|
function prioritizeOpenFile(files, firstFile) {
var workingSetFiles = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES),
workingSetFileFound = {},
fileSetWithoutWorkingSet = [],
startingWorkingFileSet = [],
propertyName = "",
i = 0;
firstFile = firstFile || "";
// Create a working set path map which indicates if a file in working set is found in file list
for (i = 0; i < workingSetFiles.length; i++) {
workingSetFileFound[workingSetFiles[i].fullPath] = false;
}
// Remove all the working set files from the filtration list
fileSetWithoutWorkingSet = files.filter(function (key) {
if (workingSetFileFound[key] !== undefined) {
workingSetFileFound[key] = true;
return false;
}
return true;
});
//push in the first file
if (workingSetFileFound[firstFile] === true) {
startingWorkingFileSet.push(firstFile);
workingSetFileFound[firstFile] = false;
}
//push in the rest of working set files already present in file list
for (propertyName in workingSetFileFound) {
if (workingSetFileFound.hasOwnProperty(propertyName) && workingSetFileFound[propertyName]) {
startingWorkingFileSet.push(propertyName);
}
}
return startingWorkingFileSet.concat(fileSetWithoutWorkingSet);
}
|
[
"function",
"prioritizeOpenFile",
"(",
"files",
",",
"firstFile",
")",
"{",
"var",
"workingSetFiles",
"=",
"MainViewManager",
".",
"getWorkingSet",
"(",
"MainViewManager",
".",
"ALL_PANES",
")",
",",
"workingSetFileFound",
"=",
"{",
"}",
",",
"fileSetWithoutWorkingSet",
"=",
"[",
"]",
",",
"startingWorkingFileSet",
"=",
"[",
"]",
",",
"propertyName",
"=",
"\"\"",
",",
"i",
"=",
"0",
";",
"firstFile",
"=",
"firstFile",
"||",
"\"\"",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"workingSetFiles",
".",
"length",
";",
"i",
"++",
")",
"{",
"workingSetFileFound",
"[",
"workingSetFiles",
"[",
"i",
"]",
".",
"fullPath",
"]",
"=",
"false",
";",
"}",
"fileSetWithoutWorkingSet",
"=",
"files",
".",
"filter",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"workingSetFileFound",
"[",
"key",
"]",
"!==",
"undefined",
")",
"{",
"workingSetFileFound",
"[",
"key",
"]",
"=",
"true",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"if",
"(",
"workingSetFileFound",
"[",
"firstFile",
"]",
"===",
"true",
")",
"{",
"startingWorkingFileSet",
".",
"push",
"(",
"firstFile",
")",
";",
"workingSetFileFound",
"[",
"firstFile",
"]",
"=",
"false",
";",
"}",
"for",
"(",
"propertyName",
"in",
"workingSetFileFound",
")",
"{",
"if",
"(",
"workingSetFileFound",
".",
"hasOwnProperty",
"(",
"propertyName",
")",
"&&",
"workingSetFileFound",
"[",
"propertyName",
"]",
")",
"{",
"startingWorkingFileSet",
".",
"push",
"(",
"propertyName",
")",
";",
"}",
"}",
"return",
"startingWorkingFileSet",
".",
"concat",
"(",
"fileSetWithoutWorkingSet",
")",
";",
"}"
] |
Prioritizes the open file and then the working set files to the starting of the list of files
@param {Array.<*>} files An array of file paths or file objects to sort
@param {?string} firstFile If specified, the path to the file that should be sorted to the top.
@return {Array.<*>}
|
[
"Prioritizes",
"the",
"open",
"file",
"and",
"then",
"the",
"working",
"set",
"files",
"to",
"the",
"starting",
"of",
"the",
"list",
"of",
"files"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindUtils.js#L343-L378
|
train
|
adobe/brackets
|
src/utils/DeprecationWarning.js
|
_trimStack
|
function _trimStack(stack) {
var indexOfFirstRequireJSline;
// Remove everything in the stack up to the end of the line that shows this module file path
stack = stack.substr(stack.indexOf(")\n") + 2);
// Find the very first line of require.js in the stack if the call is from an extension.
// Remove all those lines from the call stack.
indexOfFirstRequireJSline = stack.indexOf("requirejs/require.js");
if (indexOfFirstRequireJSline !== -1) {
indexOfFirstRequireJSline = stack.lastIndexOf(")", indexOfFirstRequireJSline) + 1;
stack = stack.substr(0, indexOfFirstRequireJSline);
}
return stack;
}
|
javascript
|
function _trimStack(stack) {
var indexOfFirstRequireJSline;
// Remove everything in the stack up to the end of the line that shows this module file path
stack = stack.substr(stack.indexOf(")\n") + 2);
// Find the very first line of require.js in the stack if the call is from an extension.
// Remove all those lines from the call stack.
indexOfFirstRequireJSline = stack.indexOf("requirejs/require.js");
if (indexOfFirstRequireJSline !== -1) {
indexOfFirstRequireJSline = stack.lastIndexOf(")", indexOfFirstRequireJSline) + 1;
stack = stack.substr(0, indexOfFirstRequireJSline);
}
return stack;
}
|
[
"function",
"_trimStack",
"(",
"stack",
")",
"{",
"var",
"indexOfFirstRequireJSline",
";",
"stack",
"=",
"stack",
".",
"substr",
"(",
"stack",
".",
"indexOf",
"(",
"\")\\n\"",
")",
"+",
"\\n",
")",
";",
"2",
"indexOfFirstRequireJSline",
"=",
"stack",
".",
"indexOf",
"(",
"\"requirejs/require.js\"",
")",
";",
"if",
"(",
"indexOfFirstRequireJSline",
"!==",
"-",
"1",
")",
"{",
"indexOfFirstRequireJSline",
"=",
"stack",
".",
"lastIndexOf",
"(",
"\")\"",
",",
"indexOfFirstRequireJSline",
")",
"+",
"1",
";",
"stack",
"=",
"stack",
".",
"substr",
"(",
"0",
",",
"indexOfFirstRequireJSline",
")",
";",
"}",
"}"
] |
Trim the stack so that it does not have the call to this module,
and all the calls to require.js to load the extension that shows
this deprecation warning.
|
[
"Trim",
"the",
"stack",
"so",
"that",
"it",
"does",
"not",
"have",
"the",
"call",
"to",
"this",
"module",
"and",
"all",
"the",
"calls",
"to",
"require",
".",
"js",
"to",
"load",
"the",
"extension",
"that",
"shows",
"this",
"deprecation",
"warning",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/DeprecationWarning.js#L41-L56
|
train
|
adobe/brackets
|
src/utils/DeprecationWarning.js
|
deprecationWarning
|
function deprecationWarning(message, oncePerCaller, callerStackPos) {
// If oncePerCaller isn't set, then only show the message once no matter who calls it.
if (!message || (!oncePerCaller && displayedWarnings[message])) {
return;
}
// Don't show the warning again if we've already gotten it from the current caller.
// The true caller location is the fourth line in the stack trace:
// * 0 is the word "Error"
// * 1 is this function
// * 2 is the caller of this function (the one throwing the deprecation warning)
// * 3 is the actual caller of the deprecated function.
var stack = new Error().stack,
callerLocation = stack.split("\n")[callerStackPos || 3];
if (oncePerCaller && displayedWarnings[message] && displayedWarnings[message][callerLocation]) {
return;
}
console.warn(message + "\n" + _trimStack(stack));
if (!displayedWarnings[message]) {
displayedWarnings[message] = {};
}
displayedWarnings[message][callerLocation] = true;
}
|
javascript
|
function deprecationWarning(message, oncePerCaller, callerStackPos) {
// If oncePerCaller isn't set, then only show the message once no matter who calls it.
if (!message || (!oncePerCaller && displayedWarnings[message])) {
return;
}
// Don't show the warning again if we've already gotten it from the current caller.
// The true caller location is the fourth line in the stack trace:
// * 0 is the word "Error"
// * 1 is this function
// * 2 is the caller of this function (the one throwing the deprecation warning)
// * 3 is the actual caller of the deprecated function.
var stack = new Error().stack,
callerLocation = stack.split("\n")[callerStackPos || 3];
if (oncePerCaller && displayedWarnings[message] && displayedWarnings[message][callerLocation]) {
return;
}
console.warn(message + "\n" + _trimStack(stack));
if (!displayedWarnings[message]) {
displayedWarnings[message] = {};
}
displayedWarnings[message][callerLocation] = true;
}
|
[
"function",
"deprecationWarning",
"(",
"message",
",",
"oncePerCaller",
",",
"callerStackPos",
")",
"{",
"if",
"(",
"!",
"message",
"||",
"(",
"!",
"oncePerCaller",
"&&",
"displayedWarnings",
"[",
"message",
"]",
")",
")",
"{",
"return",
";",
"}",
"var",
"stack",
"=",
"new",
"Error",
"(",
")",
".",
"stack",
",",
"callerLocation",
"=",
"stack",
".",
"split",
"(",
"\"\\n\"",
")",
"[",
"\\n",
"]",
";",
"callerStackPos",
"||",
"3",
"if",
"(",
"oncePerCaller",
"&&",
"displayedWarnings",
"[",
"message",
"]",
"&&",
"displayedWarnings",
"[",
"message",
"]",
"[",
"callerLocation",
"]",
")",
"{",
"return",
";",
"}",
"console",
".",
"warn",
"(",
"message",
"+",
"\"\\n\"",
"+",
"\\n",
")",
";",
"_trimStack",
"(",
"stack",
")",
"}"
] |
Show deprecation warning with the call stack if it
has never been displayed before.
@param {!string} message The deprecation message to be displayed.
@param {boolean=} oncePerCaller If true, displays the message once for each unique call location.
If false (the default), only displays the message once no matter where it's called from.
Note that setting this to true can cause a slight performance hit (because it has to generate
a stack trace), so don't set this for functions that you expect to be called from performance-
sensitive code (e.g. tight loops).
@param {number=} callerStackPos Only used if oncePerCaller=true. Overrides the `Error().stack` depth
where the client-code caller can be found. Only needed if extra shim layers are involved.
|
[
"Show",
"deprecation",
"warning",
"with",
"the",
"call",
"stack",
"if",
"it",
"has",
"never",
"been",
"displayed",
"before",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/DeprecationWarning.js#L70-L93
|
train
|
adobe/brackets
|
src/utils/DeprecationWarning.js
|
deprecateEvent
|
function deprecateEvent(outbound, inbound, oldEventName, newEventName, canonicalOutboundName, canonicalInboundName) {
// Mark deprecated so EventDispatcher.on() will emit warnings
EventDispatcher.markDeprecated(outbound, oldEventName, canonicalInboundName);
// create an event handler for the new event to listen for
inbound.on(newEventName, function () {
// Dispatch the event in case anyone is still listening
EventDispatcher.triggerWithArray(outbound, oldEventName, Array.prototype.slice.call(arguments, 1));
});
}
|
javascript
|
function deprecateEvent(outbound, inbound, oldEventName, newEventName, canonicalOutboundName, canonicalInboundName) {
// Mark deprecated so EventDispatcher.on() will emit warnings
EventDispatcher.markDeprecated(outbound, oldEventName, canonicalInboundName);
// create an event handler for the new event to listen for
inbound.on(newEventName, function () {
// Dispatch the event in case anyone is still listening
EventDispatcher.triggerWithArray(outbound, oldEventName, Array.prototype.slice.call(arguments, 1));
});
}
|
[
"function",
"deprecateEvent",
"(",
"outbound",
",",
"inbound",
",",
"oldEventName",
",",
"newEventName",
",",
"canonicalOutboundName",
",",
"canonicalInboundName",
")",
"{",
"EventDispatcher",
".",
"markDeprecated",
"(",
"outbound",
",",
"oldEventName",
",",
"canonicalInboundName",
")",
";",
"inbound",
".",
"on",
"(",
"newEventName",
",",
"function",
"(",
")",
"{",
"EventDispatcher",
".",
"triggerWithArray",
"(",
"outbound",
",",
"oldEventName",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
";",
"}",
")",
";",
"}"
] |
Show a deprecation warning if there are listeners for the event
```
DeprecationWarning.deprecateEvent(exports,
MainViewManager,
"workingSetAdd",
"workingSetAdd",
"DocumentManager.workingSetAdd",
"MainViewManager.workingSetAdd");
```
@param {Object} outbound - the object with the old event to dispatch
@param {Object} inbound - the object with the new event to map to the old event
@param {string} oldEventName - the name of the old event
@param {string} newEventName - the name of the new event
@param {string=} canonicalOutboundName - the canonical name of the old event
@param {string=} canonicalInboundName - the canonical name of the new event
|
[
"Show",
"a",
"deprecation",
"warning",
"if",
"there",
"are",
"listeners",
"for",
"the",
"event"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/DeprecationWarning.js#L115-L124
|
train
|
adobe/brackets
|
src/utils/DeprecationWarning.js
|
deprecateConstant
|
function deprecateConstant(obj, oldId, newId) {
var warning = "Use Menus." + newId + " instead of Menus." + oldId,
newValue = obj[newId];
Object.defineProperty(obj, oldId, {
get: function () {
deprecationWarning(warning, true);
return newValue;
}
});
}
|
javascript
|
function deprecateConstant(obj, oldId, newId) {
var warning = "Use Menus." + newId + " instead of Menus." + oldId,
newValue = obj[newId];
Object.defineProperty(obj, oldId, {
get: function () {
deprecationWarning(warning, true);
return newValue;
}
});
}
|
[
"function",
"deprecateConstant",
"(",
"obj",
",",
"oldId",
",",
"newId",
")",
"{",
"var",
"warning",
"=",
"\"Use Menus.\"",
"+",
"newId",
"+",
"\" instead of Menus.\"",
"+",
"oldId",
",",
"newValue",
"=",
"obj",
"[",
"newId",
"]",
";",
"Object",
".",
"defineProperty",
"(",
"obj",
",",
"oldId",
",",
"{",
"get",
":",
"function",
"(",
")",
"{",
"deprecationWarning",
"(",
"warning",
",",
"true",
")",
";",
"return",
"newValue",
";",
"}",
"}",
")",
";",
"}"
] |
Create a deprecation warning and action for updated constants
@param {!string} old Menu Id
@param {!string} new Menu Id
|
[
"Create",
"a",
"deprecation",
"warning",
"and",
"action",
"for",
"updated",
"constants"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/DeprecationWarning.js#L132-L142
|
train
|
adobe/brackets
|
src/preferences/PreferencesManager.js
|
setViewState
|
function setViewState(id, value, context, doNotSave) {
PreferencesImpl.stateManager.set(id, value, context);
if (!doNotSave) {
PreferencesImpl.stateManager.save();
}
}
|
javascript
|
function setViewState(id, value, context, doNotSave) {
PreferencesImpl.stateManager.set(id, value, context);
if (!doNotSave) {
PreferencesImpl.stateManager.save();
}
}
|
[
"function",
"setViewState",
"(",
"id",
",",
"value",
",",
"context",
",",
"doNotSave",
")",
"{",
"PreferencesImpl",
".",
"stateManager",
".",
"set",
"(",
"id",
",",
"value",
",",
"context",
")",
";",
"if",
"(",
"!",
"doNotSave",
")",
"{",
"PreferencesImpl",
".",
"stateManager",
".",
"save",
"(",
")",
";",
"}",
"}"
] |
Convenience function that sets a view state and then saves the file
@param {string} id preference to set
@param {*} value new value for the preference
@param {?Object} context Optional additional information about the request
@param {boolean=} doNotSave If it is undefined or false, then save the
view state immediately.
|
[
"Convenience",
"function",
"that",
"sets",
"a",
"view",
"state",
"and",
"then",
"saves",
"the",
"file"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesManager.js#L307-L314
|
train
|
adobe/brackets
|
src/utils/TokenUtils.js
|
movePrevToken
|
function movePrevToken(ctx, precise) {
if (precise === undefined) {
precise = true;
}
if (ctx.pos.ch <= 0 || ctx.token.start <= 0) {
//move up a line
if (ctx.pos.line <= 0) {
return false; //at the top already
}
ctx.pos.line--;
ctx.pos.ch = ctx.editor.getLine(ctx.pos.line).length;
} else {
ctx.pos.ch = ctx.token.start;
}
ctx.token = getTokenAt(ctx.editor, ctx.pos, precise);
return true;
}
|
javascript
|
function movePrevToken(ctx, precise) {
if (precise === undefined) {
precise = true;
}
if (ctx.pos.ch <= 0 || ctx.token.start <= 0) {
//move up a line
if (ctx.pos.line <= 0) {
return false; //at the top already
}
ctx.pos.line--;
ctx.pos.ch = ctx.editor.getLine(ctx.pos.line).length;
} else {
ctx.pos.ch = ctx.token.start;
}
ctx.token = getTokenAt(ctx.editor, ctx.pos, precise);
return true;
}
|
[
"function",
"movePrevToken",
"(",
"ctx",
",",
"precise",
")",
"{",
"if",
"(",
"precise",
"===",
"undefined",
")",
"{",
"precise",
"=",
"true",
";",
"}",
"if",
"(",
"ctx",
".",
"pos",
".",
"ch",
"<=",
"0",
"||",
"ctx",
".",
"token",
".",
"start",
"<=",
"0",
")",
"{",
"if",
"(",
"ctx",
".",
"pos",
".",
"line",
"<=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"ctx",
".",
"pos",
".",
"line",
"--",
";",
"ctx",
".",
"pos",
".",
"ch",
"=",
"ctx",
".",
"editor",
".",
"getLine",
"(",
"ctx",
".",
"pos",
".",
"line",
")",
".",
"length",
";",
"}",
"else",
"{",
"ctx",
".",
"pos",
".",
"ch",
"=",
"ctx",
".",
"token",
".",
"start",
";",
"}",
"ctx",
".",
"token",
"=",
"getTokenAt",
"(",
"ctx",
".",
"editor",
",",
"ctx",
".",
"pos",
",",
"precise",
")",
";",
"return",
"true",
";",
"}"
] |
Moves the given context backwards by one token.
@param {!{editor:!CodeMirror, pos:!{ch:number, line:number}, token:Object}} ctx
@param {boolean=} precise If code is being edited, use true (default) for accuracy.
If parsing unchanging code, use false to use cache for performance.
@return {boolean} whether the context changed
|
[
"Moves",
"the",
"given",
"context",
"backwards",
"by",
"one",
"token",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/TokenUtils.js#L109-L126
|
train
|
adobe/brackets
|
src/utils/TokenUtils.js
|
moveNextToken
|
function moveNextToken(ctx, precise) {
var eol = ctx.editor.getLine(ctx.pos.line).length;
if (precise === undefined) {
precise = true;
}
if (ctx.pos.ch >= eol || ctx.token.end >= eol) {
//move down a line
if (ctx.pos.line >= ctx.editor.lineCount() - 1) {
return false; //at the bottom
}
ctx.pos.line++;
ctx.pos.ch = 0;
} else {
ctx.pos.ch = ctx.token.end + 1;
}
ctx.token = getTokenAt(ctx.editor, ctx.pos, precise);
return true;
}
|
javascript
|
function moveNextToken(ctx, precise) {
var eol = ctx.editor.getLine(ctx.pos.line).length;
if (precise === undefined) {
precise = true;
}
if (ctx.pos.ch >= eol || ctx.token.end >= eol) {
//move down a line
if (ctx.pos.line >= ctx.editor.lineCount() - 1) {
return false; //at the bottom
}
ctx.pos.line++;
ctx.pos.ch = 0;
} else {
ctx.pos.ch = ctx.token.end + 1;
}
ctx.token = getTokenAt(ctx.editor, ctx.pos, precise);
return true;
}
|
[
"function",
"moveNextToken",
"(",
"ctx",
",",
"precise",
")",
"{",
"var",
"eol",
"=",
"ctx",
".",
"editor",
".",
"getLine",
"(",
"ctx",
".",
"pos",
".",
"line",
")",
".",
"length",
";",
"if",
"(",
"precise",
"===",
"undefined",
")",
"{",
"precise",
"=",
"true",
";",
"}",
"if",
"(",
"ctx",
".",
"pos",
".",
"ch",
">=",
"eol",
"||",
"ctx",
".",
"token",
".",
"end",
">=",
"eol",
")",
"{",
"if",
"(",
"ctx",
".",
"pos",
".",
"line",
">=",
"ctx",
".",
"editor",
".",
"lineCount",
"(",
")",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"ctx",
".",
"pos",
".",
"line",
"++",
";",
"ctx",
".",
"pos",
".",
"ch",
"=",
"0",
";",
"}",
"else",
"{",
"ctx",
".",
"pos",
".",
"ch",
"=",
"ctx",
".",
"token",
".",
"end",
"+",
"1",
";",
"}",
"ctx",
".",
"token",
"=",
"getTokenAt",
"(",
"ctx",
".",
"editor",
",",
"ctx",
".",
"pos",
",",
"precise",
")",
";",
"return",
"true",
";",
"}"
] |
Moves the given context forward by one token.
@param {!{editor:!CodeMirror, pos:!{ch:number, line:number}, token:Object}} ctx
@param {boolean=} precise If code is being edited, use true (default) for accuracy.
If parsing unchanging code, use false to use cache for performance.
@return {boolean} whether the context changed
|
[
"Moves",
"the",
"given",
"context",
"forward",
"by",
"one",
"token",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/TokenUtils.js#L143-L161
|
train
|
adobe/brackets
|
src/utils/TokenUtils.js
|
moveSkippingWhitespace
|
function moveSkippingWhitespace(moveFxn, ctx) {
if (!moveFxn(ctx)) {
return false;
}
while (!ctx.token.type && !/\S/.test(ctx.token.string)) {
if (!moveFxn(ctx)) {
return false;
}
}
return true;
}
|
javascript
|
function moveSkippingWhitespace(moveFxn, ctx) {
if (!moveFxn(ctx)) {
return false;
}
while (!ctx.token.type && !/\S/.test(ctx.token.string)) {
if (!moveFxn(ctx)) {
return false;
}
}
return true;
}
|
[
"function",
"moveSkippingWhitespace",
"(",
"moveFxn",
",",
"ctx",
")",
"{",
"if",
"(",
"!",
"moveFxn",
"(",
"ctx",
")",
")",
"{",
"return",
"false",
";",
"}",
"while",
"(",
"!",
"ctx",
".",
"token",
".",
"type",
"&&",
"!",
"/",
"\\S",
"/",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
")",
")",
"{",
"if",
"(",
"!",
"moveFxn",
"(",
"ctx",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Moves the given context in the given direction, skipping any whitespace it hits.
@param {function} moveFxn the function to move the context
@param {!{editor:!CodeMirror, pos:!{ch:number, line:number}, token:Object}} ctx
@return {boolean} whether the context changed
|
[
"Moves",
"the",
"given",
"context",
"in",
"the",
"given",
"direction",
"skipping",
"any",
"whitespace",
"it",
"hits",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/TokenUtils.js#L178-L188
|
train
|
adobe/brackets
|
src/utils/TokenUtils.js
|
offsetInToken
|
function offsetInToken(ctx) {
var offset = ctx.pos.ch - ctx.token.start;
if (offset < 0) {
console.log("CodeHintUtils: _offsetInToken - Invalid context: pos not in the current token!");
}
return offset;
}
|
javascript
|
function offsetInToken(ctx) {
var offset = ctx.pos.ch - ctx.token.start;
if (offset < 0) {
console.log("CodeHintUtils: _offsetInToken - Invalid context: pos not in the current token!");
}
return offset;
}
|
[
"function",
"offsetInToken",
"(",
"ctx",
")",
"{",
"var",
"offset",
"=",
"ctx",
".",
"pos",
".",
"ch",
"-",
"ctx",
".",
"token",
".",
"start",
";",
"if",
"(",
"offset",
"<",
"0",
")",
"{",
"console",
".",
"log",
"(",
"\"CodeHintUtils: _offsetInToken - Invalid context: pos not in the current token!\"",
")",
";",
"}",
"return",
"offset",
";",
"}"
] |
In the given context, get the character offset of pos from the start of the token.
@param {!{editor:!CodeMirror, pos:!{ch:number, line:number}, token:Object}} context
@return {number}
|
[
"In",
"the",
"given",
"context",
"get",
"the",
"character",
"offset",
"of",
"pos",
"from",
"the",
"start",
"of",
"the",
"token",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/TokenUtils.js#L195-L201
|
train
|
adobe/brackets
|
src/utils/TokenUtils.js
|
getModeAt
|
function getModeAt(cm, pos, precise) {
precise = precise || true;
var modeData = cm.getMode(),
name;
if (modeData.innerMode) {
modeData = CodeMirror.innerMode(modeData, getTokenAt(cm, pos, precise).state).mode;
}
name = (modeData.name === "xml") ?
modeData.configuration : modeData.name;
return {mode: modeData, name: name};
}
|
javascript
|
function getModeAt(cm, pos, precise) {
precise = precise || true;
var modeData = cm.getMode(),
name;
if (modeData.innerMode) {
modeData = CodeMirror.innerMode(modeData, getTokenAt(cm, pos, precise).state).mode;
}
name = (modeData.name === "xml") ?
modeData.configuration : modeData.name;
return {mode: modeData, name: name};
}
|
[
"function",
"getModeAt",
"(",
"cm",
",",
"pos",
",",
"precise",
")",
"{",
"precise",
"=",
"precise",
"||",
"true",
";",
"var",
"modeData",
"=",
"cm",
".",
"getMode",
"(",
")",
",",
"name",
";",
"if",
"(",
"modeData",
".",
"innerMode",
")",
"{",
"modeData",
"=",
"CodeMirror",
".",
"innerMode",
"(",
"modeData",
",",
"getTokenAt",
"(",
"cm",
",",
"pos",
",",
"precise",
")",
".",
"state",
")",
".",
"mode",
";",
"}",
"name",
"=",
"(",
"modeData",
".",
"name",
"===",
"\"xml\"",
")",
"?",
"modeData",
".",
"configuration",
":",
"modeData",
".",
"name",
";",
"return",
"{",
"mode",
":",
"modeData",
",",
"name",
":",
"name",
"}",
";",
"}"
] |
Returns the mode object and mode name string at a given position
@param {!CodeMirror} cm CodeMirror instance
@param {!{line:number, ch:number}} pos Position to query for mode
@param {boolean} precise If given, results in more current results. Suppresses caching.
@return {mode:{Object}, name:string}
|
[
"Returns",
"the",
"mode",
"object",
"and",
"mode",
"name",
"string",
"at",
"a",
"given",
"position"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/TokenUtils.js#L210-L223
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/HighlightAgent.js
|
node
|
function node(n) {
if (!LiveDevelopment.config.experimental) {
return;
}
if (!Inspector.config.highlight) {
return;
}
// go to the parent of a text node
if (n && n.type === 3) {
n = n.parent;
}
// node cannot be highlighted
if (!n || !n.nodeId || n.type !== 1) {
return hide();
}
// node is already highlighted
if (_highlight.type === "node" && _highlight.ref === n.nodeId) {
return;
}
// highlight the node
_highlight = {type: "node", ref: n.nodeId};
Inspector.DOM.highlightNode(n.nodeId, Inspector.config.highlightConfig);
}
|
javascript
|
function node(n) {
if (!LiveDevelopment.config.experimental) {
return;
}
if (!Inspector.config.highlight) {
return;
}
// go to the parent of a text node
if (n && n.type === 3) {
n = n.parent;
}
// node cannot be highlighted
if (!n || !n.nodeId || n.type !== 1) {
return hide();
}
// node is already highlighted
if (_highlight.type === "node" && _highlight.ref === n.nodeId) {
return;
}
// highlight the node
_highlight = {type: "node", ref: n.nodeId};
Inspector.DOM.highlightNode(n.nodeId, Inspector.config.highlightConfig);
}
|
[
"function",
"node",
"(",
"n",
")",
"{",
"if",
"(",
"!",
"LiveDevelopment",
".",
"config",
".",
"experimental",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"Inspector",
".",
"config",
".",
"highlight",
")",
"{",
"return",
";",
"}",
"if",
"(",
"n",
"&&",
"n",
".",
"type",
"===",
"3",
")",
"{",
"n",
"=",
"n",
".",
"parent",
";",
"}",
"if",
"(",
"!",
"n",
"||",
"!",
"n",
".",
"nodeId",
"||",
"n",
".",
"type",
"!==",
"1",
")",
"{",
"return",
"hide",
"(",
")",
";",
"}",
"if",
"(",
"_highlight",
".",
"type",
"===",
"\"node\"",
"&&",
"_highlight",
".",
"ref",
"===",
"n",
".",
"nodeId",
")",
"{",
"return",
";",
"}",
"_highlight",
"=",
"{",
"type",
":",
"\"node\"",
",",
"ref",
":",
"n",
".",
"nodeId",
"}",
";",
"Inspector",
".",
"DOM",
".",
"highlightNode",
"(",
"n",
".",
"nodeId",
",",
"Inspector",
".",
"config",
".",
"highlightConfig",
")",
";",
"}"
] |
Highlight a single node using DOM.highlightNode
@param {DOMNode} node
|
[
"Highlight",
"a",
"single",
"node",
"using",
"DOM",
".",
"highlightNode"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/HighlightAgent.js#L67-L94
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/HighlightAgent.js
|
rule
|
function rule(name) {
if (_highlight.ref === name) {
return;
}
hide();
_highlight = {type: "css", ref: name};
RemoteAgent.call("highlightRule", name);
}
|
javascript
|
function rule(name) {
if (_highlight.ref === name) {
return;
}
hide();
_highlight = {type: "css", ref: name};
RemoteAgent.call("highlightRule", name);
}
|
[
"function",
"rule",
"(",
"name",
")",
"{",
"if",
"(",
"_highlight",
".",
"ref",
"===",
"name",
")",
"{",
"return",
";",
"}",
"hide",
"(",
")",
";",
"_highlight",
"=",
"{",
"type",
":",
"\"css\"",
",",
"ref",
":",
"name",
"}",
";",
"RemoteAgent",
".",
"call",
"(",
"\"highlightRule\"",
",",
"name",
")",
";",
"}"
] |
Highlight all nodes affected by a CSS rule
@param {string} rule selector
|
[
"Highlight",
"all",
"nodes",
"affected",
"by",
"a",
"CSS",
"rule"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/HighlightAgent.js#L99-L106
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/HighlightAgent.js
|
domElement
|
function domElement(ids) {
var selector = "";
if (!Array.isArray(ids)) {
ids = [ids];
}
_.each(ids, function (id) {
if (selector !== "") {
selector += ",";
}
selector += "[data-brackets-id='" + id + "']";
});
rule(selector);
}
|
javascript
|
function domElement(ids) {
var selector = "";
if (!Array.isArray(ids)) {
ids = [ids];
}
_.each(ids, function (id) {
if (selector !== "") {
selector += ",";
}
selector += "[data-brackets-id='" + id + "']";
});
rule(selector);
}
|
[
"function",
"domElement",
"(",
"ids",
")",
"{",
"var",
"selector",
"=",
"\"\"",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"ids",
")",
")",
"{",
"ids",
"=",
"[",
"ids",
"]",
";",
"}",
"_",
".",
"each",
"(",
"ids",
",",
"function",
"(",
"id",
")",
"{",
"if",
"(",
"selector",
"!==",
"\"\"",
")",
"{",
"selector",
"+=",
"\",\"",
";",
"}",
"selector",
"+=",
"\"[data-brackets-id='\"",
"+",
"id",
"+",
"\"']\"",
";",
"}",
")",
";",
"rule",
"(",
"selector",
")",
";",
"}"
] |
Highlight all nodes with 'data-brackets-id' value
that matches id, or if id is an array, matches any of the given ids.
@param {string|Array<string>} value of the 'data-brackets-id' to match,
or an array of such.
|
[
"Highlight",
"all",
"nodes",
"with",
"data",
"-",
"brackets",
"-",
"id",
"value",
"that",
"matches",
"id",
"or",
"if",
"id",
"is",
"an",
"array",
"matches",
"any",
"of",
"the",
"given",
"ids",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/HighlightAgent.js#L113-L125
|
train
|
adobe/brackets
|
src/project/FileViewController.js
|
openAndSelectDocument
|
function openAndSelectDocument(fullPath, fileSelectionFocus, paneId) {
var result,
curDocChangedDueToMe = _curDocChangedDueToMe;
function _getDerivedPaneContext() {
function _secondPaneContext() {
return (window.event.ctrlKey || window.event.metaKey) && window.event.altKey ? MainViewManager.SECOND_PANE : null;
}
function _firstPaneContext() {
return (window.event.ctrlKey || window.event.metaKey) ? MainViewManager.FIRST_PANE : null;
}
return window.event && (_secondPaneContext() || _firstPaneContext());
}
if (fileSelectionFocus !== PROJECT_MANAGER && fileSelectionFocus !== WORKING_SET_VIEW) {
console.error("Bad parameter passed to FileViewController.openAndSelectDocument");
return;
}
// Opening files are asynchronous and we want to know when this function caused a file
// to open so that _fileSelectionFocus is set appropriatly. _curDocChangedDueToMe is set here
// and checked in the currentFileChange handler
_curDocChangedDueToMe = true;
_fileSelectionFocus = fileSelectionFocus;
paneId = (paneId || _getDerivedPaneContext() || MainViewManager.ACTIVE_PANE);
// If fullPath corresonds to the current doc being viewed then opening the file won't
// trigger a currentFileChange event, so we need to trigger a documentSelectionFocusChange
// in this case to signify the selection focus has changed even though the current document has not.
var currentPath = MainViewManager.getCurrentlyViewedPath(paneId);
if (currentPath === fullPath) {
_activatePane(paneId);
result = (new $.Deferred()).resolve().promise();
} else {
result = CommandManager.execute(Commands.FILE_OPEN, {fullPath: fullPath,
paneId: paneId});
}
// clear after notification is done
result.always(function () {
_curDocChangedDueToMe = curDocChangedDueToMe;
});
return result;
}
|
javascript
|
function openAndSelectDocument(fullPath, fileSelectionFocus, paneId) {
var result,
curDocChangedDueToMe = _curDocChangedDueToMe;
function _getDerivedPaneContext() {
function _secondPaneContext() {
return (window.event.ctrlKey || window.event.metaKey) && window.event.altKey ? MainViewManager.SECOND_PANE : null;
}
function _firstPaneContext() {
return (window.event.ctrlKey || window.event.metaKey) ? MainViewManager.FIRST_PANE : null;
}
return window.event && (_secondPaneContext() || _firstPaneContext());
}
if (fileSelectionFocus !== PROJECT_MANAGER && fileSelectionFocus !== WORKING_SET_VIEW) {
console.error("Bad parameter passed to FileViewController.openAndSelectDocument");
return;
}
// Opening files are asynchronous and we want to know when this function caused a file
// to open so that _fileSelectionFocus is set appropriatly. _curDocChangedDueToMe is set here
// and checked in the currentFileChange handler
_curDocChangedDueToMe = true;
_fileSelectionFocus = fileSelectionFocus;
paneId = (paneId || _getDerivedPaneContext() || MainViewManager.ACTIVE_PANE);
// If fullPath corresonds to the current doc being viewed then opening the file won't
// trigger a currentFileChange event, so we need to trigger a documentSelectionFocusChange
// in this case to signify the selection focus has changed even though the current document has not.
var currentPath = MainViewManager.getCurrentlyViewedPath(paneId);
if (currentPath === fullPath) {
_activatePane(paneId);
result = (new $.Deferred()).resolve().promise();
} else {
result = CommandManager.execute(Commands.FILE_OPEN, {fullPath: fullPath,
paneId: paneId});
}
// clear after notification is done
result.always(function () {
_curDocChangedDueToMe = curDocChangedDueToMe;
});
return result;
}
|
[
"function",
"openAndSelectDocument",
"(",
"fullPath",
",",
"fileSelectionFocus",
",",
"paneId",
")",
"{",
"var",
"result",
",",
"curDocChangedDueToMe",
"=",
"_curDocChangedDueToMe",
";",
"function",
"_getDerivedPaneContext",
"(",
")",
"{",
"function",
"_secondPaneContext",
"(",
")",
"{",
"return",
"(",
"window",
".",
"event",
".",
"ctrlKey",
"||",
"window",
".",
"event",
".",
"metaKey",
")",
"&&",
"window",
".",
"event",
".",
"altKey",
"?",
"MainViewManager",
".",
"SECOND_PANE",
":",
"null",
";",
"}",
"function",
"_firstPaneContext",
"(",
")",
"{",
"return",
"(",
"window",
".",
"event",
".",
"ctrlKey",
"||",
"window",
".",
"event",
".",
"metaKey",
")",
"?",
"MainViewManager",
".",
"FIRST_PANE",
":",
"null",
";",
"}",
"return",
"window",
".",
"event",
"&&",
"(",
"_secondPaneContext",
"(",
")",
"||",
"_firstPaneContext",
"(",
")",
")",
";",
"}",
"if",
"(",
"fileSelectionFocus",
"!==",
"PROJECT_MANAGER",
"&&",
"fileSelectionFocus",
"!==",
"WORKING_SET_VIEW",
")",
"{",
"console",
".",
"error",
"(",
"\"Bad parameter passed to FileViewController.openAndSelectDocument\"",
")",
";",
"return",
";",
"}",
"_curDocChangedDueToMe",
"=",
"true",
";",
"_fileSelectionFocus",
"=",
"fileSelectionFocus",
";",
"paneId",
"=",
"(",
"paneId",
"||",
"_getDerivedPaneContext",
"(",
")",
"||",
"MainViewManager",
".",
"ACTIVE_PANE",
")",
";",
"var",
"currentPath",
"=",
"MainViewManager",
".",
"getCurrentlyViewedPath",
"(",
"paneId",
")",
";",
"if",
"(",
"currentPath",
"===",
"fullPath",
")",
"{",
"_activatePane",
"(",
"paneId",
")",
";",
"result",
"=",
"(",
"new",
"$",
".",
"Deferred",
"(",
")",
")",
".",
"resolve",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"else",
"{",
"result",
"=",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"FILE_OPEN",
",",
"{",
"fullPath",
":",
"fullPath",
",",
"paneId",
":",
"paneId",
"}",
")",
";",
"}",
"result",
".",
"always",
"(",
"function",
"(",
")",
"{",
"_curDocChangedDueToMe",
"=",
"curDocChangedDueToMe",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] |
Opens a document if it's not open and selects the file in the UI corresponding to
fileSelectionFocus
@param {!fullPath} fullPath - full path of the document to open
@param {string} fileSelectionFocus - (WORKING_SET_VIEW || PROJECT_MANAGER)
@param {string} paneId - pane in which to open the document
@return {$.Promise}
|
[
"Opens",
"a",
"document",
"if",
"it",
"s",
"not",
"open",
"and",
"selects",
"the",
"file",
"in",
"the",
"UI",
"corresponding",
"to",
"fileSelectionFocus"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileViewController.js#L145-L195
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/UpdateInfoBar.js
|
generateJsonForMustache
|
function generateJsonForMustache(msgObj) {
var msgJsonObj = {};
if (msgObj.type) {
msgJsonObj.type = "'" + msgObj.type + "'";
}
msgJsonObj.title = msgObj.title;
msgJsonObj.description = msgObj.description;
if (msgObj.needButtons) {
msgJsonObj.buttons = [{
"id": "restart",
"value": Strings.RESTART_BUTTON,
"tIndex": "'0'"
}, {
"id": "later",
"value": Strings.LATER_BUTTON,
"tIndex": "'0'"
}];
msgJsonObj.needButtons = msgObj.needButtons;
}
return msgJsonObj;
}
|
javascript
|
function generateJsonForMustache(msgObj) {
var msgJsonObj = {};
if (msgObj.type) {
msgJsonObj.type = "'" + msgObj.type + "'";
}
msgJsonObj.title = msgObj.title;
msgJsonObj.description = msgObj.description;
if (msgObj.needButtons) {
msgJsonObj.buttons = [{
"id": "restart",
"value": Strings.RESTART_BUTTON,
"tIndex": "'0'"
}, {
"id": "later",
"value": Strings.LATER_BUTTON,
"tIndex": "'0'"
}];
msgJsonObj.needButtons = msgObj.needButtons;
}
return msgJsonObj;
}
|
[
"function",
"generateJsonForMustache",
"(",
"msgObj",
")",
"{",
"var",
"msgJsonObj",
"=",
"{",
"}",
";",
"if",
"(",
"msgObj",
".",
"type",
")",
"{",
"msgJsonObj",
".",
"type",
"=",
"\"'\"",
"+",
"msgObj",
".",
"type",
"+",
"\"'\"",
";",
"}",
"msgJsonObj",
".",
"title",
"=",
"msgObj",
".",
"title",
";",
"msgJsonObj",
".",
"description",
"=",
"msgObj",
".",
"description",
";",
"if",
"(",
"msgObj",
".",
"needButtons",
")",
"{",
"msgJsonObj",
".",
"buttons",
"=",
"[",
"{",
"\"id\"",
":",
"\"restart\"",
",",
"\"value\"",
":",
"Strings",
".",
"RESTART_BUTTON",
",",
"\"tIndex\"",
":",
"\"'0'\"",
"}",
",",
"{",
"\"id\"",
":",
"\"later\"",
",",
"\"value\"",
":",
"Strings",
".",
"LATER_BUTTON",
",",
"\"tIndex\"",
":",
"\"'0'\"",
"}",
"]",
";",
"msgJsonObj",
".",
"needButtons",
"=",
"msgObj",
".",
"needButtons",
";",
"}",
"return",
"msgJsonObj",
";",
"}"
] |
keycode for escape key
Generates the json to be used by Mustache for rendering
@param {object} msgObj - json object containing message information to be displayed
@returns {object} - the generated json object
|
[
"keycode",
"for",
"escape",
"key",
"Generates",
"the",
"json",
"to",
"be",
"used",
"by",
"Mustache",
"for",
"rendering"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/UpdateInfoBar.js#L53-L73
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/UpdateInfoBar.js
|
function () {
if($updateContent.length > 0 && $contentContainer.length > 0 && $updateBar.length > 0) {
var newWidth = $updateBar.outerWidth() - 38;
if($buttonContainer.length > 0) {
newWidth = newWidth- $buttonContainer.outerWidth();
}
if($iconContainer.length > 0) {
newWidth = newWidth - $iconContainer.outerWidth();
}
if($closeIconContainer.length > 0) {
newWidth = newWidth - $closeIconContainer.outerWidth();
}
$contentContainer.css({
"maxWidth": newWidth
});
}
}
|
javascript
|
function () {
if($updateContent.length > 0 && $contentContainer.length > 0 && $updateBar.length > 0) {
var newWidth = $updateBar.outerWidth() - 38;
if($buttonContainer.length > 0) {
newWidth = newWidth- $buttonContainer.outerWidth();
}
if($iconContainer.length > 0) {
newWidth = newWidth - $iconContainer.outerWidth();
}
if($closeIconContainer.length > 0) {
newWidth = newWidth - $closeIconContainer.outerWidth();
}
$contentContainer.css({
"maxWidth": newWidth
});
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"$updateContent",
".",
"length",
">",
"0",
"&&",
"$contentContainer",
".",
"length",
">",
"0",
"&&",
"$updateBar",
".",
"length",
">",
"0",
")",
"{",
"var",
"newWidth",
"=",
"$updateBar",
".",
"outerWidth",
"(",
")",
"-",
"38",
";",
"if",
"(",
"$buttonContainer",
".",
"length",
">",
"0",
")",
"{",
"newWidth",
"=",
"newWidth",
"-",
"$buttonContainer",
".",
"outerWidth",
"(",
")",
";",
"}",
"if",
"(",
"$iconContainer",
".",
"length",
">",
"0",
")",
"{",
"newWidth",
"=",
"newWidth",
"-",
"$iconContainer",
".",
"outerWidth",
"(",
")",
";",
"}",
"if",
"(",
"$closeIconContainer",
".",
"length",
">",
"0",
")",
"{",
"newWidth",
"=",
"newWidth",
"-",
"$closeIconContainer",
".",
"outerWidth",
"(",
")",
";",
"}",
"$contentContainer",
".",
"css",
"(",
"{",
"\"maxWidth\"",
":",
"newWidth",
"}",
")",
";",
"}",
"}"
] |
Content Container Width between Icon Container and Button Container or Close Icon Container will be assigned when window will be rezied.
|
[
"Content",
"Container",
"Width",
"between",
"Icon",
"Container",
"and",
"Button",
"Container",
"or",
"Close",
"Icon",
"Container",
"will",
"be",
"assigned",
"when",
"window",
"will",
"be",
"rezied",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/UpdateInfoBar.js#L123-L140
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js
|
function (href) {
var self = this;
// Inspect CSSRules for @imports:
// styleSheet obejct is required to scan CSSImportRules but
// browsers differ on the implementation of MutationObserver interface.
// Webkit triggers notifications before stylesheets are loaded,
// Firefox does it after loading.
// There are also differences on when 'load' event is triggered for
// the 'link' nodes. Webkit triggers it before stylesheet is loaded.
// Some references to check:
// http://www.phpied.com/when-is-a-stylesheet-really-loaded/
// http://stackoverflow.com/questions/17747616/webkit-dynamically-created-stylesheet-when-does-it-really-load
// http://stackoverflow.com/questions/11425209/are-dom-mutation-observers-slower-than-dom-mutation-events
//
// TODO: This is just a temporary 'cross-browser' solution, it needs optimization.
var loadInterval = setInterval(function () {
var i;
for (i = 0; i < window.document.styleSheets.length; i++) {
if (window.document.styleSheets[i].href === href) {
//clear interval
clearInterval(loadInterval);
// notify stylesheets added
self.notifyStylesheetAdded(href);
break;
}
}
}, 50);
}
|
javascript
|
function (href) {
var self = this;
// Inspect CSSRules for @imports:
// styleSheet obejct is required to scan CSSImportRules but
// browsers differ on the implementation of MutationObserver interface.
// Webkit triggers notifications before stylesheets are loaded,
// Firefox does it after loading.
// There are also differences on when 'load' event is triggered for
// the 'link' nodes. Webkit triggers it before stylesheet is loaded.
// Some references to check:
// http://www.phpied.com/when-is-a-stylesheet-really-loaded/
// http://stackoverflow.com/questions/17747616/webkit-dynamically-created-stylesheet-when-does-it-really-load
// http://stackoverflow.com/questions/11425209/are-dom-mutation-observers-slower-than-dom-mutation-events
//
// TODO: This is just a temporary 'cross-browser' solution, it needs optimization.
var loadInterval = setInterval(function () {
var i;
for (i = 0; i < window.document.styleSheets.length; i++) {
if (window.document.styleSheets[i].href === href) {
//clear interval
clearInterval(loadInterval);
// notify stylesheets added
self.notifyStylesheetAdded(href);
break;
}
}
}, 50);
}
|
[
"function",
"(",
"href",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"loadInterval",
"=",
"setInterval",
"(",
"function",
"(",
")",
"{",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"window",
".",
"document",
".",
"styleSheets",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"window",
".",
"document",
".",
"styleSheets",
"[",
"i",
"]",
".",
"href",
"===",
"href",
")",
"{",
"clearInterval",
"(",
"loadInterval",
")",
";",
"self",
".",
"notifyStylesheetAdded",
"(",
"href",
")",
";",
"break",
";",
"}",
"}",
"}",
",",
"50",
")",
";",
"}"
] |
Check the stylesheet that was just added be really loaded
to be able to extract potential import-ed stylesheets.
It invokes notifyStylesheetAdded once the sheet is loaded.
@param {string} href Absolute URL of the stylesheet.
|
[
"Check",
"the",
"stylesheet",
"that",
"was",
"just",
"added",
"be",
"really",
"loaded",
"to",
"be",
"able",
"to",
"extract",
"potential",
"import",
"-",
"ed",
"stylesheets",
".",
"It",
"invokes",
"notifyStylesheetAdded",
"once",
"the",
"sheet",
"is",
"loaded",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js#L124-L153
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js
|
function () {
var added = {},
current,
newStatus;
current = this.stylesheets;
newStatus = related().stylesheets;
Object.keys(newStatus).forEach(function (v, i) {
if (!current[v]) {
added[v] = newStatus[v];
}
});
Object.keys(added).forEach(function (v, i) {
_transport.send(JSON.stringify({
method: "StylesheetAdded",
href: v,
roots: [added[v]]
}));
});
this.stylesheets = newStatus;
}
|
javascript
|
function () {
var added = {},
current,
newStatus;
current = this.stylesheets;
newStatus = related().stylesheets;
Object.keys(newStatus).forEach(function (v, i) {
if (!current[v]) {
added[v] = newStatus[v];
}
});
Object.keys(added).forEach(function (v, i) {
_transport.send(JSON.stringify({
method: "StylesheetAdded",
href: v,
roots: [added[v]]
}));
});
this.stylesheets = newStatus;
}
|
[
"function",
"(",
")",
"{",
"var",
"added",
"=",
"{",
"}",
",",
"current",
",",
"newStatus",
";",
"current",
"=",
"this",
".",
"stylesheets",
";",
"newStatus",
"=",
"related",
"(",
")",
".",
"stylesheets",
";",
"Object",
".",
"keys",
"(",
"newStatus",
")",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"i",
")",
"{",
"if",
"(",
"!",
"current",
"[",
"v",
"]",
")",
"{",
"added",
"[",
"v",
"]",
"=",
"newStatus",
"[",
"v",
"]",
";",
"}",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"added",
")",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"i",
")",
"{",
"_transport",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"method",
":",
"\"StylesheetAdded\"",
",",
"href",
":",
"v",
",",
"roots",
":",
"[",
"added",
"[",
"v",
"]",
"]",
"}",
")",
")",
";",
"}",
")",
";",
"this",
".",
"stylesheets",
"=",
"newStatus",
";",
"}"
] |
Send a notification for the stylesheet added and
its import-ed styleshets based on document.stylesheets diff
from previous status. It also updates stylesheets status.
|
[
"Send",
"a",
"notification",
"for",
"the",
"stylesheet",
"added",
"and",
"its",
"import",
"-",
"ed",
"styleshets",
"based",
"on",
"document",
".",
"stylesheets",
"diff",
"from",
"previous",
"status",
".",
"It",
"also",
"updates",
"stylesheets",
"status",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js#L169-L192
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js
|
function () {
var self = this;
var removed = {},
newStatus,
current;
current = self.stylesheets;
newStatus = related().stylesheets;
Object.keys(current).forEach(function (v, i) {
if (!newStatus[v]) {
removed[v] = current[v];
// remove node created by setStylesheetText if any
self.onStylesheetRemoved(current[v]);
}
});
Object.keys(removed).forEach(function (v, i) {
_transport.send(JSON.stringify({
method: "StylesheetRemoved",
href: v,
roots: [removed[v]]
}));
});
self.stylesheets = newStatus;
}
|
javascript
|
function () {
var self = this;
var removed = {},
newStatus,
current;
current = self.stylesheets;
newStatus = related().stylesheets;
Object.keys(current).forEach(function (v, i) {
if (!newStatus[v]) {
removed[v] = current[v];
// remove node created by setStylesheetText if any
self.onStylesheetRemoved(current[v]);
}
});
Object.keys(removed).forEach(function (v, i) {
_transport.send(JSON.stringify({
method: "StylesheetRemoved",
href: v,
roots: [removed[v]]
}));
});
self.stylesheets = newStatus;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"removed",
"=",
"{",
"}",
",",
"newStatus",
",",
"current",
";",
"current",
"=",
"self",
".",
"stylesheets",
";",
"newStatus",
"=",
"related",
"(",
")",
".",
"stylesheets",
";",
"Object",
".",
"keys",
"(",
"current",
")",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"i",
")",
"{",
"if",
"(",
"!",
"newStatus",
"[",
"v",
"]",
")",
"{",
"removed",
"[",
"v",
"]",
"=",
"current",
"[",
"v",
"]",
";",
"self",
".",
"onStylesheetRemoved",
"(",
"current",
"[",
"v",
"]",
")",
";",
"}",
"}",
")",
";",
"Object",
".",
"keys",
"(",
"removed",
")",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"i",
")",
"{",
"_transport",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"method",
":",
"\"StylesheetRemoved\"",
",",
"href",
":",
"v",
",",
"roots",
":",
"[",
"removed",
"[",
"v",
"]",
"]",
"}",
")",
")",
";",
"}",
")",
";",
"self",
".",
"stylesheets",
"=",
"newStatus",
";",
"}"
] |
Send a notification for the removed stylesheet and
its import-ed styleshets based on document.stylesheets diff
from previous status. It also updates stylesheets status.
|
[
"Send",
"a",
"notification",
"for",
"the",
"removed",
"stylesheet",
"and",
"its",
"import",
"-",
"ed",
"styleshets",
"based",
"on",
"document",
".",
"stylesheets",
"diff",
"from",
"previous",
"status",
".",
"It",
"also",
"updates",
"stylesheets",
"status",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js#L199-L226
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js
|
start
|
function start(document, transport) {
_transport = transport;
_document = document;
// start listening to node changes
_enableListeners();
var rel = related();
// send the current status of related docs.
_transport.send(JSON.stringify({
method: "DocumentRelated",
related: rel
}));
// initialize stylesheets with current status for further notifications.
CSS.stylesheets = rel.stylesheets;
}
|
javascript
|
function start(document, transport) {
_transport = transport;
_document = document;
// start listening to node changes
_enableListeners();
var rel = related();
// send the current status of related docs.
_transport.send(JSON.stringify({
method: "DocumentRelated",
related: rel
}));
// initialize stylesheets with current status for further notifications.
CSS.stylesheets = rel.stylesheets;
}
|
[
"function",
"start",
"(",
"document",
",",
"transport",
")",
"{",
"_transport",
"=",
"transport",
";",
"_document",
"=",
"document",
";",
"_enableListeners",
"(",
")",
";",
"var",
"rel",
"=",
"related",
"(",
")",
";",
"_transport",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"method",
":",
"\"DocumentRelated\"",
",",
"related",
":",
"rel",
"}",
")",
")",
";",
"CSS",
".",
"stylesheets",
"=",
"rel",
".",
"stylesheets",
";",
"}"
] |
Start listening for events and send initial related documents message.
@param {HTMLDocument} document
@param {object} transport Live development transport connection
|
[
"Start",
"listening",
"for",
"events",
"and",
"send",
"initial",
"related",
"documents",
"message",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/DocumentObserver.js#L303-L318
|
train
|
adobe/brackets
|
src/utils/NativeApp.js
|
openLiveBrowser
|
function openLiveBrowser(url, enableRemoteDebugging) {
var result = new $.Deferred();
brackets.app.openLiveBrowser(url, !!enableRemoteDebugging, function onRun(err, pid) {
if (!err) {
// Undefined ids never get removed from list, so don't push them on
if (pid !== undefined) {
liveBrowserOpenedPIDs.push(pid);
}
result.resolve(pid);
} else {
result.reject(_browserErrToFileError(err));
}
});
return result.promise();
}
|
javascript
|
function openLiveBrowser(url, enableRemoteDebugging) {
var result = new $.Deferred();
brackets.app.openLiveBrowser(url, !!enableRemoteDebugging, function onRun(err, pid) {
if (!err) {
// Undefined ids never get removed from list, so don't push them on
if (pid !== undefined) {
liveBrowserOpenedPIDs.push(pid);
}
result.resolve(pid);
} else {
result.reject(_browserErrToFileError(err));
}
});
return result.promise();
}
|
[
"function",
"openLiveBrowser",
"(",
"url",
",",
"enableRemoteDebugging",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"brackets",
".",
"app",
".",
"openLiveBrowser",
"(",
"url",
",",
"!",
"!",
"enableRemoteDebugging",
",",
"function",
"onRun",
"(",
"err",
",",
"pid",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"if",
"(",
"pid",
"!==",
"undefined",
")",
"{",
"liveBrowserOpenedPIDs",
".",
"push",
"(",
"pid",
")",
";",
"}",
"result",
".",
"resolve",
"(",
"pid",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
"_browserErrToFileError",
"(",
"err",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
openLiveBrowser
Open the given URL in the user's system browser, optionally enabling debugging.
@param {string} url The URL to open.
@param {boolean=} enableRemoteDebugging Whether to turn on remote debugging. Default false.
@return {$.Promise}
|
[
"openLiveBrowser",
"Open",
"the",
"given",
"URL",
"in",
"the",
"user",
"s",
"system",
"browser",
"optionally",
"enabling",
"debugging",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/NativeApp.js#L51-L67
|
train
|
adobe/brackets
|
src/LiveDevelopment/Servers/BaseServer.js
|
BaseServer
|
function BaseServer(config) {
this._baseUrl = config.baseUrl;
this._root = config.root; // ProjectManager.getProjectRoot().fullPath
this._pathResolver = config.pathResolver; // ProjectManager.makeProjectRelativeIfPossible(doc.file.fullPath)
this._liveDocuments = {};
}
|
javascript
|
function BaseServer(config) {
this._baseUrl = config.baseUrl;
this._root = config.root; // ProjectManager.getProjectRoot().fullPath
this._pathResolver = config.pathResolver; // ProjectManager.makeProjectRelativeIfPossible(doc.file.fullPath)
this._liveDocuments = {};
}
|
[
"function",
"BaseServer",
"(",
"config",
")",
"{",
"this",
".",
"_baseUrl",
"=",
"config",
".",
"baseUrl",
";",
"this",
".",
"_root",
"=",
"config",
".",
"root",
";",
"this",
".",
"_pathResolver",
"=",
"config",
".",
"pathResolver",
";",
"this",
".",
"_liveDocuments",
"=",
"{",
"}",
";",
"}"
] |
Base class for live preview servers
Configuration parameters for this server:
- baseUrl - Optional base URL (populated by the current project)
- pathResolver - Function to covert absolute native paths to project relative paths
- root - Native path to the project root (and base URL)
@constructor
@param {!{baseUrl: string, root: string, pathResolver: function(string): string}} config
|
[
"Base",
"class",
"for",
"live",
"preview",
"servers"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Servers/BaseServer.js#L40-L45
|
train
|
adobe/brackets
|
src/extensions/default/HealthData/HealthDataUtils.js
|
getUserInstalledExtensions
|
function getUserInstalledExtensions() {
var result = new $.Deferred();
if (!ExtensionManager.hasDownloadedRegistry) {
ExtensionManager.downloadRegistry().done(function () {
result.resolve(getUserExtensionsPresentInRegistry(ExtensionManager.extensions));
})
.fail(function () {
result.resolve([]);
});
} else {
result.resolve(getUserExtensionsPresentInRegistry(ExtensionManager.extensions));
}
return result.promise();
}
|
javascript
|
function getUserInstalledExtensions() {
var result = new $.Deferred();
if (!ExtensionManager.hasDownloadedRegistry) {
ExtensionManager.downloadRegistry().done(function () {
result.resolve(getUserExtensionsPresentInRegistry(ExtensionManager.extensions));
})
.fail(function () {
result.resolve([]);
});
} else {
result.resolve(getUserExtensionsPresentInRegistry(ExtensionManager.extensions));
}
return result.promise();
}
|
[
"function",
"getUserInstalledExtensions",
"(",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"!",
"ExtensionManager",
".",
"hasDownloadedRegistry",
")",
"{",
"ExtensionManager",
".",
"downloadRegistry",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
"getUserExtensionsPresentInRegistry",
"(",
"ExtensionManager",
".",
"extensions",
")",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
"[",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"resolve",
"(",
"getUserExtensionsPresentInRegistry",
"(",
"ExtensionManager",
".",
"extensions",
")",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Utility function to get the user installed extension which are present in the registry
|
[
"Utility",
"function",
"to",
"get",
"the",
"user",
"installed",
"extension",
"which",
"are",
"present",
"in",
"the",
"registry"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/HealthData/HealthDataUtils.js#L53-L68
|
train
|
adobe/brackets
|
src/extensions/default/HealthData/HealthDataUtils.js
|
getUserInstalledTheme
|
function getUserInstalledTheme() {
var result = new $.Deferred();
var installedTheme = themesPref.get("theme"),
bracketsTheme;
if (installedTheme === "light-theme" || installedTheme === "dark-theme") {
return result.resolve(installedTheme);
}
if (!ExtensionManager.hasDownloadedRegistry) {
ExtensionManager.downloadRegistry().done(function () {
bracketsTheme = ExtensionManager.extensions[installedTheme];
if (bracketsTheme && bracketsTheme.installInfo && bracketsTheme.installInfo.locationType === ExtensionManager.LOCATION_USER && bracketsTheme.registryInfo) {
result.resolve(installedTheme);
} else {
result.reject();
}
})
.fail(function () {
result.reject();
});
} else {
bracketsTheme = ExtensionManager.extensions[installedTheme];
if (bracketsTheme && bracketsTheme.installInfo && bracketsTheme.installInfo.locationType === ExtensionManager.LOCATION_USER && bracketsTheme.registryInfo) {
result.resolve(installedTheme);
} else {
result.reject();
}
}
return result.promise();
}
|
javascript
|
function getUserInstalledTheme() {
var result = new $.Deferred();
var installedTheme = themesPref.get("theme"),
bracketsTheme;
if (installedTheme === "light-theme" || installedTheme === "dark-theme") {
return result.resolve(installedTheme);
}
if (!ExtensionManager.hasDownloadedRegistry) {
ExtensionManager.downloadRegistry().done(function () {
bracketsTheme = ExtensionManager.extensions[installedTheme];
if (bracketsTheme && bracketsTheme.installInfo && bracketsTheme.installInfo.locationType === ExtensionManager.LOCATION_USER && bracketsTheme.registryInfo) {
result.resolve(installedTheme);
} else {
result.reject();
}
})
.fail(function () {
result.reject();
});
} else {
bracketsTheme = ExtensionManager.extensions[installedTheme];
if (bracketsTheme && bracketsTheme.installInfo && bracketsTheme.installInfo.locationType === ExtensionManager.LOCATION_USER && bracketsTheme.registryInfo) {
result.resolve(installedTheme);
} else {
result.reject();
}
}
return result.promise();
}
|
[
"function",
"getUserInstalledTheme",
"(",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"installedTheme",
"=",
"themesPref",
".",
"get",
"(",
"\"theme\"",
")",
",",
"bracketsTheme",
";",
"if",
"(",
"installedTheme",
"===",
"\"light-theme\"",
"||",
"installedTheme",
"===",
"\"dark-theme\"",
")",
"{",
"return",
"result",
".",
"resolve",
"(",
"installedTheme",
")",
";",
"}",
"if",
"(",
"!",
"ExtensionManager",
".",
"hasDownloadedRegistry",
")",
"{",
"ExtensionManager",
".",
"downloadRegistry",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"bracketsTheme",
"=",
"ExtensionManager",
".",
"extensions",
"[",
"installedTheme",
"]",
";",
"if",
"(",
"bracketsTheme",
"&&",
"bracketsTheme",
".",
"installInfo",
"&&",
"bracketsTheme",
".",
"installInfo",
".",
"locationType",
"===",
"ExtensionManager",
".",
"LOCATION_USER",
"&&",
"bracketsTheme",
".",
"registryInfo",
")",
"{",
"result",
".",
"resolve",
"(",
"installedTheme",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"bracketsTheme",
"=",
"ExtensionManager",
".",
"extensions",
"[",
"installedTheme",
"]",
";",
"if",
"(",
"bracketsTheme",
"&&",
"bracketsTheme",
".",
"installInfo",
"&&",
"bracketsTheme",
".",
"installInfo",
".",
"locationType",
"===",
"ExtensionManager",
".",
"LOCATION_USER",
"&&",
"bracketsTheme",
".",
"registryInfo",
")",
"{",
"result",
".",
"resolve",
"(",
"installedTheme",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Utility function to get the user installed theme which are present in the registry
|
[
"Utility",
"function",
"to",
"get",
"the",
"user",
"installed",
"theme",
"which",
"are",
"present",
"in",
"the",
"registry"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/HealthData/HealthDataUtils.js#L73-L105
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
normalizeKeyDescriptorString
|
function normalizeKeyDescriptorString(origDescriptor) {
var hasMacCtrl = false,
hasCtrl = false,
hasAlt = false,
hasShift = false,
key = "",
error = false;
function _compareModifierString(left, right) {
if (!left || !right) {
return false;
}
left = left.trim().toLowerCase();
right = right.trim().toLowerCase();
return (left.length > 0 && left === right);
}
origDescriptor.split("-").forEach(function parseDescriptor(ele, i, arr) {
if (_compareModifierString("ctrl", ele)) {
if (brackets.platform === "mac") {
hasMacCtrl = true;
} else {
hasCtrl = true;
}
} else if (_compareModifierString("cmd", ele)) {
if (brackets.platform === "mac") {
hasCtrl = true;
} else {
error = true;
}
} else if (_compareModifierString("alt", ele)) {
hasAlt = true;
} else if (_compareModifierString("opt", ele)) {
if (brackets.platform === "mac") {
hasAlt = true;
} else {
error = true;
}
} else if (_compareModifierString("shift", ele)) {
hasShift = true;
} else if (key.length > 0) {
console.log("KeyBindingManager normalizeKeyDescriptorString() - Multiple keys defined. Using key: " + key + " from: " + origDescriptor);
error = true;
} else {
key = ele;
}
});
if (error) {
return null;
}
// Check to see if the binding is for "-".
if (key === "" && origDescriptor.search(/^.+--$/) !== -1) {
key = "-";
}
// '+' char is valid if it's the only key. Keyboard shortcut strings should use
// unicode characters (unescaped). Keyboard shortcut display strings may use
// unicode escape sequences (e.g. \u20AC euro sign)
if ((key.indexOf("+")) >= 0 && (key.length > 1)) {
return null;
}
// Ensure that the first letter of the key name is in upper case and the rest are
// in lower case. i.e. 'a' => 'A' and 'up' => 'Up'
if (/^[a-z]/i.test(key)) {
key = _.capitalize(key.toLowerCase());
}
// Also make sure that the second word of PageUp/PageDown has the first letter in upper case.
if (/^Page/.test(key)) {
key = key.replace(/(up|down)$/, function (match, p1) {
return _.capitalize(p1);
});
}
// No restriction on single character key yet, but other key names are restricted to either
// Function keys or those listed in _keyNames array.
if (key.length > 1 && !/F\d+/.test(key) &&
_keyNames.indexOf(key) === -1) {
return null;
}
return _buildKeyDescriptor(hasMacCtrl, hasCtrl, hasAlt, hasShift, key);
}
|
javascript
|
function normalizeKeyDescriptorString(origDescriptor) {
var hasMacCtrl = false,
hasCtrl = false,
hasAlt = false,
hasShift = false,
key = "",
error = false;
function _compareModifierString(left, right) {
if (!left || !right) {
return false;
}
left = left.trim().toLowerCase();
right = right.trim().toLowerCase();
return (left.length > 0 && left === right);
}
origDescriptor.split("-").forEach(function parseDescriptor(ele, i, arr) {
if (_compareModifierString("ctrl", ele)) {
if (brackets.platform === "mac") {
hasMacCtrl = true;
} else {
hasCtrl = true;
}
} else if (_compareModifierString("cmd", ele)) {
if (brackets.platform === "mac") {
hasCtrl = true;
} else {
error = true;
}
} else if (_compareModifierString("alt", ele)) {
hasAlt = true;
} else if (_compareModifierString("opt", ele)) {
if (brackets.platform === "mac") {
hasAlt = true;
} else {
error = true;
}
} else if (_compareModifierString("shift", ele)) {
hasShift = true;
} else if (key.length > 0) {
console.log("KeyBindingManager normalizeKeyDescriptorString() - Multiple keys defined. Using key: " + key + " from: " + origDescriptor);
error = true;
} else {
key = ele;
}
});
if (error) {
return null;
}
// Check to see if the binding is for "-".
if (key === "" && origDescriptor.search(/^.+--$/) !== -1) {
key = "-";
}
// '+' char is valid if it's the only key. Keyboard shortcut strings should use
// unicode characters (unescaped). Keyboard shortcut display strings may use
// unicode escape sequences (e.g. \u20AC euro sign)
if ((key.indexOf("+")) >= 0 && (key.length > 1)) {
return null;
}
// Ensure that the first letter of the key name is in upper case and the rest are
// in lower case. i.e. 'a' => 'A' and 'up' => 'Up'
if (/^[a-z]/i.test(key)) {
key = _.capitalize(key.toLowerCase());
}
// Also make sure that the second word of PageUp/PageDown has the first letter in upper case.
if (/^Page/.test(key)) {
key = key.replace(/(up|down)$/, function (match, p1) {
return _.capitalize(p1);
});
}
// No restriction on single character key yet, but other key names are restricted to either
// Function keys or those listed in _keyNames array.
if (key.length > 1 && !/F\d+/.test(key) &&
_keyNames.indexOf(key) === -1) {
return null;
}
return _buildKeyDescriptor(hasMacCtrl, hasCtrl, hasAlt, hasShift, key);
}
|
[
"function",
"normalizeKeyDescriptorString",
"(",
"origDescriptor",
")",
"{",
"var",
"hasMacCtrl",
"=",
"false",
",",
"hasCtrl",
"=",
"false",
",",
"hasAlt",
"=",
"false",
",",
"hasShift",
"=",
"false",
",",
"key",
"=",
"\"\"",
",",
"error",
"=",
"false",
";",
"function",
"_compareModifierString",
"(",
"left",
",",
"right",
")",
"{",
"if",
"(",
"!",
"left",
"||",
"!",
"right",
")",
"{",
"return",
"false",
";",
"}",
"left",
"=",
"left",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"right",
"=",
"right",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"return",
"(",
"left",
".",
"length",
">",
"0",
"&&",
"left",
"===",
"right",
")",
";",
"}",
"origDescriptor",
".",
"split",
"(",
"\"-\"",
")",
".",
"forEach",
"(",
"function",
"parseDescriptor",
"(",
"ele",
",",
"i",
",",
"arr",
")",
"{",
"if",
"(",
"_compareModifierString",
"(",
"\"ctrl\"",
",",
"ele",
")",
")",
"{",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"hasMacCtrl",
"=",
"true",
";",
"}",
"else",
"{",
"hasCtrl",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"_compareModifierString",
"(",
"\"cmd\"",
",",
"ele",
")",
")",
"{",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"hasCtrl",
"=",
"true",
";",
"}",
"else",
"{",
"error",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"_compareModifierString",
"(",
"\"alt\"",
",",
"ele",
")",
")",
"{",
"hasAlt",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"_compareModifierString",
"(",
"\"opt\"",
",",
"ele",
")",
")",
"{",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"hasAlt",
"=",
"true",
";",
"}",
"else",
"{",
"error",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"_compareModifierString",
"(",
"\"shift\"",
",",
"ele",
")",
")",
"{",
"hasShift",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"key",
".",
"length",
">",
"0",
")",
"{",
"console",
".",
"log",
"(",
"\"KeyBindingManager normalizeKeyDescriptorString() - Multiple keys defined. Using key: \"",
"+",
"key",
"+",
"\" from: \"",
"+",
"origDescriptor",
")",
";",
"error",
"=",
"true",
";",
"}",
"else",
"{",
"key",
"=",
"ele",
";",
"}",
"}",
")",
";",
"if",
"(",
"error",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"key",
"===",
"\"\"",
"&&",
"origDescriptor",
".",
"search",
"(",
"/",
"^.+--$",
"/",
")",
"!==",
"-",
"1",
")",
"{",
"key",
"=",
"\"-\"",
";",
"}",
"if",
"(",
"(",
"key",
".",
"indexOf",
"(",
"\"+\"",
")",
")",
">=",
"0",
"&&",
"(",
"key",
".",
"length",
">",
"1",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"/",
"^[a-z]",
"/",
"i",
".",
"test",
"(",
"key",
")",
")",
"{",
"key",
"=",
"_",
".",
"capitalize",
"(",
"key",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
"if",
"(",
"/",
"^Page",
"/",
".",
"test",
"(",
"key",
")",
")",
"{",
"key",
"=",
"key",
".",
"replace",
"(",
"/",
"(up|down)$",
"/",
",",
"function",
"(",
"match",
",",
"p1",
")",
"{",
"return",
"_",
".",
"capitalize",
"(",
"p1",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"key",
".",
"length",
">",
"1",
"&&",
"!",
"/",
"F\\d+",
"/",
".",
"test",
"(",
"key",
")",
"&&",
"_keyNames",
".",
"indexOf",
"(",
"key",
")",
"===",
"-",
"1",
")",
"{",
"return",
"null",
";",
"}",
"return",
"_buildKeyDescriptor",
"(",
"hasMacCtrl",
",",
"hasCtrl",
",",
"hasAlt",
",",
"hasShift",
",",
"key",
")",
";",
"}"
] |
normalizes the incoming key descriptor so the modifier keys are always specified in the correct order
@param {string} The string for a key descriptor, can be in any order, the result will be Ctrl-Alt-Shift-<Key>
@return {string} The normalized key descriptor or null if the descriptor invalid
|
[
"normalizes",
"the",
"incoming",
"key",
"descriptor",
"so",
"the",
"modifier",
"keys",
"are",
"always",
"specified",
"in",
"the",
"correct",
"order"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L339-L425
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
_translateKeyboardEvent
|
function _translateKeyboardEvent(event) {
var hasMacCtrl = (brackets.platform === "mac") ? (event.ctrlKey) : false,
hasCtrl = (brackets.platform !== "mac") ? (event.ctrlKey) : (event.metaKey),
hasAlt = (event.altKey),
hasShift = (event.shiftKey),
key = String.fromCharCode(event.keyCode);
//From the W3C, if we can get the KeyboardEvent.keyIdentifier then look here
//As that will let us use keys like then function keys "F5" for commands. The
//full set of values we can use is here
//http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/keyset.html#KeySet-Set
var ident = event.keyIdentifier;
if (ident) {
if (ident.charAt(0) === "U" && ident.charAt(1) === "+") {
//This is a unicode code point like "U+002A", get the 002A and use that
key = String.fromCharCode(parseInt(ident.substring(2), 16));
} else {
//This is some non-character key, just use the raw identifier
key = ident;
}
}
// Translate some keys to their common names
if (key === "\t") {
key = "Tab";
} else if (key === " ") {
key = "Space";
} else if (key === "\b") {
key = "Backspace";
} else if (key === "Help") {
key = "Insert";
} else if (event.keyCode === KeyEvent.DOM_VK_DELETE) {
key = "Delete";
} else {
key = _mapKeycodeToKey(event.keyCode, key);
}
return _buildKeyDescriptor(hasMacCtrl, hasCtrl, hasAlt, hasShift, key);
}
|
javascript
|
function _translateKeyboardEvent(event) {
var hasMacCtrl = (brackets.platform === "mac") ? (event.ctrlKey) : false,
hasCtrl = (brackets.platform !== "mac") ? (event.ctrlKey) : (event.metaKey),
hasAlt = (event.altKey),
hasShift = (event.shiftKey),
key = String.fromCharCode(event.keyCode);
//From the W3C, if we can get the KeyboardEvent.keyIdentifier then look here
//As that will let us use keys like then function keys "F5" for commands. The
//full set of values we can use is here
//http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/keyset.html#KeySet-Set
var ident = event.keyIdentifier;
if (ident) {
if (ident.charAt(0) === "U" && ident.charAt(1) === "+") {
//This is a unicode code point like "U+002A", get the 002A and use that
key = String.fromCharCode(parseInt(ident.substring(2), 16));
} else {
//This is some non-character key, just use the raw identifier
key = ident;
}
}
// Translate some keys to their common names
if (key === "\t") {
key = "Tab";
} else if (key === " ") {
key = "Space";
} else if (key === "\b") {
key = "Backspace";
} else if (key === "Help") {
key = "Insert";
} else if (event.keyCode === KeyEvent.DOM_VK_DELETE) {
key = "Delete";
} else {
key = _mapKeycodeToKey(event.keyCode, key);
}
return _buildKeyDescriptor(hasMacCtrl, hasCtrl, hasAlt, hasShift, key);
}
|
[
"function",
"_translateKeyboardEvent",
"(",
"event",
")",
"{",
"var",
"hasMacCtrl",
"=",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"?",
"(",
"event",
".",
"ctrlKey",
")",
":",
"false",
",",
"hasCtrl",
"=",
"(",
"brackets",
".",
"platform",
"!==",
"\"mac\"",
")",
"?",
"(",
"event",
".",
"ctrlKey",
")",
":",
"(",
"event",
".",
"metaKey",
")",
",",
"hasAlt",
"=",
"(",
"event",
".",
"altKey",
")",
",",
"hasShift",
"=",
"(",
"event",
".",
"shiftKey",
")",
",",
"key",
"=",
"String",
".",
"fromCharCode",
"(",
"event",
".",
"keyCode",
")",
";",
"var",
"ident",
"=",
"event",
".",
"keyIdentifier",
";",
"if",
"(",
"ident",
")",
"{",
"if",
"(",
"ident",
".",
"charAt",
"(",
"0",
")",
"===",
"\"U\"",
"&&",
"ident",
".",
"charAt",
"(",
"1",
")",
"===",
"\"+\"",
")",
"{",
"key",
"=",
"String",
".",
"fromCharCode",
"(",
"parseInt",
"(",
"ident",
".",
"substring",
"(",
"2",
")",
",",
"16",
")",
")",
";",
"}",
"else",
"{",
"key",
"=",
"ident",
";",
"}",
"}",
"if",
"(",
"key",
"===",
"\"\\t\"",
")",
"\\t",
"else",
"{",
"key",
"=",
"\"Tab\"",
";",
"}",
"if",
"(",
"key",
"===",
"\" \"",
")",
"{",
"key",
"=",
"\"Space\"",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"\"\\b\"",
")",
"\\b",
"else",
"{",
"key",
"=",
"\"Backspace\"",
";",
"}",
"}"
] |
Takes a keyboard event and translates it into a key in a key map
|
[
"Takes",
"a",
"keyboard",
"event",
"and",
"translates",
"it",
"into",
"a",
"key",
"in",
"a",
"key",
"map"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L482-L520
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
formatKeyDescriptor
|
function formatKeyDescriptor(descriptor) {
var displayStr;
if (brackets.platform === "mac") {
displayStr = descriptor.replace(/-(?!$)/g, ""); // remove dashes
displayStr = displayStr.replace("Ctrl", "\u2303"); // Ctrl > control symbol
displayStr = displayStr.replace("Cmd", "\u2318"); // Cmd > command symbol
displayStr = displayStr.replace("Shift", "\u21E7"); // Shift > shift symbol
displayStr = displayStr.replace("Alt", "\u2325"); // Alt > option symbol
} else {
displayStr = descriptor.replace("Ctrl", Strings.KEYBOARD_CTRL);
displayStr = displayStr.replace("Shift", Strings.KEYBOARD_SHIFT);
displayStr = displayStr.replace(/-(?!$)/g, "+");
}
displayStr = displayStr.replace("Space", Strings.KEYBOARD_SPACE);
displayStr = displayStr.replace("PageUp", Strings.KEYBOARD_PAGE_UP);
displayStr = displayStr.replace("PageDown", Strings.KEYBOARD_PAGE_DOWN);
displayStr = displayStr.replace("Home", Strings.KEYBOARD_HOME);
displayStr = displayStr.replace("End", Strings.KEYBOARD_END);
displayStr = displayStr.replace("Ins", Strings.KEYBOARD_INSERT);
displayStr = displayStr.replace("Del", Strings.KEYBOARD_DELETE);
return displayStr;
}
|
javascript
|
function formatKeyDescriptor(descriptor) {
var displayStr;
if (brackets.platform === "mac") {
displayStr = descriptor.replace(/-(?!$)/g, ""); // remove dashes
displayStr = displayStr.replace("Ctrl", "\u2303"); // Ctrl > control symbol
displayStr = displayStr.replace("Cmd", "\u2318"); // Cmd > command symbol
displayStr = displayStr.replace("Shift", "\u21E7"); // Shift > shift symbol
displayStr = displayStr.replace("Alt", "\u2325"); // Alt > option symbol
} else {
displayStr = descriptor.replace("Ctrl", Strings.KEYBOARD_CTRL);
displayStr = displayStr.replace("Shift", Strings.KEYBOARD_SHIFT);
displayStr = displayStr.replace(/-(?!$)/g, "+");
}
displayStr = displayStr.replace("Space", Strings.KEYBOARD_SPACE);
displayStr = displayStr.replace("PageUp", Strings.KEYBOARD_PAGE_UP);
displayStr = displayStr.replace("PageDown", Strings.KEYBOARD_PAGE_DOWN);
displayStr = displayStr.replace("Home", Strings.KEYBOARD_HOME);
displayStr = displayStr.replace("End", Strings.KEYBOARD_END);
displayStr = displayStr.replace("Ins", Strings.KEYBOARD_INSERT);
displayStr = displayStr.replace("Del", Strings.KEYBOARD_DELETE);
return displayStr;
}
|
[
"function",
"formatKeyDescriptor",
"(",
"descriptor",
")",
"{",
"var",
"displayStr",
";",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"displayStr",
"=",
"descriptor",
".",
"replace",
"(",
"/",
"-(?!$)",
"/",
"g",
",",
"\"\"",
")",
";",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Ctrl\"",
",",
"\"\\u2303\"",
")",
";",
"\\u2303",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Cmd\"",
",",
"\"\\u2318\"",
")",
";",
"\\u2318",
"}",
"else",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Shift\"",
",",
"\"\\u21E7\"",
")",
";",
"\\u21E7",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Alt\"",
",",
"\"\\u2325\"",
")",
";",
"\\u2325",
"{",
"displayStr",
"=",
"descriptor",
".",
"replace",
"(",
"\"Ctrl\"",
",",
"Strings",
".",
"KEYBOARD_CTRL",
")",
";",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Shift\"",
",",
"Strings",
".",
"KEYBOARD_SHIFT",
")",
";",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"/",
"-(?!$)",
"/",
"g",
",",
"\"+\"",
")",
";",
"}",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Space\"",
",",
"Strings",
".",
"KEYBOARD_SPACE",
")",
";",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"PageUp\"",
",",
"Strings",
".",
"KEYBOARD_PAGE_UP",
")",
";",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"PageDown\"",
",",
"Strings",
".",
"KEYBOARD_PAGE_DOWN",
")",
";",
"displayStr",
"=",
"displayStr",
".",
"replace",
"(",
"\"Home\"",
",",
"Strings",
".",
"KEYBOARD_HOME",
")",
";",
"}"
] |
Convert normalized key representation to display appropriate for platform.
@param {!string} descriptor Normalized key descriptor.
@return {!string} Display/Operating system appropriate string
|
[
"Convert",
"normalized",
"key",
"representation",
"to",
"display",
"appropriate",
"for",
"platform",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L527-L553
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
removeBinding
|
function removeBinding(key, platform) {
if (!key || ((platform !== null) && (platform !== undefined) && (platform !== brackets.platform))) {
return;
}
var normalizedKey = normalizeKeyDescriptorString(key);
if (!normalizedKey) {
console.log("Failed to normalize " + key);
} else if (_isKeyAssigned(normalizedKey)) {
var binding = _keyMap[normalizedKey],
command = CommandManager.get(binding.commandID),
bindings = _commandMap[binding.commandID];
// delete key binding record
delete _keyMap[normalizedKey];
if (bindings) {
// delete mapping from command to key binding
_commandMap[binding.commandID] = bindings.filter(function (b) {
return (b.key !== normalizedKey);
});
if (command) {
command.trigger("keyBindingRemoved", {key: normalizedKey, displayKey: binding.displayKey});
}
}
}
}
|
javascript
|
function removeBinding(key, platform) {
if (!key || ((platform !== null) && (platform !== undefined) && (platform !== brackets.platform))) {
return;
}
var normalizedKey = normalizeKeyDescriptorString(key);
if (!normalizedKey) {
console.log("Failed to normalize " + key);
} else if (_isKeyAssigned(normalizedKey)) {
var binding = _keyMap[normalizedKey],
command = CommandManager.get(binding.commandID),
bindings = _commandMap[binding.commandID];
// delete key binding record
delete _keyMap[normalizedKey];
if (bindings) {
// delete mapping from command to key binding
_commandMap[binding.commandID] = bindings.filter(function (b) {
return (b.key !== normalizedKey);
});
if (command) {
command.trigger("keyBindingRemoved", {key: normalizedKey, displayKey: binding.displayKey});
}
}
}
}
|
[
"function",
"removeBinding",
"(",
"key",
",",
"platform",
")",
"{",
"if",
"(",
"!",
"key",
"||",
"(",
"(",
"platform",
"!==",
"null",
")",
"&&",
"(",
"platform",
"!==",
"undefined",
")",
"&&",
"(",
"platform",
"!==",
"brackets",
".",
"platform",
")",
")",
")",
"{",
"return",
";",
"}",
"var",
"normalizedKey",
"=",
"normalizeKeyDescriptorString",
"(",
"key",
")",
";",
"if",
"(",
"!",
"normalizedKey",
")",
"{",
"console",
".",
"log",
"(",
"\"Failed to normalize \"",
"+",
"key",
")",
";",
"}",
"else",
"if",
"(",
"_isKeyAssigned",
"(",
"normalizedKey",
")",
")",
"{",
"var",
"binding",
"=",
"_keyMap",
"[",
"normalizedKey",
"]",
",",
"command",
"=",
"CommandManager",
".",
"get",
"(",
"binding",
".",
"commandID",
")",
",",
"bindings",
"=",
"_commandMap",
"[",
"binding",
".",
"commandID",
"]",
";",
"delete",
"_keyMap",
"[",
"normalizedKey",
"]",
";",
"if",
"(",
"bindings",
")",
"{",
"_commandMap",
"[",
"binding",
".",
"commandID",
"]",
"=",
"bindings",
".",
"filter",
"(",
"function",
"(",
"b",
")",
"{",
"return",
"(",
"b",
".",
"key",
"!==",
"normalizedKey",
")",
";",
"}",
")",
";",
"if",
"(",
"command",
")",
"{",
"command",
".",
"trigger",
"(",
"\"keyBindingRemoved\"",
",",
"{",
"key",
":",
"normalizedKey",
",",
"displayKey",
":",
"binding",
".",
"displayKey",
"}",
")",
";",
"}",
"}",
"}",
"}"
] |
Remove a key binding from _keymap
@param {!string} key - a key-description string that may or may not be normalized.
@param {?string} platform - OS from which to remove the binding (all platforms if unspecified)
|
[
"Remove",
"a",
"key",
"binding",
"from",
"_keymap"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L570-L598
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
_handleKey
|
function _handleKey(key) {
if (_enabled && _keyMap[key]) {
// The execute() function returns a promise because some commands are async.
// Generally, commands decide whether they can run or not synchronously,
// and reject immediately, so we can test for that synchronously.
var promise = CommandManager.execute(_keyMap[key].commandID);
return (promise.state() !== "rejected");
}
return false;
}
|
javascript
|
function _handleKey(key) {
if (_enabled && _keyMap[key]) {
// The execute() function returns a promise because some commands are async.
// Generally, commands decide whether they can run or not synchronously,
// and reject immediately, so we can test for that synchronously.
var promise = CommandManager.execute(_keyMap[key].commandID);
return (promise.state() !== "rejected");
}
return false;
}
|
[
"function",
"_handleKey",
"(",
"key",
")",
"{",
"if",
"(",
"_enabled",
"&&",
"_keyMap",
"[",
"key",
"]",
")",
"{",
"var",
"promise",
"=",
"CommandManager",
".",
"execute",
"(",
"_keyMap",
"[",
"key",
"]",
".",
"commandID",
")",
";",
"return",
"(",
"promise",
".",
"state",
"(",
")",
"!==",
"\"rejected\"",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Process the keybinding for the current key.
@param {string} A key-description string.
@return {boolean} true if the key was processed, false otherwise
|
[
"Process",
"the",
"keybinding",
"for",
"the",
"current",
"key",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L811-L820
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
addBinding
|
function addBinding(command, keyBindings, platform) {
var commandID = "",
results;
if (!command) {
console.error("addBinding(): missing required parameter: command");
return;
}
if (!keyBindings) { return; }
if (typeof (command) === "string") {
commandID = command;
} else {
commandID = command.getID();
}
if (Array.isArray(keyBindings)) {
var keyBinding;
results = [];
// process platform-specific bindings first
keyBindings.sort(_sortByPlatform);
keyBindings.forEach(function addSingleBinding(keyBindingRequest) {
// attempt to add keybinding
keyBinding = _addBinding(commandID, keyBindingRequest, keyBindingRequest.platform);
if (keyBinding) {
results.push(keyBinding);
}
});
} else {
results = _addBinding(commandID, keyBindings, platform);
}
return results;
}
|
javascript
|
function addBinding(command, keyBindings, platform) {
var commandID = "",
results;
if (!command) {
console.error("addBinding(): missing required parameter: command");
return;
}
if (!keyBindings) { return; }
if (typeof (command) === "string") {
commandID = command;
} else {
commandID = command.getID();
}
if (Array.isArray(keyBindings)) {
var keyBinding;
results = [];
// process platform-specific bindings first
keyBindings.sort(_sortByPlatform);
keyBindings.forEach(function addSingleBinding(keyBindingRequest) {
// attempt to add keybinding
keyBinding = _addBinding(commandID, keyBindingRequest, keyBindingRequest.platform);
if (keyBinding) {
results.push(keyBinding);
}
});
} else {
results = _addBinding(commandID, keyBindings, platform);
}
return results;
}
|
[
"function",
"addBinding",
"(",
"command",
",",
"keyBindings",
",",
"platform",
")",
"{",
"var",
"commandID",
"=",
"\"\"",
",",
"results",
";",
"if",
"(",
"!",
"command",
")",
"{",
"console",
".",
"error",
"(",
"\"addBinding(): missing required parameter: command\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"keyBindings",
")",
"{",
"return",
";",
"}",
"if",
"(",
"typeof",
"(",
"command",
")",
"===",
"\"string\"",
")",
"{",
"commandID",
"=",
"command",
";",
"}",
"else",
"{",
"commandID",
"=",
"command",
".",
"getID",
"(",
")",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"keyBindings",
")",
")",
"{",
"var",
"keyBinding",
";",
"results",
"=",
"[",
"]",
";",
"keyBindings",
".",
"sort",
"(",
"_sortByPlatform",
")",
";",
"keyBindings",
".",
"forEach",
"(",
"function",
"addSingleBinding",
"(",
"keyBindingRequest",
")",
"{",
"keyBinding",
"=",
"_addBinding",
"(",
"commandID",
",",
"keyBindingRequest",
",",
"keyBindingRequest",
".",
"platform",
")",
";",
"if",
"(",
"keyBinding",
")",
"{",
"results",
".",
"push",
"(",
"keyBinding",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"results",
"=",
"_addBinding",
"(",
"commandID",
",",
"keyBindings",
",",
"platform",
")",
";",
"}",
"return",
"results",
";",
"}"
] |
Add one or more key bindings to a particular Command.
@param {!string | Command} command - A command ID or command object
@param {?({key: string, displayKey: string}|Array.<{key: string, displayKey: string, platform: string}>)} keyBindings
A single key binding or an array of keybindings. Example:
"Shift-Cmd-F". Mac and Win key equivalents are automatically
mapped to each other. Use displayKey property to display a different
string (e.g. "CMD+" instead of "CMD=").
@param {?string} platform The target OS of the keyBindings either
"mac", "win" or "linux". If undefined, all platforms not explicitly
defined will use the key binding.
NOTE: If platform is not specified, Ctrl will be replaced by Cmd for "mac" platform
@return {{key: string, displayKey:String}|Array.<{key: string, displayKey:String}>}
Returns record(s) for valid key binding(s)
|
[
"Add",
"one",
"or",
"more",
"key",
"bindings",
"to",
"a",
"particular",
"Command",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L850-L887
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
getKeyBindings
|
function getKeyBindings(command) {
var bindings = [],
commandID = "";
if (!command) {
console.error("getKeyBindings(): missing required parameter: command");
return [];
}
if (typeof (command) === "string") {
commandID = command;
} else {
commandID = command.getID();
}
bindings = _commandMap[commandID];
return bindings || [];
}
|
javascript
|
function getKeyBindings(command) {
var bindings = [],
commandID = "";
if (!command) {
console.error("getKeyBindings(): missing required parameter: command");
return [];
}
if (typeof (command) === "string") {
commandID = command;
} else {
commandID = command.getID();
}
bindings = _commandMap[commandID];
return bindings || [];
}
|
[
"function",
"getKeyBindings",
"(",
"command",
")",
"{",
"var",
"bindings",
"=",
"[",
"]",
",",
"commandID",
"=",
"\"\"",
";",
"if",
"(",
"!",
"command",
")",
"{",
"console",
".",
"error",
"(",
"\"getKeyBindings(): missing required parameter: command\"",
")",
";",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"typeof",
"(",
"command",
")",
"===",
"\"string\"",
")",
"{",
"commandID",
"=",
"command",
";",
"}",
"else",
"{",
"commandID",
"=",
"command",
".",
"getID",
"(",
")",
";",
"}",
"bindings",
"=",
"_commandMap",
"[",
"commandID",
"]",
";",
"return",
"bindings",
"||",
"[",
"]",
";",
"}"
] |
Retrieve key bindings currently associated with a command
@param {!string | Command} command - A command ID or command object
@return {!Array.<{{key: string, displayKey: string}}>} An array of associated key bindings.
|
[
"Retrieve",
"key",
"bindings",
"currently",
"associated",
"with",
"a",
"command"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L895-L912
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
_handleCommandRegistered
|
function _handleCommandRegistered(event, command) {
var commandId = command.getID(),
defaults = KeyboardPrefs[commandId];
if (defaults) {
addBinding(commandId, defaults);
}
}
|
javascript
|
function _handleCommandRegistered(event, command) {
var commandId = command.getID(),
defaults = KeyboardPrefs[commandId];
if (defaults) {
addBinding(commandId, defaults);
}
}
|
[
"function",
"_handleCommandRegistered",
"(",
"event",
",",
"command",
")",
"{",
"var",
"commandId",
"=",
"command",
".",
"getID",
"(",
")",
",",
"defaults",
"=",
"KeyboardPrefs",
"[",
"commandId",
"]",
";",
"if",
"(",
"defaults",
")",
"{",
"addBinding",
"(",
"commandId",
",",
"defaults",
")",
";",
"}",
"}"
] |
Adds default key bindings when commands are registered to CommandManager
@param {$.Event} event jQuery event
@param {Command} command Newly registered command
|
[
"Adds",
"default",
"key",
"bindings",
"when",
"commands",
"are",
"registered",
"to",
"CommandManager"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L919-L926
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
removeGlobalKeydownHook
|
function removeGlobalKeydownHook(hook) {
var index = _globalKeydownHooks.indexOf(hook);
if (index !== -1) {
_globalKeydownHooks.splice(index, 1);
}
}
|
javascript
|
function removeGlobalKeydownHook(hook) {
var index = _globalKeydownHooks.indexOf(hook);
if (index !== -1) {
_globalKeydownHooks.splice(index, 1);
}
}
|
[
"function",
"removeGlobalKeydownHook",
"(",
"hook",
")",
"{",
"var",
"index",
"=",
"_globalKeydownHooks",
".",
"indexOf",
"(",
"hook",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"_globalKeydownHooks",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"}"
] |
Removes a global keydown hook added by `addGlobalKeydownHook`.
Does not need to be the most recently added hook.
@param {function(Event): boolean} hook The global hook to remove.
|
[
"Removes",
"a",
"global",
"keydown",
"hook",
"added",
"by",
"addGlobalKeydownHook",
".",
"Does",
"not",
"need",
"to",
"be",
"the",
"most",
"recently",
"added",
"hook",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L964-L969
|
train
|
adobe/brackets
|
src/command/KeyBindingManager.js
|
_handleKeyEvent
|
function _handleKeyEvent(event) {
var i, handled = false;
for (i = _globalKeydownHooks.length - 1; i >= 0; i--) {
if (_globalKeydownHooks[i](event)) {
handled = true;
break;
}
}
_detectAltGrKeyDown(event);
if (!handled && _handleKey(_translateKeyboardEvent(event))) {
event.stopPropagation();
event.preventDefault();
}
}
|
javascript
|
function _handleKeyEvent(event) {
var i, handled = false;
for (i = _globalKeydownHooks.length - 1; i >= 0; i--) {
if (_globalKeydownHooks[i](event)) {
handled = true;
break;
}
}
_detectAltGrKeyDown(event);
if (!handled && _handleKey(_translateKeyboardEvent(event))) {
event.stopPropagation();
event.preventDefault();
}
}
|
[
"function",
"_handleKeyEvent",
"(",
"event",
")",
"{",
"var",
"i",
",",
"handled",
"=",
"false",
";",
"for",
"(",
"i",
"=",
"_globalKeydownHooks",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"_globalKeydownHooks",
"[",
"i",
"]",
"(",
"event",
")",
")",
"{",
"handled",
"=",
"true",
";",
"break",
";",
"}",
"}",
"_detectAltGrKeyDown",
"(",
"event",
")",
";",
"if",
"(",
"!",
"handled",
"&&",
"_handleKey",
"(",
"_translateKeyboardEvent",
"(",
"event",
")",
")",
")",
"{",
"event",
".",
"stopPropagation",
"(",
")",
";",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
"}"
] |
Handles a given keydown event, checking global hooks first before
deciding to handle it ourselves.
@param {Event} The keydown event to handle.
|
[
"Handles",
"a",
"given",
"keydown",
"event",
"checking",
"global",
"hooks",
"first",
"before",
"deciding",
"to",
"handle",
"it",
"ourselves",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/KeyBindingManager.js#L976-L989
|
train
|
adobe/brackets
|
src/command/CommandManager.js
|
register
|
function register(name, id, commandFn) {
if (_commands[id]) {
console.log("Attempting to register an already-registered command: " + id);
return null;
}
if (!name || !id || !commandFn) {
console.error("Attempting to register a command with a missing name, id, or command function:" + name + " " + id);
return null;
}
var command = new Command(name, id, commandFn);
_commands[id] = command;
exports.trigger("commandRegistered", command);
return command;
}
|
javascript
|
function register(name, id, commandFn) {
if (_commands[id]) {
console.log("Attempting to register an already-registered command: " + id);
return null;
}
if (!name || !id || !commandFn) {
console.error("Attempting to register a command with a missing name, id, or command function:" + name + " " + id);
return null;
}
var command = new Command(name, id, commandFn);
_commands[id] = command;
exports.trigger("commandRegistered", command);
return command;
}
|
[
"function",
"register",
"(",
"name",
",",
"id",
",",
"commandFn",
")",
"{",
"if",
"(",
"_commands",
"[",
"id",
"]",
")",
"{",
"console",
".",
"log",
"(",
"\"Attempting to register an already-registered command: \"",
"+",
"id",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"name",
"||",
"!",
"id",
"||",
"!",
"commandFn",
")",
"{",
"console",
".",
"error",
"(",
"\"Attempting to register a command with a missing name, id, or command function:\"",
"+",
"name",
"+",
"\" \"",
"+",
"id",
")",
";",
"return",
"null",
";",
"}",
"var",
"command",
"=",
"new",
"Command",
"(",
"name",
",",
"id",
",",
"commandFn",
")",
";",
"_commands",
"[",
"id",
"]",
"=",
"command",
";",
"exports",
".",
"trigger",
"(",
"\"commandRegistered\"",
",",
"command",
")",
";",
"return",
"command",
";",
"}"
] |
Registers a global command.
@param {string} name - text that will be displayed in the UI to represent command
@param {string} id - unique identifier for command.
Core commands in Brackets use a simple command title as an id, for example "open.file".
Extensions should use the following format: "author.myextension.mycommandname".
For example, "lschmitt.csswizard.format.css".
@param {function(...)} commandFn - the function to call when the command is executed. Any arguments passed to
execute() (after the id) are passed as arguments to the function. If the function is asynchronous,
it must return a jQuery promise that is resolved when the command completes. Otherwise, the
CommandManager will assume it is synchronous, and return a promise that is already resolved.
@return {?Command}
|
[
"Registers",
"a",
"global",
"command",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/CommandManager.js#L189-L205
|
train
|
adobe/brackets
|
src/command/CommandManager.js
|
registerInternal
|
function registerInternal(id, commandFn) {
if (_commands[id]) {
console.log("Attempting to register an already-registered command: " + id);
return null;
}
if (!id || !commandFn) {
console.error("Attempting to register an internal command with a missing id, or command function: " + id);
return null;
}
var command = new Command(null, id, commandFn);
_commands[id] = command;
exports.trigger("commandRegistered", command);
return command;
}
|
javascript
|
function registerInternal(id, commandFn) {
if (_commands[id]) {
console.log("Attempting to register an already-registered command: " + id);
return null;
}
if (!id || !commandFn) {
console.error("Attempting to register an internal command with a missing id, or command function: " + id);
return null;
}
var command = new Command(null, id, commandFn);
_commands[id] = command;
exports.trigger("commandRegistered", command);
return command;
}
|
[
"function",
"registerInternal",
"(",
"id",
",",
"commandFn",
")",
"{",
"if",
"(",
"_commands",
"[",
"id",
"]",
")",
"{",
"console",
".",
"log",
"(",
"\"Attempting to register an already-registered command: \"",
"+",
"id",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"id",
"||",
"!",
"commandFn",
")",
"{",
"console",
".",
"error",
"(",
"\"Attempting to register an internal command with a missing id, or command function: \"",
"+",
"id",
")",
";",
"return",
"null",
";",
"}",
"var",
"command",
"=",
"new",
"Command",
"(",
"null",
",",
"id",
",",
"commandFn",
")",
";",
"_commands",
"[",
"id",
"]",
"=",
"command",
";",
"exports",
".",
"trigger",
"(",
"\"commandRegistered\"",
",",
"command",
")",
";",
"return",
"command",
";",
"}"
] |
Registers a global internal only command.
@param {string} id - unique identifier for command.
Core commands in Brackets use a simple command title as an id, for example "app.abort_quit".
Extensions should use the following format: "author.myextension.mycommandname".
For example, "lschmitt.csswizard.format.css".
@param {function(...)} commandFn - the function to call when the command is executed. Any arguments passed to
execute() (after the id) are passed as arguments to the function. If the function is asynchronous,
it must return a jQuery promise that is resolved when the command completes. Otherwise, the
CommandManager will assume it is synchronous, and return a promise that is already resolved.
@return {?Command}
|
[
"Registers",
"a",
"global",
"internal",
"only",
"command",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/CommandManager.js#L219-L235
|
train
|
adobe/brackets
|
src/command/CommandManager.js
|
execute
|
function execute(id) {
var command = _commands[id];
if (command) {
try {
exports.trigger("beforeExecuteCommand", id);
} catch (err) {
console.error(err);
}
return command.execute.apply(command, Array.prototype.slice.call(arguments, 1));
} else {
return (new $.Deferred()).reject().promise();
}
}
|
javascript
|
function execute(id) {
var command = _commands[id];
if (command) {
try {
exports.trigger("beforeExecuteCommand", id);
} catch (err) {
console.error(err);
}
return command.execute.apply(command, Array.prototype.slice.call(arguments, 1));
} else {
return (new $.Deferred()).reject().promise();
}
}
|
[
"function",
"execute",
"(",
"id",
")",
"{",
"var",
"command",
"=",
"_commands",
"[",
"id",
"]",
";",
"if",
"(",
"command",
")",
"{",
"try",
"{",
"exports",
".",
"trigger",
"(",
"\"beforeExecuteCommand\"",
",",
"id",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
")",
";",
"}",
"return",
"command",
".",
"execute",
".",
"apply",
"(",
"command",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
";",
"}",
"else",
"{",
"return",
"(",
"new",
"$",
".",
"Deferred",
"(",
")",
")",
".",
"reject",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"}"
] |
Looks up and runs a global command. Additional arguments are passed to the command.
@param {string} id The ID of the command to run.
@return {$.Promise} a jQuery promise that will be resolved when the command completes.
|
[
"Looks",
"up",
"and",
"runs",
"a",
"global",
"command",
".",
"Additional",
"arguments",
"are",
"passed",
"to",
"the",
"command",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/command/CommandManager.js#L277-L291
|
train
|
adobe/brackets
|
src/utils/PerfUtils.js
|
addMeasurement
|
function addMeasurement(id) {
if (!enabled) {
return;
}
if (!(id instanceof PerfMeasurement)) {
id = new PerfMeasurement(id, id);
}
var elapsedTime = brackets.app.getElapsedMilliseconds();
if (activeTests[id.id]) {
elapsedTime -= activeTests[id.id].startTime;
delete activeTests[id.id];
}
if (perfData[id]) {
// We have existing data, add to it
if (Array.isArray(perfData[id])) {
perfData[id].push(elapsedTime);
} else {
// Current data is a number, convert to Array
perfData[id] = [perfData[id], elapsedTime];
}
} else {
perfData[id] = elapsedTime;
}
if (id.reent !== undefined) {
if (_reentTests[id] === 0) {
delete _reentTests[id];
} else {
_reentTests[id]--;
}
}
}
|
javascript
|
function addMeasurement(id) {
if (!enabled) {
return;
}
if (!(id instanceof PerfMeasurement)) {
id = new PerfMeasurement(id, id);
}
var elapsedTime = brackets.app.getElapsedMilliseconds();
if (activeTests[id.id]) {
elapsedTime -= activeTests[id.id].startTime;
delete activeTests[id.id];
}
if (perfData[id]) {
// We have existing data, add to it
if (Array.isArray(perfData[id])) {
perfData[id].push(elapsedTime);
} else {
// Current data is a number, convert to Array
perfData[id] = [perfData[id], elapsedTime];
}
} else {
perfData[id] = elapsedTime;
}
if (id.reent !== undefined) {
if (_reentTests[id] === 0) {
delete _reentTests[id];
} else {
_reentTests[id]--;
}
}
}
|
[
"function",
"addMeasurement",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"enabled",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"(",
"id",
"instanceof",
"PerfMeasurement",
")",
")",
"{",
"id",
"=",
"new",
"PerfMeasurement",
"(",
"id",
",",
"id",
")",
";",
"}",
"var",
"elapsedTime",
"=",
"brackets",
".",
"app",
".",
"getElapsedMilliseconds",
"(",
")",
";",
"if",
"(",
"activeTests",
"[",
"id",
".",
"id",
"]",
")",
"{",
"elapsedTime",
"-=",
"activeTests",
"[",
"id",
".",
"id",
"]",
".",
"startTime",
";",
"delete",
"activeTests",
"[",
"id",
".",
"id",
"]",
";",
"}",
"if",
"(",
"perfData",
"[",
"id",
"]",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"perfData",
"[",
"id",
"]",
")",
")",
"{",
"perfData",
"[",
"id",
"]",
".",
"push",
"(",
"elapsedTime",
")",
";",
"}",
"else",
"{",
"perfData",
"[",
"id",
"]",
"=",
"[",
"perfData",
"[",
"id",
"]",
",",
"elapsedTime",
"]",
";",
"}",
"}",
"else",
"{",
"perfData",
"[",
"id",
"]",
"=",
"elapsedTime",
";",
"}",
"if",
"(",
"id",
".",
"reent",
"!==",
"undefined",
")",
"{",
"if",
"(",
"_reentTests",
"[",
"id",
"]",
"===",
"0",
")",
"{",
"delete",
"_reentTests",
"[",
"id",
"]",
";",
"}",
"else",
"{",
"_reentTests",
"[",
"id",
"]",
"--",
";",
"}",
"}",
"}"
] |
Stop a timer and add its measurements to the performance data.
Multiple measurements can be stored for any given name. If there are
multiple values for a name, they are stored in an Array.
If markStart() was not called for the specified timer, the
measured time is relative to app startup.
@param {Object} id Timer id.
|
[
"Stop",
"a",
"timer",
"and",
"add",
"its",
"measurements",
"to",
"the",
"performance",
"data",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/PerfUtils.js#L187-L223
|
train
|
adobe/brackets
|
src/utils/PerfUtils.js
|
finalizeMeasurement
|
function finalizeMeasurement(id) {
if (activeTests[id.id]) {
delete activeTests[id.id];
}
if (updatableTests[id.id]) {
delete updatableTests[id.id];
}
}
|
javascript
|
function finalizeMeasurement(id) {
if (activeTests[id.id]) {
delete activeTests[id.id];
}
if (updatableTests[id.id]) {
delete updatableTests[id.id];
}
}
|
[
"function",
"finalizeMeasurement",
"(",
"id",
")",
"{",
"if",
"(",
"activeTests",
"[",
"id",
".",
"id",
"]",
")",
"{",
"delete",
"activeTests",
"[",
"id",
".",
"id",
"]",
";",
"}",
"if",
"(",
"updatableTests",
"[",
"id",
".",
"id",
"]",
")",
"{",
"delete",
"updatableTests",
"[",
"id",
".",
"id",
"]",
";",
"}",
"}"
] |
Remove timer from lists so next action starts a new measurement
updateMeasurement may not have been called, so timer may be
in either or neither list, but should never be in both.
@param {Object} id Timer id.
|
[
"Remove",
"timer",
"from",
"lists",
"so",
"next",
"action",
"starts",
"a",
"new",
"measurement"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/PerfUtils.js#L281-L289
|
train
|
adobe/brackets
|
src/utils/PerfUtils.js
|
getDelimitedPerfData
|
function getDelimitedPerfData() {
var result = "";
_.forEach(perfData, function (entry, testName) {
result += getValueAsString(entry) + "\t" + testName + "\n";
});
return result;
}
|
javascript
|
function getDelimitedPerfData() {
var result = "";
_.forEach(perfData, function (entry, testName) {
result += getValueAsString(entry) + "\t" + testName + "\n";
});
return result;
}
|
[
"function",
"getDelimitedPerfData",
"(",
")",
"{",
"var",
"result",
"=",
"\"\"",
";",
"_",
".",
"forEach",
"(",
"perfData",
",",
"function",
"(",
"entry",
",",
"testName",
")",
"{",
"result",
"+=",
"getValueAsString",
"(",
"entry",
")",
"+",
"\"\\t\"",
"+",
"\\t",
"+",
"testName",
";",
"}",
")",
";",
"\"\\n\"",
"}"
] |
Returns the performance data as a tab delimited string
@return {string}
|
[
"Returns",
"the",
"performance",
"data",
"as",
"a",
"tab",
"delimited",
"string"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/PerfUtils.js#L343-L350
|
train
|
adobe/brackets
|
src/utils/PerfUtils.js
|
getHealthReport
|
function getHealthReport() {
var healthReport = {
projectLoadTimes : "",
fileOpenTimes : ""
};
_.forEach(perfData, function (entry, testName) {
if (StringUtils.startsWith(testName, "Application Startup")) {
healthReport.AppStartupTime = getValueAsString(entry);
} else if (StringUtils.startsWith(testName, "brackets module dependencies resolved")) {
healthReport.ModuleDepsResolved = getValueAsString(entry);
} else if (StringUtils.startsWith(testName, "Load Project")) {
healthReport.projectLoadTimes += ":" + getValueAsString(entry, true);
} else if (StringUtils.startsWith(testName, "Open File")) {
healthReport.fileOpenTimes += ":" + getValueAsString(entry, true);
}
});
return healthReport;
}
|
javascript
|
function getHealthReport() {
var healthReport = {
projectLoadTimes : "",
fileOpenTimes : ""
};
_.forEach(perfData, function (entry, testName) {
if (StringUtils.startsWith(testName, "Application Startup")) {
healthReport.AppStartupTime = getValueAsString(entry);
} else if (StringUtils.startsWith(testName, "brackets module dependencies resolved")) {
healthReport.ModuleDepsResolved = getValueAsString(entry);
} else if (StringUtils.startsWith(testName, "Load Project")) {
healthReport.projectLoadTimes += ":" + getValueAsString(entry, true);
} else if (StringUtils.startsWith(testName, "Open File")) {
healthReport.fileOpenTimes += ":" + getValueAsString(entry, true);
}
});
return healthReport;
}
|
[
"function",
"getHealthReport",
"(",
")",
"{",
"var",
"healthReport",
"=",
"{",
"projectLoadTimes",
":",
"\"\"",
",",
"fileOpenTimes",
":",
"\"\"",
"}",
";",
"_",
".",
"forEach",
"(",
"perfData",
",",
"function",
"(",
"entry",
",",
"testName",
")",
"{",
"if",
"(",
"StringUtils",
".",
"startsWith",
"(",
"testName",
",",
"\"Application Startup\"",
")",
")",
"{",
"healthReport",
".",
"AppStartupTime",
"=",
"getValueAsString",
"(",
"entry",
")",
";",
"}",
"else",
"if",
"(",
"StringUtils",
".",
"startsWith",
"(",
"testName",
",",
"\"brackets module dependencies resolved\"",
")",
")",
"{",
"healthReport",
".",
"ModuleDepsResolved",
"=",
"getValueAsString",
"(",
"entry",
")",
";",
"}",
"else",
"if",
"(",
"StringUtils",
".",
"startsWith",
"(",
"testName",
",",
"\"Load Project\"",
")",
")",
"{",
"healthReport",
".",
"projectLoadTimes",
"+=",
"\":\"",
"+",
"getValueAsString",
"(",
"entry",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"StringUtils",
".",
"startsWith",
"(",
"testName",
",",
"\"Open File\"",
")",
")",
"{",
"healthReport",
".",
"fileOpenTimes",
"+=",
"\":\"",
"+",
"getValueAsString",
"(",
"entry",
",",
"true",
")",
";",
"}",
"}",
")",
";",
"return",
"healthReport",
";",
"}"
] |
Returns the Performance metrics to be logged for health report
@return {Object} An object with the health data logs to be sent
|
[
"Returns",
"the",
"Performance",
"metrics",
"to",
"be",
"logged",
"for",
"health",
"report"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/PerfUtils.js#L368-L387
|
train
|
adobe/brackets
|
src/language/HTMLUtils.js
|
getTagAttributes
|
function getTagAttributes(editor, pos) {
var attrs = [],
backwardCtx = TokenUtils.getInitialContext(editor._codeMirror, pos),
forwardCtx = $.extend({}, backwardCtx);
if (editor.getModeForSelection() === "html") {
if (backwardCtx.token && !tagPrefixedRegExp.test(backwardCtx.token.type)) {
while (TokenUtils.movePrevToken(backwardCtx) && !tagPrefixedRegExp.test(backwardCtx.token.type)) {
if (backwardCtx.token.type === "error" && backwardCtx.token.string.indexOf("<") === 0) {
break;
}
if (backwardCtx.token.type === "attribute") {
attrs.push(backwardCtx.token.string);
}
}
while (TokenUtils.moveNextToken(forwardCtx) && !tagPrefixedRegExp.test(forwardCtx.token.type)) {
if (forwardCtx.token.type === "attribute") {
// If the current tag is not closed, codemirror may return the next opening
// tag as an attribute. Stop the search loop in that case.
if (forwardCtx.token.string.indexOf("<") === 0) {
break;
}
attrs.push(forwardCtx.token.string);
} else if (forwardCtx.token.type === "error") {
if (forwardCtx.token.string.indexOf("<") === 0 || forwardCtx.token.string.indexOf(">") === 0) {
break;
}
// If we type the first letter of the next attribute, it comes as an error
// token. We need to double check for possible invalidated attributes.
if (/\S/.test(forwardCtx.token.string) &&
forwardCtx.token.string.indexOf("\"") === -1 &&
forwardCtx.token.string.indexOf("'") === -1 &&
forwardCtx.token.string.indexOf("=") === -1) {
attrs.push(forwardCtx.token.string);
}
}
}
}
}
return attrs;
}
|
javascript
|
function getTagAttributes(editor, pos) {
var attrs = [],
backwardCtx = TokenUtils.getInitialContext(editor._codeMirror, pos),
forwardCtx = $.extend({}, backwardCtx);
if (editor.getModeForSelection() === "html") {
if (backwardCtx.token && !tagPrefixedRegExp.test(backwardCtx.token.type)) {
while (TokenUtils.movePrevToken(backwardCtx) && !tagPrefixedRegExp.test(backwardCtx.token.type)) {
if (backwardCtx.token.type === "error" && backwardCtx.token.string.indexOf("<") === 0) {
break;
}
if (backwardCtx.token.type === "attribute") {
attrs.push(backwardCtx.token.string);
}
}
while (TokenUtils.moveNextToken(forwardCtx) && !tagPrefixedRegExp.test(forwardCtx.token.type)) {
if (forwardCtx.token.type === "attribute") {
// If the current tag is not closed, codemirror may return the next opening
// tag as an attribute. Stop the search loop in that case.
if (forwardCtx.token.string.indexOf("<") === 0) {
break;
}
attrs.push(forwardCtx.token.string);
} else if (forwardCtx.token.type === "error") {
if (forwardCtx.token.string.indexOf("<") === 0 || forwardCtx.token.string.indexOf(">") === 0) {
break;
}
// If we type the first letter of the next attribute, it comes as an error
// token. We need to double check for possible invalidated attributes.
if (/\S/.test(forwardCtx.token.string) &&
forwardCtx.token.string.indexOf("\"") === -1 &&
forwardCtx.token.string.indexOf("'") === -1 &&
forwardCtx.token.string.indexOf("=") === -1) {
attrs.push(forwardCtx.token.string);
}
}
}
}
}
return attrs;
}
|
[
"function",
"getTagAttributes",
"(",
"editor",
",",
"pos",
")",
"{",
"var",
"attrs",
"=",
"[",
"]",
",",
"backwardCtx",
"=",
"TokenUtils",
".",
"getInitialContext",
"(",
"editor",
".",
"_codeMirror",
",",
"pos",
")",
",",
"forwardCtx",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"backwardCtx",
")",
";",
"if",
"(",
"editor",
".",
"getModeForSelection",
"(",
")",
"===",
"\"html\"",
")",
"{",
"if",
"(",
"backwardCtx",
".",
"token",
"&&",
"!",
"tagPrefixedRegExp",
".",
"test",
"(",
"backwardCtx",
".",
"token",
".",
"type",
")",
")",
"{",
"while",
"(",
"TokenUtils",
".",
"movePrevToken",
"(",
"backwardCtx",
")",
"&&",
"!",
"tagPrefixedRegExp",
".",
"test",
"(",
"backwardCtx",
".",
"token",
".",
"type",
")",
")",
"{",
"if",
"(",
"backwardCtx",
".",
"token",
".",
"type",
"===",
"\"error\"",
"&&",
"backwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\"<\"",
")",
"===",
"0",
")",
"{",
"break",
";",
"}",
"if",
"(",
"backwardCtx",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
")",
"{",
"attrs",
".",
"push",
"(",
"backwardCtx",
".",
"token",
".",
"string",
")",
";",
"}",
"}",
"while",
"(",
"TokenUtils",
".",
"moveNextToken",
"(",
"forwardCtx",
")",
"&&",
"!",
"tagPrefixedRegExp",
".",
"test",
"(",
"forwardCtx",
".",
"token",
".",
"type",
")",
")",
"{",
"if",
"(",
"forwardCtx",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
")",
"{",
"if",
"(",
"forwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\"<\"",
")",
"===",
"0",
")",
"{",
"break",
";",
"}",
"attrs",
".",
"push",
"(",
"forwardCtx",
".",
"token",
".",
"string",
")",
";",
"}",
"else",
"if",
"(",
"forwardCtx",
".",
"token",
".",
"type",
"===",
"\"error\"",
")",
"{",
"if",
"(",
"forwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\"<\"",
")",
"===",
"0",
"||",
"forwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\">\"",
")",
"===",
"0",
")",
"{",
"break",
";",
"}",
"if",
"(",
"/",
"\\S",
"/",
".",
"test",
"(",
"forwardCtx",
".",
"token",
".",
"string",
")",
"&&",
"forwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\"\\\"\"",
")",
"===",
"\\\"",
"&&",
"-",
"1",
"&&",
"forwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\"'\"",
")",
"===",
"-",
"1",
")",
"forwardCtx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\"=\"",
")",
"===",
"-",
"1",
"}",
"}",
"}",
"}",
"{",
"attrs",
".",
"push",
"(",
"forwardCtx",
".",
"token",
".",
"string",
")",
";",
"}",
"}"
] |
Compiles a list of used attributes for a given tag
@param {CodeMirror} editor An instance of a CodeMirror editor
@param {ch:{string}, line:{number}} pos A CodeMirror position
@return {Array.<string>} A list of the used attributes inside the current tag
|
[
"Compiles",
"a",
"list",
"of",
"used",
"attributes",
"for",
"a",
"given",
"tag"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLUtils.js#L131-L173
|
train
|
adobe/brackets
|
src/language/HTMLUtils.js
|
createTagInfo
|
function createTagInfo(tokenType, offset, tagName, attrName, attrValue, valueAssigned, quoteChar, hasEndQuote) {
return { tagName: tagName || "",
attr:
{ name: attrName || "",
value: attrValue || "",
valueAssigned: valueAssigned || false,
quoteChar: quoteChar || "",
hasEndQuote: hasEndQuote || false },
position:
{ tokenType: tokenType || "",
offset: offset || 0 } };
}
|
javascript
|
function createTagInfo(tokenType, offset, tagName, attrName, attrValue, valueAssigned, quoteChar, hasEndQuote) {
return { tagName: tagName || "",
attr:
{ name: attrName || "",
value: attrValue || "",
valueAssigned: valueAssigned || false,
quoteChar: quoteChar || "",
hasEndQuote: hasEndQuote || false },
position:
{ tokenType: tokenType || "",
offset: offset || 0 } };
}
|
[
"function",
"createTagInfo",
"(",
"tokenType",
",",
"offset",
",",
"tagName",
",",
"attrName",
",",
"attrValue",
",",
"valueAssigned",
",",
"quoteChar",
",",
"hasEndQuote",
")",
"{",
"return",
"{",
"tagName",
":",
"tagName",
"||",
"\"\"",
",",
"attr",
":",
"{",
"name",
":",
"attrName",
"||",
"\"\"",
",",
"value",
":",
"attrValue",
"||",
"\"\"",
",",
"valueAssigned",
":",
"valueAssigned",
"||",
"false",
",",
"quoteChar",
":",
"quoteChar",
"||",
"\"\"",
",",
"hasEndQuote",
":",
"hasEndQuote",
"||",
"false",
"}",
",",
"position",
":",
"{",
"tokenType",
":",
"tokenType",
"||",
"\"\"",
",",
"offset",
":",
"offset",
"||",
"0",
"}",
"}",
";",
"}"
] |
Creates a tagInfo object and assures all the values are entered or are empty strings
@param {string=} tokenType what is getting edited and should be hinted
@param {number=} offset where the cursor is for the part getting hinted
@param {string=} tagName The name of the tag
@param {string=} attrName The name of the attribute
@param {string=} attrValue The value of the attribute
@return {{tagName:string,
attr:{name:string, value:string, valueAssigned:boolean, quoteChar:string, hasEndQuote:boolean},
position:{tokenType:string, offset:number}
}}
A tagInfo object with some context about the current tag hint.
|
[
"Creates",
"a",
"tagInfo",
"object",
"and",
"assures",
"all",
"the",
"values",
"are",
"entered",
"or",
"are",
"empty",
"strings"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLUtils.js#L188-L199
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/foldhelpers/handlebarsFold.js
|
scanTextUntil
|
function scanTextUntil(cm, startCh, startLine, condition) {
var line = cm.getLine(startLine),
seen = "",
characterIndex = startCh,
currentLine = startLine,
range;
while (currentLine <= cm.lastLine()) {
if (line.length === 0) {
characterIndex = 0;
line = cm.getLine(++currentLine);
} else {
seen = seen.concat(line[characterIndex] || "");
if (condition(seen)) {
range = {
from: {ch: startCh, line: startLine},
to: {ch: characterIndex, line: currentLine},
string: seen
};
return range;
} else if (characterIndex >= line.length) {
seen = seen.concat(cm.lineSeparator());
if (condition(seen)) {
range = {
from: {ch: startCh, line: startLine},
to: {ch: characterIndex, line: currentLine},
string: seen
};
return range;
}
characterIndex = 0;
line = cm.getLine(++currentLine);
} else {
++characterIndex;
}
}
}
}
|
javascript
|
function scanTextUntil(cm, startCh, startLine, condition) {
var line = cm.getLine(startLine),
seen = "",
characterIndex = startCh,
currentLine = startLine,
range;
while (currentLine <= cm.lastLine()) {
if (line.length === 0) {
characterIndex = 0;
line = cm.getLine(++currentLine);
} else {
seen = seen.concat(line[characterIndex] || "");
if (condition(seen)) {
range = {
from: {ch: startCh, line: startLine},
to: {ch: characterIndex, line: currentLine},
string: seen
};
return range;
} else if (characterIndex >= line.length) {
seen = seen.concat(cm.lineSeparator());
if (condition(seen)) {
range = {
from: {ch: startCh, line: startLine},
to: {ch: characterIndex, line: currentLine},
string: seen
};
return range;
}
characterIndex = 0;
line = cm.getLine(++currentLine);
} else {
++characterIndex;
}
}
}
}
|
[
"function",
"scanTextUntil",
"(",
"cm",
",",
"startCh",
",",
"startLine",
",",
"condition",
")",
"{",
"var",
"line",
"=",
"cm",
".",
"getLine",
"(",
"startLine",
")",
",",
"seen",
"=",
"\"\"",
",",
"characterIndex",
"=",
"startCh",
",",
"currentLine",
"=",
"startLine",
",",
"range",
";",
"while",
"(",
"currentLine",
"<=",
"cm",
".",
"lastLine",
"(",
")",
")",
"{",
"if",
"(",
"line",
".",
"length",
"===",
"0",
")",
"{",
"characterIndex",
"=",
"0",
";",
"line",
"=",
"cm",
".",
"getLine",
"(",
"++",
"currentLine",
")",
";",
"}",
"else",
"{",
"seen",
"=",
"seen",
".",
"concat",
"(",
"line",
"[",
"characterIndex",
"]",
"||",
"\"\"",
")",
";",
"if",
"(",
"condition",
"(",
"seen",
")",
")",
"{",
"range",
"=",
"{",
"from",
":",
"{",
"ch",
":",
"startCh",
",",
"line",
":",
"startLine",
"}",
",",
"to",
":",
"{",
"ch",
":",
"characterIndex",
",",
"line",
":",
"currentLine",
"}",
",",
"string",
":",
"seen",
"}",
";",
"return",
"range",
";",
"}",
"else",
"if",
"(",
"characterIndex",
">=",
"line",
".",
"length",
")",
"{",
"seen",
"=",
"seen",
".",
"concat",
"(",
"cm",
".",
"lineSeparator",
"(",
")",
")",
";",
"if",
"(",
"condition",
"(",
"seen",
")",
")",
"{",
"range",
"=",
"{",
"from",
":",
"{",
"ch",
":",
"startCh",
",",
"line",
":",
"startLine",
"}",
",",
"to",
":",
"{",
"ch",
":",
"characterIndex",
",",
"line",
":",
"currentLine",
"}",
",",
"string",
":",
"seen",
"}",
";",
"return",
"range",
";",
"}",
"characterIndex",
"=",
"0",
";",
"line",
"=",
"cm",
".",
"getLine",
"(",
"++",
"currentLine",
")",
";",
"}",
"else",
"{",
"++",
"characterIndex",
";",
"}",
"}",
"}",
"}"
] |
Utility function for scanning the text in a document until a certain condition is met
@param {object} cm The code mirror object representing the document
@param {string} startCh The start character position for the scan operation
@param {number} startLine The start line position for the scan operation
@param {function (string): boolean} condition A predicate function that takes in the text seen so far and returns true if the scanning process should be halted
@returns {{from:CodeMirror.Pos, to: CodeMirror.Pos, string: string}} An object representing the range of text scanned.
|
[
"Utility",
"function",
"for",
"scanning",
"the",
"text",
"in",
"a",
"document",
"until",
"a",
"certain",
"condition",
"is",
"met"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/foldhelpers/handlebarsFold.js#L44-L80
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/CSSAgent.js
|
styleForURL
|
function styleForURL(url) {
var styleSheetId, styles = {};
url = _canonicalize(url);
for (styleSheetId in _styleSheetDetails) {
if (_styleSheetDetails[styleSheetId].canonicalizedURL === url) {
styles[styleSheetId] = _styleSheetDetails[styleSheetId];
}
}
return styles;
}
|
javascript
|
function styleForURL(url) {
var styleSheetId, styles = {};
url = _canonicalize(url);
for (styleSheetId in _styleSheetDetails) {
if (_styleSheetDetails[styleSheetId].canonicalizedURL === url) {
styles[styleSheetId] = _styleSheetDetails[styleSheetId];
}
}
return styles;
}
|
[
"function",
"styleForURL",
"(",
"url",
")",
"{",
"var",
"styleSheetId",
",",
"styles",
"=",
"{",
"}",
";",
"url",
"=",
"_canonicalize",
"(",
"url",
")",
";",
"for",
"(",
"styleSheetId",
"in",
"_styleSheetDetails",
")",
"{",
"if",
"(",
"_styleSheetDetails",
"[",
"styleSheetId",
"]",
".",
"canonicalizedURL",
"===",
"url",
")",
"{",
"styles",
"[",
"styleSheetId",
"]",
"=",
"_styleSheetDetails",
"[",
"styleSheetId",
"]",
";",
"}",
"}",
"return",
"styles",
";",
"}"
] |
Get the style sheets for a url
@param {string} url
@return {Object.<string, CSSStyleSheetHeader>}
|
[
"Get",
"the",
"style",
"sheets",
"for",
"a",
"url"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/CSSAgent.js#L81-L90
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/CSSAgent.js
|
reloadCSSForDocument
|
function reloadCSSForDocument(doc, newContent) {
var styles = styleForURL(doc.url),
styleSheetId,
deferreds = [];
if (newContent === undefined) {
newContent = doc.getText();
}
for (styleSheetId in styles) {
deferreds.push(Inspector.CSS.setStyleSheetText(styles[styleSheetId].styleSheetId, newContent));
}
if (!deferreds.length) {
console.error("Style Sheet for document not loaded: " + doc.url);
return new $.Deferred().reject().promise();
}
// return master deferred
return $.when.apply($, deferreds);
}
|
javascript
|
function reloadCSSForDocument(doc, newContent) {
var styles = styleForURL(doc.url),
styleSheetId,
deferreds = [];
if (newContent === undefined) {
newContent = doc.getText();
}
for (styleSheetId in styles) {
deferreds.push(Inspector.CSS.setStyleSheetText(styles[styleSheetId].styleSheetId, newContent));
}
if (!deferreds.length) {
console.error("Style Sheet for document not loaded: " + doc.url);
return new $.Deferred().reject().promise();
}
// return master deferred
return $.when.apply($, deferreds);
}
|
[
"function",
"reloadCSSForDocument",
"(",
"doc",
",",
"newContent",
")",
"{",
"var",
"styles",
"=",
"styleForURL",
"(",
"doc",
".",
"url",
")",
",",
"styleSheetId",
",",
"deferreds",
"=",
"[",
"]",
";",
"if",
"(",
"newContent",
"===",
"undefined",
")",
"{",
"newContent",
"=",
"doc",
".",
"getText",
"(",
")",
";",
"}",
"for",
"(",
"styleSheetId",
"in",
"styles",
")",
"{",
"deferreds",
".",
"push",
"(",
"Inspector",
".",
"CSS",
".",
"setStyleSheetText",
"(",
"styles",
"[",
"styleSheetId",
"]",
".",
"styleSheetId",
",",
"newContent",
")",
")",
";",
"}",
"if",
"(",
"!",
"deferreds",
".",
"length",
")",
"{",
"console",
".",
"error",
"(",
"\"Style Sheet for document not loaded: \"",
"+",
"doc",
".",
"url",
")",
";",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"reject",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"return",
"$",
".",
"when",
".",
"apply",
"(",
"$",
",",
"deferreds",
")",
";",
"}"
] |
Reload a CSS style sheet from a document
@param {Document} document
@param {string=} newContent new content of every stylesheet. Defaults to doc.getText() if omitted
@return {jQuery.Promise}
|
[
"Reload",
"a",
"CSS",
"style",
"sheet",
"from",
"a",
"document"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/CSSAgent.js#L98-L115
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
_removeListeners
|
function _removeListeners() {
DocumentModule.off("documentChange", _documentChangeHandler);
FileSystem.off("change", _debouncedFileSystemChangeHandler);
DocumentManager.off("fileNameChange", _fileNameChangeHandler);
}
|
javascript
|
function _removeListeners() {
DocumentModule.off("documentChange", _documentChangeHandler);
FileSystem.off("change", _debouncedFileSystemChangeHandler);
DocumentManager.off("fileNameChange", _fileNameChangeHandler);
}
|
[
"function",
"_removeListeners",
"(",
")",
"{",
"DocumentModule",
".",
"off",
"(",
"\"documentChange\"",
",",
"_documentChangeHandler",
")",
";",
"FileSystem",
".",
"off",
"(",
"\"change\"",
",",
"_debouncedFileSystemChangeHandler",
")",
";",
"DocumentManager",
".",
"off",
"(",
"\"fileNameChange\"",
",",
"_fileNameChangeHandler",
")",
";",
"}"
] |
Remove the listeners that were tracking potential search result changes
|
[
"Remove",
"the",
"listeners",
"that",
"were",
"tracking",
"potential",
"search",
"result",
"changes"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L91-L95
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
_addListeners
|
function _addListeners() {
// Avoid adding duplicate listeners - e.g. if a 2nd search is run without closing the old results panel first
_removeListeners();
DocumentModule.on("documentChange", _documentChangeHandler);
FileSystem.on("change", _debouncedFileSystemChangeHandler);
DocumentManager.on("fileNameChange", _fileNameChangeHandler);
}
|
javascript
|
function _addListeners() {
// Avoid adding duplicate listeners - e.g. if a 2nd search is run without closing the old results panel first
_removeListeners();
DocumentModule.on("documentChange", _documentChangeHandler);
FileSystem.on("change", _debouncedFileSystemChangeHandler);
DocumentManager.on("fileNameChange", _fileNameChangeHandler);
}
|
[
"function",
"_addListeners",
"(",
")",
"{",
"_removeListeners",
"(",
")",
";",
"DocumentModule",
".",
"on",
"(",
"\"documentChange\"",
",",
"_documentChangeHandler",
")",
";",
"FileSystem",
".",
"on",
"(",
"\"change\"",
",",
"_debouncedFileSystemChangeHandler",
")",
";",
"DocumentManager",
".",
"on",
"(",
"\"fileNameChange\"",
",",
"_fileNameChangeHandler",
")",
";",
"}"
] |
Add listeners to track events that might change the search result set
|
[
"Add",
"listeners",
"to",
"track",
"events",
"that",
"might",
"change",
"the",
"search",
"result",
"set"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L98-L105
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
getCandidateFiles
|
function getCandidateFiles(scope) {
function filter(file) {
return _subtreeFilter(file, scope) && _isReadableText(file.fullPath);
}
// If the scope is a single file, just check if the file passes the filter directly rather than
// trying to use ProjectManager.getAllFiles(), both for performance and because an individual
// in-memory file might be an untitled document that doesn't show up in getAllFiles().
if (scope && scope.isFile) {
return new $.Deferred().resolve(filter(scope) ? [scope] : []).promise();
} else {
return ProjectManager.getAllFiles(filter, true, true);
}
}
|
javascript
|
function getCandidateFiles(scope) {
function filter(file) {
return _subtreeFilter(file, scope) && _isReadableText(file.fullPath);
}
// If the scope is a single file, just check if the file passes the filter directly rather than
// trying to use ProjectManager.getAllFiles(), both for performance and because an individual
// in-memory file might be an untitled document that doesn't show up in getAllFiles().
if (scope && scope.isFile) {
return new $.Deferred().resolve(filter(scope) ? [scope] : []).promise();
} else {
return ProjectManager.getAllFiles(filter, true, true);
}
}
|
[
"function",
"getCandidateFiles",
"(",
"scope",
")",
"{",
"function",
"filter",
"(",
"file",
")",
"{",
"return",
"_subtreeFilter",
"(",
"file",
",",
"scope",
")",
"&&",
"_isReadableText",
"(",
"file",
".",
"fullPath",
")",
";",
"}",
"if",
"(",
"scope",
"&&",
"scope",
".",
"isFile",
")",
"{",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"resolve",
"(",
"filter",
"(",
"scope",
")",
"?",
"[",
"scope",
"]",
":",
"[",
"]",
")",
".",
"promise",
"(",
")",
";",
"}",
"else",
"{",
"return",
"ProjectManager",
".",
"getAllFiles",
"(",
"filter",
",",
"true",
",",
"true",
")",
";",
"}",
"}"
] |
Finds all candidate files to search in the given scope's subtree that are not binary content. Does NOT apply
the current filter yet.
@param {?FileSystemEntry} scope Search scope, or null if whole project
@return {$.Promise} A promise that will be resolved with the list of files in the scope. Never rejected.
|
[
"Finds",
"all",
"candidate",
"files",
"to",
"search",
"in",
"the",
"given",
"scope",
"s",
"subtree",
"that",
"are",
"not",
"binary",
"content",
".",
"Does",
"NOT",
"apply",
"the",
"current",
"filter",
"yet",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L350-L363
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
doSearchInScope
|
function doSearchInScope(queryInfo, scope, filter, replaceText, candidateFilesPromise) {
clearSearch();
searchModel.scope = scope;
if (replaceText !== undefined) {
searchModel.isReplace = true;
searchModel.replaceText = replaceText;
}
candidateFilesPromise = candidateFilesPromise || getCandidateFiles(scope);
return _doSearch(queryInfo, candidateFilesPromise, filter);
}
|
javascript
|
function doSearchInScope(queryInfo, scope, filter, replaceText, candidateFilesPromise) {
clearSearch();
searchModel.scope = scope;
if (replaceText !== undefined) {
searchModel.isReplace = true;
searchModel.replaceText = replaceText;
}
candidateFilesPromise = candidateFilesPromise || getCandidateFiles(scope);
return _doSearch(queryInfo, candidateFilesPromise, filter);
}
|
[
"function",
"doSearchInScope",
"(",
"queryInfo",
",",
"scope",
",",
"filter",
",",
"replaceText",
",",
"candidateFilesPromise",
")",
"{",
"clearSearch",
"(",
")",
";",
"searchModel",
".",
"scope",
"=",
"scope",
";",
"if",
"(",
"replaceText",
"!==",
"undefined",
")",
"{",
"searchModel",
".",
"isReplace",
"=",
"true",
";",
"searchModel",
".",
"replaceText",
"=",
"replaceText",
";",
"}",
"candidateFilesPromise",
"=",
"candidateFilesPromise",
"||",
"getCandidateFiles",
"(",
"scope",
")",
";",
"return",
"_doSearch",
"(",
"queryInfo",
",",
"candidateFilesPromise",
",",
"filter",
")",
";",
"}"
] |
Does a search in the given scope with the given filter. Used when you want to start a search
programmatically.
@param {{query: string, caseSensitive: boolean, isRegexp: boolean}} queryInfo Query info object
@param {?Entry} scope Project file/subfolder to search within; else searches whole project.
@param {?string} filter A "compiled" filter as returned by FileFilters.compile(), or null for no filter
@param {?string} replaceText If this is a replacement, the text to replace matches with. This is just
stored in the model for later use - the replacement is not actually performed right now.
@param {?$.Promise} candidateFilesPromise If specified, a promise that should resolve with the same set of files that
getCandidateFiles(scope) would return.
@return {$.Promise} A promise that's resolved with the search results or rejected when the find competes.
|
[
"Does",
"a",
"search",
"in",
"the",
"given",
"scope",
"with",
"the",
"given",
"filter",
".",
"Used",
"when",
"you",
"want",
"to",
"start",
"a",
"search",
"programmatically",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L619-L628
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
doReplace
|
function doReplace(results, replaceText, options) {
return FindUtils.performReplacements(results, replaceText, options).always(function () {
// For UI integration testing only
exports._replaceDone = true;
});
}
|
javascript
|
function doReplace(results, replaceText, options) {
return FindUtils.performReplacements(results, replaceText, options).always(function () {
// For UI integration testing only
exports._replaceDone = true;
});
}
|
[
"function",
"doReplace",
"(",
"results",
",",
"replaceText",
",",
"options",
")",
"{",
"return",
"FindUtils",
".",
"performReplacements",
"(",
"results",
",",
"replaceText",
",",
"options",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"exports",
".",
"_replaceDone",
"=",
"true",
";",
"}",
")",
";",
"}"
] |
Given a set of search results, replaces them with the given replaceText, either on disk or in memory.
@param {Object.<fullPath: string, {matches: Array.<{start: {line:number,ch:number}, end: {line:number,ch:number}, startOffset: number, endOffset: number, line: string}>, collapsed: boolean}>} results
The list of results to replace, as returned from _doSearch..
@param {string} replaceText The text to replace each result with.
@param {?Object} options An options object:
forceFilesOpen: boolean - Whether to open all files in editors and do replacements there rather than doing the
replacements on disk. Note that even if this is false, files that are already open in editors will have replacements
done in memory.
isRegexp: boolean - Whether the original query was a regexp. If true, $-substitution is performed on the replaceText.
@return {$.Promise} A promise that's resolved when the replacement is finished or rejected with an array of errors
if there were one or more errors. Each individual item in the array will be a {item: string, error: string} object,
where item is the full path to the file that could not be updated, and error is either a FileSystem error or one
of the `FindInFiles.ERROR_*` constants.
|
[
"Given",
"a",
"set",
"of",
"search",
"results",
"replaces",
"them",
"with",
"the",
"given",
"replaceText",
"either",
"on",
"disk",
"or",
"in",
"memory",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L645-L650
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
filesChanged
|
function filesChanged(fileList) {
if (FindUtils.isNodeSearchDisabled() || !fileList || fileList.length === 0) {
return;
}
var updateObject = {
"fileList": fileList
};
if (searchModel.filter) {
updateObject.filesInSearchScope = FileFilters.getPathsMatchingFilter(searchModel.filter, fileList);
_searchScopeChanged();
}
searchDomain.exec("filesChanged", updateObject);
}
|
javascript
|
function filesChanged(fileList) {
if (FindUtils.isNodeSearchDisabled() || !fileList || fileList.length === 0) {
return;
}
var updateObject = {
"fileList": fileList
};
if (searchModel.filter) {
updateObject.filesInSearchScope = FileFilters.getPathsMatchingFilter(searchModel.filter, fileList);
_searchScopeChanged();
}
searchDomain.exec("filesChanged", updateObject);
}
|
[
"function",
"filesChanged",
"(",
"fileList",
")",
"{",
"if",
"(",
"FindUtils",
".",
"isNodeSearchDisabled",
"(",
")",
"||",
"!",
"fileList",
"||",
"fileList",
".",
"length",
"===",
"0",
")",
"{",
"return",
";",
"}",
"var",
"updateObject",
"=",
"{",
"\"fileList\"",
":",
"fileList",
"}",
";",
"if",
"(",
"searchModel",
".",
"filter",
")",
"{",
"updateObject",
".",
"filesInSearchScope",
"=",
"FileFilters",
".",
"getPathsMatchingFilter",
"(",
"searchModel",
".",
"filter",
",",
"fileList",
")",
";",
"_searchScopeChanged",
"(",
")",
";",
"}",
"searchDomain",
".",
"exec",
"(",
"\"filesChanged\"",
",",
"updateObject",
")",
";",
"}"
] |
Inform node that the list of files has changed.
@param {array} fileList The list of files that changed.
|
[
"Inform",
"node",
"that",
"the",
"list",
"of",
"files",
"has",
"changed",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L674-L686
|
train
|
adobe/brackets
|
src/search/FindInFiles.js
|
function (child) {
// Replicate filtering that getAllFiles() does
if (ProjectManager.shouldShow(child)) {
if (child.isFile && _isReadableText(child.name)) {
// Re-check the filtering that the initial search applied
if (_inSearchScope(child)) {
addedFiles.push(child);
addedFilePaths.push(child.fullPath);
}
}
return true;
}
return false;
}
|
javascript
|
function (child) {
// Replicate filtering that getAllFiles() does
if (ProjectManager.shouldShow(child)) {
if (child.isFile && _isReadableText(child.name)) {
// Re-check the filtering that the initial search applied
if (_inSearchScope(child)) {
addedFiles.push(child);
addedFilePaths.push(child.fullPath);
}
}
return true;
}
return false;
}
|
[
"function",
"(",
"child",
")",
"{",
"if",
"(",
"ProjectManager",
".",
"shouldShow",
"(",
"child",
")",
")",
"{",
"if",
"(",
"child",
".",
"isFile",
"&&",
"_isReadableText",
"(",
"child",
".",
"name",
")",
")",
"{",
"if",
"(",
"_inSearchScope",
"(",
"child",
")",
")",
"{",
"addedFiles",
".",
"push",
"(",
"child",
")",
";",
"addedFilePaths",
".",
"push",
"(",
"child",
".",
"fullPath",
")",
";",
"}",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
gather up added files
|
[
"gather",
"up",
"added",
"files"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L783-L796
|
train
|
|
adobe/brackets
|
src/search/FindInFiles.js
|
function () {
function filter(file) {
return _subtreeFilter(file, null) && _isReadableText(file.fullPath);
}
FindUtils.setInstantSearchDisabled(true);
//we always listen for filesytem changes.
_addListeners();
if (!PreferencesManager.get("findInFiles.nodeSearch")) {
return;
}
ProjectManager.getAllFiles(filter, true, true)
.done(function (fileListResult) {
var files = fileListResult,
filter = FileFilters.getActiveFilter();
if (filter && filter.patterns.length > 0) {
files = FileFilters.filterFileList(FileFilters.compile(filter.patterns), files);
}
files = files.filter(function (entry) {
return entry.isFile && _isReadableText(entry.fullPath);
}).map(function (entry) {
return entry.fullPath;
});
FindUtils.notifyIndexingStarted();
searchDomain.exec("initCache", files);
});
_searchScopeChanged();
}
|
javascript
|
function () {
function filter(file) {
return _subtreeFilter(file, null) && _isReadableText(file.fullPath);
}
FindUtils.setInstantSearchDisabled(true);
//we always listen for filesytem changes.
_addListeners();
if (!PreferencesManager.get("findInFiles.nodeSearch")) {
return;
}
ProjectManager.getAllFiles(filter, true, true)
.done(function (fileListResult) {
var files = fileListResult,
filter = FileFilters.getActiveFilter();
if (filter && filter.patterns.length > 0) {
files = FileFilters.filterFileList(FileFilters.compile(filter.patterns), files);
}
files = files.filter(function (entry) {
return entry.isFile && _isReadableText(entry.fullPath);
}).map(function (entry) {
return entry.fullPath;
});
FindUtils.notifyIndexingStarted();
searchDomain.exec("initCache", files);
});
_searchScopeChanged();
}
|
[
"function",
"(",
")",
"{",
"function",
"filter",
"(",
"file",
")",
"{",
"return",
"_subtreeFilter",
"(",
"file",
",",
"null",
")",
"&&",
"_isReadableText",
"(",
"file",
".",
"fullPath",
")",
";",
"}",
"FindUtils",
".",
"setInstantSearchDisabled",
"(",
"true",
")",
";",
"_addListeners",
"(",
")",
";",
"if",
"(",
"!",
"PreferencesManager",
".",
"get",
"(",
"\"findInFiles.nodeSearch\"",
")",
")",
"{",
"return",
";",
"}",
"ProjectManager",
".",
"getAllFiles",
"(",
"filter",
",",
"true",
",",
"true",
")",
".",
"done",
"(",
"function",
"(",
"fileListResult",
")",
"{",
"var",
"files",
"=",
"fileListResult",
",",
"filter",
"=",
"FileFilters",
".",
"getActiveFilter",
"(",
")",
";",
"if",
"(",
"filter",
"&&",
"filter",
".",
"patterns",
".",
"length",
">",
"0",
")",
"{",
"files",
"=",
"FileFilters",
".",
"filterFileList",
"(",
"FileFilters",
".",
"compile",
"(",
"filter",
".",
"patterns",
")",
",",
"files",
")",
";",
"}",
"files",
"=",
"files",
".",
"filter",
"(",
"function",
"(",
"entry",
")",
"{",
"return",
"entry",
".",
"isFile",
"&&",
"_isReadableText",
"(",
"entry",
".",
"fullPath",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"entry",
")",
"{",
"return",
"entry",
".",
"fullPath",
";",
"}",
")",
";",
"FindUtils",
".",
"notifyIndexingStarted",
"(",
")",
";",
"searchDomain",
".",
"exec",
"(",
"\"initCache\"",
",",
"files",
")",
";",
"}",
")",
";",
"_searchScopeChanged",
"(",
")",
";",
"}"
] |
On project change, inform node about the new list of files that needs to be crawled.
Instant search is also disabled for the time being till the crawl is complete in node.
|
[
"On",
"project",
"change",
"inform",
"node",
"about",
"the",
"new",
"list",
"of",
"files",
"that",
"needs",
"to",
"be",
"crawled",
".",
"Instant",
"search",
"is",
"also",
"disabled",
"for",
"the",
"time",
"being",
"till",
"the",
"crawl",
"is",
"complete",
"in",
"node",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L916-L944
|
train
|
|
adobe/brackets
|
src/search/FindInFiles.js
|
getNextPageofSearchResults
|
function getNextPageofSearchResults() {
var searchDeferred = $.Deferred();
if (searchModel.allResultsAvailable) {
return searchDeferred.resolve().promise();
}
_updateChangedDocs();
FindUtils.notifyNodeSearchStarted();
searchDomain.exec("nextPage")
.done(function (rcvd_object) {
FindUtils.notifyNodeSearchFinished();
if (searchModel.results) {
var resultEntry;
for (resultEntry in rcvd_object.results ) {
if (rcvd_object.results.hasOwnProperty(resultEntry)) {
searchModel.results[resultEntry.toString()] = rcvd_object.results[resultEntry];
}
}
} else {
searchModel.results = rcvd_object.results;
}
searchModel.fireChanged();
searchDeferred.resolve();
})
.fail(function () {
FindUtils.notifyNodeSearchFinished();
console.log('node fails');
FindUtils.setNodeSearchDisabled(true);
searchDeferred.reject();
});
return searchDeferred.promise();
}
|
javascript
|
function getNextPageofSearchResults() {
var searchDeferred = $.Deferred();
if (searchModel.allResultsAvailable) {
return searchDeferred.resolve().promise();
}
_updateChangedDocs();
FindUtils.notifyNodeSearchStarted();
searchDomain.exec("nextPage")
.done(function (rcvd_object) {
FindUtils.notifyNodeSearchFinished();
if (searchModel.results) {
var resultEntry;
for (resultEntry in rcvd_object.results ) {
if (rcvd_object.results.hasOwnProperty(resultEntry)) {
searchModel.results[resultEntry.toString()] = rcvd_object.results[resultEntry];
}
}
} else {
searchModel.results = rcvd_object.results;
}
searchModel.fireChanged();
searchDeferred.resolve();
})
.fail(function () {
FindUtils.notifyNodeSearchFinished();
console.log('node fails');
FindUtils.setNodeSearchDisabled(true);
searchDeferred.reject();
});
return searchDeferred.promise();
}
|
[
"function",
"getNextPageofSearchResults",
"(",
")",
"{",
"var",
"searchDeferred",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"searchModel",
".",
"allResultsAvailable",
")",
"{",
"return",
"searchDeferred",
".",
"resolve",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"_updateChangedDocs",
"(",
")",
";",
"FindUtils",
".",
"notifyNodeSearchStarted",
"(",
")",
";",
"searchDomain",
".",
"exec",
"(",
"\"nextPage\"",
")",
".",
"done",
"(",
"function",
"(",
"rcvd_object",
")",
"{",
"FindUtils",
".",
"notifyNodeSearchFinished",
"(",
")",
";",
"if",
"(",
"searchModel",
".",
"results",
")",
"{",
"var",
"resultEntry",
";",
"for",
"(",
"resultEntry",
"in",
"rcvd_object",
".",
"results",
")",
"{",
"if",
"(",
"rcvd_object",
".",
"results",
".",
"hasOwnProperty",
"(",
"resultEntry",
")",
")",
"{",
"searchModel",
".",
"results",
"[",
"resultEntry",
".",
"toString",
"(",
")",
"]",
"=",
"rcvd_object",
".",
"results",
"[",
"resultEntry",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"searchModel",
".",
"results",
"=",
"rcvd_object",
".",
"results",
";",
"}",
"searchModel",
".",
"fireChanged",
"(",
")",
";",
"searchDeferred",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"FindUtils",
".",
"notifyNodeSearchFinished",
"(",
")",
";",
"console",
".",
"log",
"(",
"'node fails'",
")",
";",
"FindUtils",
".",
"setNodeSearchDisabled",
"(",
"true",
")",
";",
"searchDeferred",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"searchDeferred",
".",
"promise",
"(",
")",
";",
"}"
] |
Gets the next page of search results to append to the result set.
@return {object} A promise that's resolved with the search results or rejected when the find competes.
|
[
"Gets",
"the",
"next",
"page",
"of",
"search",
"results",
"to",
"append",
"to",
"the",
"result",
"set",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindInFiles.js#L951-L981
|
train
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function (beforeID, isBeingDeleted) {
newEdits.forEach(function (edit) {
// elementDeletes don't need any positioning information
if (edit.type !== "elementDelete") {
edit.beforeID = beforeID;
}
});
edits.push.apply(edits, newEdits);
newEdits = [];
// If the item we made this set of edits relative to
// is being deleted, we can't use it as the afterID for future
// edits. It's okay to just keep the previous afterID, since
// this node will no longer be in the tree by the time we get
// to any future edit that needs an afterID.
if (!isBeingDeleted) {
textAfterID = beforeID;
}
}
|
javascript
|
function (beforeID, isBeingDeleted) {
newEdits.forEach(function (edit) {
// elementDeletes don't need any positioning information
if (edit.type !== "elementDelete") {
edit.beforeID = beforeID;
}
});
edits.push.apply(edits, newEdits);
newEdits = [];
// If the item we made this set of edits relative to
// is being deleted, we can't use it as the afterID for future
// edits. It's okay to just keep the previous afterID, since
// this node will no longer be in the tree by the time we get
// to any future edit that needs an afterID.
if (!isBeingDeleted) {
textAfterID = beforeID;
}
}
|
[
"function",
"(",
"beforeID",
",",
"isBeingDeleted",
")",
"{",
"newEdits",
".",
"forEach",
"(",
"function",
"(",
"edit",
")",
"{",
"if",
"(",
"edit",
".",
"type",
"!==",
"\"elementDelete\"",
")",
"{",
"edit",
".",
"beforeID",
"=",
"beforeID",
";",
"}",
"}",
")",
";",
"edits",
".",
"push",
".",
"apply",
"(",
"edits",
",",
"newEdits",
")",
";",
"newEdits",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"isBeingDeleted",
")",
"{",
"textAfterID",
"=",
"beforeID",
";",
"}",
"}"
] |
We initially put new edit objects into the `newEdits` array so that we
can fix them up with proper positioning information. This function is
responsible for doing that fixup.
The `beforeID` that appears in many edits tells the browser to make the
change before the element with the given ID. In other words, an
elementInsert with a `beforeID` of 32 would result in something like
`parentElement.insertBefore(newChildElement, _queryBracketsID(32))`
Many new edits are captured in the `newEdits` array so that a suitable
`beforeID` can be added to them before they are added to the main edits
list. This function sets the `beforeID` on any pending edits and adds
them to the main list.
If this item is not being deleted, then it will be used as the `afterID`
for text edits that follow.
@param {int} beforeID ID to set on the pending edits
@param {boolean} isBeingDeleted true if the given item is being deleted. If so,
we can't use it as the `afterID` for future edits--whatever previous item
was set as the `textAfterID` is still okay.
|
[
"We",
"initially",
"put",
"new",
"edit",
"objects",
"into",
"the",
"newEdits",
"array",
"so",
"that",
"we",
"can",
"fix",
"them",
"up",
"with",
"proper",
"positioning",
"information",
".",
"This",
"function",
"is",
"responsible",
"for",
"doing",
"that",
"fixup",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L131-L149
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function () {
if (!oldNodeMap[newChild.tagID]) {
newEdit = {
type: "elementInsert",
tag: newChild.tag,
tagID: newChild.tagID,
parentID: newChild.parent.tagID,
attributes: newChild.attributes
};
newEdits.push(newEdit);
// This newly inserted node needs to have edits generated for its
// children, so we add it to the queue.
newElements.push(newChild);
// A textInsert edit that follows this elementInsert should use
// this element's ID.
textAfterID = newChild.tagID;
// new element means we need to move on to compare the next
// of the current tree with the one from the old tree that we
// just compared
newIndex++;
return true;
}
return false;
}
|
javascript
|
function () {
if (!oldNodeMap[newChild.tagID]) {
newEdit = {
type: "elementInsert",
tag: newChild.tag,
tagID: newChild.tagID,
parentID: newChild.parent.tagID,
attributes: newChild.attributes
};
newEdits.push(newEdit);
// This newly inserted node needs to have edits generated for its
// children, so we add it to the queue.
newElements.push(newChild);
// A textInsert edit that follows this elementInsert should use
// this element's ID.
textAfterID = newChild.tagID;
// new element means we need to move on to compare the next
// of the current tree with the one from the old tree that we
// just compared
newIndex++;
return true;
}
return false;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"oldNodeMap",
"[",
"newChild",
".",
"tagID",
"]",
")",
"{",
"newEdit",
"=",
"{",
"type",
":",
"\"elementInsert\"",
",",
"tag",
":",
"newChild",
".",
"tag",
",",
"tagID",
":",
"newChild",
".",
"tagID",
",",
"parentID",
":",
"newChild",
".",
"parent",
".",
"tagID",
",",
"attributes",
":",
"newChild",
".",
"attributes",
"}",
";",
"newEdits",
".",
"push",
"(",
"newEdit",
")",
";",
"newElements",
".",
"push",
"(",
"newChild",
")",
";",
"textAfterID",
"=",
"newChild",
".",
"tagID",
";",
"newIndex",
"++",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
If the current element was not in the old DOM, then we will create
an elementInsert edit for it.
If the element was in the old DOM, this will return false and the
main loop will either spot this element later in the child list
or the element has been moved.
@return {boolean} true if an elementInsert was created
|
[
"If",
"the",
"current",
"element",
"was",
"not",
"in",
"the",
"old",
"DOM",
"then",
"we",
"will",
"create",
"an",
"elementInsert",
"edit",
"for",
"it",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L161-L188
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function () {
if (!newNodeMap[oldChild.tagID]) {
// We can finalize existing edits relative to this node *before* it's
// deleted.
finalizeNewEdits(oldChild.tagID, true);
newEdit = {
type: "elementDelete",
tagID: oldChild.tagID
};
newEdits.push(newEdit);
// deleted element means we need to move on to compare the next
// of the old tree with the one from the current tree that we
// just compared
oldIndex++;
return true;
}
return false;
}
|
javascript
|
function () {
if (!newNodeMap[oldChild.tagID]) {
// We can finalize existing edits relative to this node *before* it's
// deleted.
finalizeNewEdits(oldChild.tagID, true);
newEdit = {
type: "elementDelete",
tagID: oldChild.tagID
};
newEdits.push(newEdit);
// deleted element means we need to move on to compare the next
// of the old tree with the one from the current tree that we
// just compared
oldIndex++;
return true;
}
return false;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"newNodeMap",
"[",
"oldChild",
".",
"tagID",
"]",
")",
"{",
"finalizeNewEdits",
"(",
"oldChild",
".",
"tagID",
",",
"true",
")",
";",
"newEdit",
"=",
"{",
"type",
":",
"\"elementDelete\"",
",",
"tagID",
":",
"oldChild",
".",
"tagID",
"}",
";",
"newEdits",
".",
"push",
"(",
"newEdit",
")",
";",
"oldIndex",
"++",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
If the old element that we're looking at does not appear in the new
DOM, that means it was deleted and we'll create an elementDelete edit.
If the element is in the new DOM, then this will return false and
the main loop with either spot this node later on or the element
has been moved.
@return {boolean} true if elementDelete was generated
|
[
"If",
"the",
"old",
"element",
"that",
"we",
"re",
"looking",
"at",
"does",
"not",
"appear",
"in",
"the",
"new",
"DOM",
"that",
"means",
"it",
"was",
"deleted",
"and",
"we",
"ll",
"create",
"an",
"elementDelete",
"edit",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L200-L219
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function () {
newEdit = {
type: "textInsert",
content: newChild.content,
parentID: newChild.parent.tagID
};
// text changes will generally have afterID and beforeID, but we make
// special note if it's the first child.
if (textAfterID) {
newEdit.afterID = textAfterID;
} else {
newEdit.firstChild = true;
}
newEdits.push(newEdit);
// The text node is in the new tree, so we move to the next new tree item
newIndex++;
}
|
javascript
|
function () {
newEdit = {
type: "textInsert",
content: newChild.content,
parentID: newChild.parent.tagID
};
// text changes will generally have afterID and beforeID, but we make
// special note if it's the first child.
if (textAfterID) {
newEdit.afterID = textAfterID;
} else {
newEdit.firstChild = true;
}
newEdits.push(newEdit);
// The text node is in the new tree, so we move to the next new tree item
newIndex++;
}
|
[
"function",
"(",
")",
"{",
"newEdit",
"=",
"{",
"type",
":",
"\"textInsert\"",
",",
"content",
":",
"newChild",
".",
"content",
",",
"parentID",
":",
"newChild",
".",
"parent",
".",
"tagID",
"}",
";",
"if",
"(",
"textAfterID",
")",
"{",
"newEdit",
".",
"afterID",
"=",
"textAfterID",
";",
"}",
"else",
"{",
"newEdit",
".",
"firstChild",
"=",
"true",
";",
"}",
"newEdits",
".",
"push",
"(",
"newEdit",
")",
";",
"newIndex",
"++",
";",
"}"
] |
Adds a textInsert edit for a newly created text node.
|
[
"Adds",
"a",
"textInsert",
"edit",
"for",
"a",
"newly",
"created",
"text",
"node",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L224-L242
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function () {
var prev = prevNode();
if (prev && !prev.children) {
newEdit = {
type: "textReplace",
content: prev.content
};
} else {
newEdit = {
type: "textDelete"
};
}
// When elements are deleted or moved from the old set of children, you
// can end up with multiple text nodes in a row. A single textReplace edit
// will take care of those (and will contain all of the right content since
// the text nodes between elements in the new DOM are merged together).
// The check below looks to see if we're already in the process of adding
// a textReplace edit following the same element.
var previousEdit = newEdits.length > 0 && newEdits[newEdits.length - 1];
if (previousEdit && previousEdit.type === "textReplace" &&
previousEdit.afterID === textAfterID) {
oldIndex++;
return;
}
newEdit.parentID = oldChild.parent.tagID;
// If there was only one child previously, we just pass along
// textDelete/textReplace with the parentID and the browser will
// clear all of the children
if (oldChild.parent.children.length === 1) {
newEdits.push(newEdit);
} else {
if (textAfterID) {
newEdit.afterID = textAfterID;
}
newEdits.push(newEdit);
}
// This text appeared in the old tree but not the new one, so we
// increment the old children counter.
oldIndex++;
}
|
javascript
|
function () {
var prev = prevNode();
if (prev && !prev.children) {
newEdit = {
type: "textReplace",
content: prev.content
};
} else {
newEdit = {
type: "textDelete"
};
}
// When elements are deleted or moved from the old set of children, you
// can end up with multiple text nodes in a row. A single textReplace edit
// will take care of those (and will contain all of the right content since
// the text nodes between elements in the new DOM are merged together).
// The check below looks to see if we're already in the process of adding
// a textReplace edit following the same element.
var previousEdit = newEdits.length > 0 && newEdits[newEdits.length - 1];
if (previousEdit && previousEdit.type === "textReplace" &&
previousEdit.afterID === textAfterID) {
oldIndex++;
return;
}
newEdit.parentID = oldChild.parent.tagID;
// If there was only one child previously, we just pass along
// textDelete/textReplace with the parentID and the browser will
// clear all of the children
if (oldChild.parent.children.length === 1) {
newEdits.push(newEdit);
} else {
if (textAfterID) {
newEdit.afterID = textAfterID;
}
newEdits.push(newEdit);
}
// This text appeared in the old tree but not the new one, so we
// increment the old children counter.
oldIndex++;
}
|
[
"function",
"(",
")",
"{",
"var",
"prev",
"=",
"prevNode",
"(",
")",
";",
"if",
"(",
"prev",
"&&",
"!",
"prev",
".",
"children",
")",
"{",
"newEdit",
"=",
"{",
"type",
":",
"\"textReplace\"",
",",
"content",
":",
"prev",
".",
"content",
"}",
";",
"}",
"else",
"{",
"newEdit",
"=",
"{",
"type",
":",
"\"textDelete\"",
"}",
";",
"}",
"var",
"previousEdit",
"=",
"newEdits",
".",
"length",
">",
"0",
"&&",
"newEdits",
"[",
"newEdits",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"previousEdit",
"&&",
"previousEdit",
".",
"type",
"===",
"\"textReplace\"",
"&&",
"previousEdit",
".",
"afterID",
"===",
"textAfterID",
")",
"{",
"oldIndex",
"++",
";",
"return",
";",
"}",
"newEdit",
".",
"parentID",
"=",
"oldChild",
".",
"parent",
".",
"tagID",
";",
"if",
"(",
"oldChild",
".",
"parent",
".",
"children",
".",
"length",
"===",
"1",
")",
"{",
"newEdits",
".",
"push",
"(",
"newEdit",
")",
";",
"}",
"else",
"{",
"if",
"(",
"textAfterID",
")",
"{",
"newEdit",
".",
"afterID",
"=",
"textAfterID",
";",
"}",
"newEdits",
".",
"push",
"(",
"newEdit",
")",
";",
"}",
"oldIndex",
"++",
";",
"}"
] |
Adds a textDelete edit for text node that is not in the new tree.
Note that we actually create a textReplace rather than a textDelete
if the previous node in current tree was a text node. We do this because
text nodes are not individually addressable and a delete event would
end up clearing out both that previous text node that we want to keep
and this text node that we want to eliminate. Instead, we just log
a textReplace which will result in the deletion of this node and
the maintaining of the old content.
|
[
"Adds",
"a",
"textDelete",
"edit",
"for",
"text",
"node",
"that",
"is",
"not",
"in",
"the",
"new",
"tree",
".",
"Note",
"that",
"we",
"actually",
"create",
"a",
"textReplace",
"rather",
"than",
"a",
"textDelete",
"if",
"the",
"previous",
"node",
"in",
"current",
"tree",
"was",
"a",
"text",
"node",
".",
"We",
"do",
"this",
"because",
"text",
"nodes",
"are",
"not",
"individually",
"addressable",
"and",
"a",
"delete",
"event",
"would",
"end",
"up",
"clearing",
"out",
"both",
"that",
"previous",
"text",
"node",
"that",
"we",
"want",
"to",
"keep",
"and",
"this",
"text",
"node",
"that",
"we",
"want",
"to",
"eliminate",
".",
"Instead",
"we",
"just",
"log",
"a",
"textReplace",
"which",
"will",
"result",
"in",
"the",
"deletion",
"of",
"this",
"node",
"and",
"the",
"maintaining",
"of",
"the",
"old",
"content",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L266-L309
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function () {
// This check looks a little strange, but it suits what we're trying
// to do: as we're walking through the children, a child node that has moved
// from one parent to another will be found but would look like some kind
// of insert. The check that we're doing here is looking up the current
// child's ID in the *old* map and seeing if this child used to have a
// different parent.
var possiblyMovedElement = oldNodeMap[newChild.tagID];
if (possiblyMovedElement &&
newParent.tagID !== getParentID(possiblyMovedElement)) {
newEdit = {
type: "elementMove",
tagID: newChild.tagID,
parentID: newChild.parent.tagID
};
moves.push(newEdit.tagID);
newEdits.push(newEdit);
// this element in the new tree was a move to this spot, so we can move
// on to the next child in the new tree.
newIndex++;
return true;
}
return false;
}
|
javascript
|
function () {
// This check looks a little strange, but it suits what we're trying
// to do: as we're walking through the children, a child node that has moved
// from one parent to another will be found but would look like some kind
// of insert. The check that we're doing here is looking up the current
// child's ID in the *old* map and seeing if this child used to have a
// different parent.
var possiblyMovedElement = oldNodeMap[newChild.tagID];
if (possiblyMovedElement &&
newParent.tagID !== getParentID(possiblyMovedElement)) {
newEdit = {
type: "elementMove",
tagID: newChild.tagID,
parentID: newChild.parent.tagID
};
moves.push(newEdit.tagID);
newEdits.push(newEdit);
// this element in the new tree was a move to this spot, so we can move
// on to the next child in the new tree.
newIndex++;
return true;
}
return false;
}
|
[
"function",
"(",
")",
"{",
"var",
"possiblyMovedElement",
"=",
"oldNodeMap",
"[",
"newChild",
".",
"tagID",
"]",
";",
"if",
"(",
"possiblyMovedElement",
"&&",
"newParent",
".",
"tagID",
"!==",
"getParentID",
"(",
"possiblyMovedElement",
")",
")",
"{",
"newEdit",
"=",
"{",
"type",
":",
"\"elementMove\"",
",",
"tagID",
":",
"newChild",
".",
"tagID",
",",
"parentID",
":",
"newChild",
".",
"parent",
".",
"tagID",
"}",
";",
"moves",
".",
"push",
"(",
"newEdit",
".",
"tagID",
")",
";",
"newEdits",
".",
"push",
"(",
"newEdit",
")",
";",
"newIndex",
"++",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Adds an elementMove edit if the parent has changed between the old and new trees.
These are fairly infrequent and generally occur if you make a change across
tag boundaries.
@return {boolean} true if an elementMove was generated
|
[
"Adds",
"an",
"elementMove",
"edit",
"if",
"the",
"parent",
"has",
"changed",
"between",
"the",
"old",
"and",
"new",
"trees",
".",
"These",
"are",
"fairly",
"infrequent",
"and",
"generally",
"occur",
"if",
"you",
"make",
"a",
"change",
"across",
"tag",
"boundaries",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L318-L343
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function (oldChild) {
var oldChildInNewTree = newNodeMap[oldChild.tagID];
return oldChild.children && oldChildInNewTree && getParentID(oldChild) !== getParentID(oldChildInNewTree);
}
|
javascript
|
function (oldChild) {
var oldChildInNewTree = newNodeMap[oldChild.tagID];
return oldChild.children && oldChildInNewTree && getParentID(oldChild) !== getParentID(oldChildInNewTree);
}
|
[
"function",
"(",
"oldChild",
")",
"{",
"var",
"oldChildInNewTree",
"=",
"newNodeMap",
"[",
"oldChild",
".",
"tagID",
"]",
";",
"return",
"oldChild",
".",
"children",
"&&",
"oldChildInNewTree",
"&&",
"getParentID",
"(",
"oldChild",
")",
"!==",
"getParentID",
"(",
"oldChildInNewTree",
")",
";",
"}"
] |
Looks to see if the element in the old tree has moved by checking its
current and former parents.
@return {boolean} true if the element has moved
|
[
"Looks",
"to",
"see",
"if",
"the",
"element",
"in",
"the",
"old",
"tree",
"has",
"moved",
"by",
"checking",
"its",
"current",
"and",
"former",
"parents",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L351-L355
|
train
|
|
adobe/brackets
|
src/language/HTMLDOMDiff.js
|
function (delta) {
edits.push.apply(edits, delta.edits);
moves.push.apply(moves, delta.moves);
queue.push.apply(queue, delta.newElements);
}
|
javascript
|
function (delta) {
edits.push.apply(edits, delta.edits);
moves.push.apply(moves, delta.moves);
queue.push.apply(queue, delta.newElements);
}
|
[
"function",
"(",
"delta",
")",
"{",
"edits",
".",
"push",
".",
"apply",
"(",
"edits",
",",
"delta",
".",
"edits",
")",
";",
"moves",
".",
"push",
".",
"apply",
"(",
"moves",
",",
"delta",
".",
"moves",
")",
";",
"queue",
".",
"push",
".",
"apply",
"(",
"queue",
",",
"delta",
".",
"newElements",
")",
";",
"}"
] |
Aggregates the child edits in the proper data structures.
@param {Object} delta edits, moves and newElements to add
|
[
"Aggregates",
"the",
"child",
"edits",
"in",
"the",
"proper",
"data",
"structures",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L561-L565
|
train
|
|
adobe/brackets
|
src/editor/ImageViewer.js
|
_handleFileSystemChange
|
function _handleFileSystemChange(event, entry, added, removed) {
// this may have been called because files were added
// or removed to the file system. We don't care about those
if (!entry || entry.isDirectory) {
return;
}
// Look for a viewer for the changed file
var viewer = _viewers[entry.fullPath];
// viewer found, call its refresh method
if (viewer) {
viewer.refresh();
}
}
|
javascript
|
function _handleFileSystemChange(event, entry, added, removed) {
// this may have been called because files were added
// or removed to the file system. We don't care about those
if (!entry || entry.isDirectory) {
return;
}
// Look for a viewer for the changed file
var viewer = _viewers[entry.fullPath];
// viewer found, call its refresh method
if (viewer) {
viewer.refresh();
}
}
|
[
"function",
"_handleFileSystemChange",
"(",
"event",
",",
"entry",
",",
"added",
",",
"removed",
")",
"{",
"if",
"(",
"!",
"entry",
"||",
"entry",
".",
"isDirectory",
")",
"{",
"return",
";",
"}",
"var",
"viewer",
"=",
"_viewers",
"[",
"entry",
".",
"fullPath",
"]",
";",
"if",
"(",
"viewer",
")",
"{",
"viewer",
".",
"refresh",
"(",
")",
";",
"}",
"}"
] |
Handles file system change events so we can refresh
image viewers for the files that changed on disk due to external editors
@param {jQuery.event} event - event object
@param {?File} file - file object that changed
@param {Array.<FileSystemEntry>=} added If entry is a Directory, contains zero or more added children
@param {Array.<FileSystemEntry>=} removed If entry is a Directory, contains zero or more removed children
|
[
"Handles",
"file",
"system",
"change",
"events",
"so",
"we",
"can",
"refresh",
"image",
"viewers",
"for",
"the",
"files",
"that",
"changed",
"on",
"disk",
"due",
"to",
"external",
"editors"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/ImageViewer.js#L437-L451
|
train
|
adobe/brackets
|
src/view/ViewCommandHandlers.js
|
setFontSize
|
function setFontSize(fontSize) {
if (currFontSize === fontSize) {
return;
}
_removeDynamicFontSize();
if (fontSize) {
_addDynamicFontSize(fontSize);
}
// Update scroll metrics in viewed editors
_.forEach(MainViewManager.getPaneIdList(), function (paneId) {
var currentPath = MainViewManager.getCurrentlyViewedPath(paneId),
doc = currentPath && DocumentManager.getOpenDocumentForPath(currentPath);
if (doc && doc._masterEditor) {
_updateScroll(doc._masterEditor, fontSize);
}
});
exports.trigger("fontSizeChange", fontSize, currFontSize);
currFontSize = fontSize;
prefs.set("fontSize", fontSize);
}
|
javascript
|
function setFontSize(fontSize) {
if (currFontSize === fontSize) {
return;
}
_removeDynamicFontSize();
if (fontSize) {
_addDynamicFontSize(fontSize);
}
// Update scroll metrics in viewed editors
_.forEach(MainViewManager.getPaneIdList(), function (paneId) {
var currentPath = MainViewManager.getCurrentlyViewedPath(paneId),
doc = currentPath && DocumentManager.getOpenDocumentForPath(currentPath);
if (doc && doc._masterEditor) {
_updateScroll(doc._masterEditor, fontSize);
}
});
exports.trigger("fontSizeChange", fontSize, currFontSize);
currFontSize = fontSize;
prefs.set("fontSize", fontSize);
}
|
[
"function",
"setFontSize",
"(",
"fontSize",
")",
"{",
"if",
"(",
"currFontSize",
"===",
"fontSize",
")",
"{",
"return",
";",
"}",
"_removeDynamicFontSize",
"(",
")",
";",
"if",
"(",
"fontSize",
")",
"{",
"_addDynamicFontSize",
"(",
"fontSize",
")",
";",
"}",
"_",
".",
"forEach",
"(",
"MainViewManager",
".",
"getPaneIdList",
"(",
")",
",",
"function",
"(",
"paneId",
")",
"{",
"var",
"currentPath",
"=",
"MainViewManager",
".",
"getCurrentlyViewedPath",
"(",
"paneId",
")",
",",
"doc",
"=",
"currentPath",
"&&",
"DocumentManager",
".",
"getOpenDocumentForPath",
"(",
"currentPath",
")",
";",
"if",
"(",
"doc",
"&&",
"doc",
".",
"_masterEditor",
")",
"{",
"_updateScroll",
"(",
"doc",
".",
"_masterEditor",
",",
"fontSize",
")",
";",
"}",
"}",
")",
";",
"exports",
".",
"trigger",
"(",
"\"fontSizeChange\"",
",",
"fontSize",
",",
"currFontSize",
")",
";",
"currFontSize",
"=",
"fontSize",
";",
"prefs",
".",
"set",
"(",
"\"fontSize\"",
",",
"fontSize",
")",
";",
"}"
] |
Font size setter to set the font size for the document editor
@param {string} fontSize The font size with size unit as 'px' or 'em'
|
[
"Font",
"size",
"setter",
"to",
"set",
"the",
"font",
"size",
"for",
"the",
"document",
"editor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L236-L258
|
train
|
adobe/brackets
|
src/view/ViewCommandHandlers.js
|
setFontFamily
|
function setFontFamily(fontFamily) {
var editor = EditorManager.getCurrentFullEditor();
if (currFontFamily === fontFamily) {
return;
}
_removeDynamicFontFamily();
if (fontFamily) {
_addDynamicFontFamily(fontFamily);
}
exports.trigger("fontFamilyChange", fontFamily, currFontFamily);
currFontFamily = fontFamily;
prefs.set("fontFamily", fontFamily);
if (editor) {
editor.refreshAll();
}
}
|
javascript
|
function setFontFamily(fontFamily) {
var editor = EditorManager.getCurrentFullEditor();
if (currFontFamily === fontFamily) {
return;
}
_removeDynamicFontFamily();
if (fontFamily) {
_addDynamicFontFamily(fontFamily);
}
exports.trigger("fontFamilyChange", fontFamily, currFontFamily);
currFontFamily = fontFamily;
prefs.set("fontFamily", fontFamily);
if (editor) {
editor.refreshAll();
}
}
|
[
"function",
"setFontFamily",
"(",
"fontFamily",
")",
"{",
"var",
"editor",
"=",
"EditorManager",
".",
"getCurrentFullEditor",
"(",
")",
";",
"if",
"(",
"currFontFamily",
"===",
"fontFamily",
")",
"{",
"return",
";",
"}",
"_removeDynamicFontFamily",
"(",
")",
";",
"if",
"(",
"fontFamily",
")",
"{",
"_addDynamicFontFamily",
"(",
"fontFamily",
")",
";",
"}",
"exports",
".",
"trigger",
"(",
"\"fontFamilyChange\"",
",",
"fontFamily",
",",
"currFontFamily",
")",
";",
"currFontFamily",
"=",
"fontFamily",
";",
"prefs",
".",
"set",
"(",
"\"fontFamily\"",
",",
"fontFamily",
")",
";",
"if",
"(",
"editor",
")",
"{",
"editor",
".",
"refreshAll",
"(",
")",
";",
"}",
"}"
] |
Font family setter to set the font family for the document editor
@param {string} fontFamily The font family to be set. It can be a string with multiple comma separated fonts
|
[
"Font",
"family",
"setter",
"to",
"set",
"the",
"font",
"family",
"for",
"the",
"document",
"editor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L273-L292
|
train
|
adobe/brackets
|
src/view/ViewCommandHandlers.js
|
init
|
function init() {
currFontFamily = prefs.get("fontFamily");
_addDynamicFontFamily(currFontFamily);
currFontSize = prefs.get("fontSize");
_addDynamicFontSize(currFontSize);
_updateUI();
}
|
javascript
|
function init() {
currFontFamily = prefs.get("fontFamily");
_addDynamicFontFamily(currFontFamily);
currFontSize = prefs.get("fontSize");
_addDynamicFontSize(currFontSize);
_updateUI();
}
|
[
"function",
"init",
"(",
")",
"{",
"currFontFamily",
"=",
"prefs",
".",
"get",
"(",
"\"fontFamily\"",
")",
";",
"_addDynamicFontFamily",
"(",
"currFontFamily",
")",
";",
"currFontSize",
"=",
"prefs",
".",
"get",
"(",
"\"fontSize\"",
")",
";",
"_addDynamicFontSize",
"(",
"currFontSize",
")",
";",
"_updateUI",
"(",
")",
";",
"}"
] |
Initializes the different settings that need to loaded
|
[
"Initializes",
"the",
"different",
"settings",
"that",
"need",
"to",
"loaded"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L393-L399
|
train
|
adobe/brackets
|
src/view/ViewCommandHandlers.js
|
restoreFontSize
|
function restoreFontSize() {
var fsStyle = prefs.get("fontSize"),
fsAdjustment = PreferencesManager.getViewState("fontSizeAdjustment");
if (fsAdjustment) {
// Always remove the old view state even if we also have the new view state.
PreferencesManager.setViewState("fontSizeAdjustment");
if (!fsStyle) {
// Migrate the old view state to the new one.
fsStyle = (DEFAULT_FONT_SIZE + fsAdjustment) + "px";
prefs.set("fontSize", fsStyle);
}
}
if (fsStyle) {
_removeDynamicFontSize();
_addDynamicFontSize(fsStyle);
}
}
|
javascript
|
function restoreFontSize() {
var fsStyle = prefs.get("fontSize"),
fsAdjustment = PreferencesManager.getViewState("fontSizeAdjustment");
if (fsAdjustment) {
// Always remove the old view state even if we also have the new view state.
PreferencesManager.setViewState("fontSizeAdjustment");
if (!fsStyle) {
// Migrate the old view state to the new one.
fsStyle = (DEFAULT_FONT_SIZE + fsAdjustment) + "px";
prefs.set("fontSize", fsStyle);
}
}
if (fsStyle) {
_removeDynamicFontSize();
_addDynamicFontSize(fsStyle);
}
}
|
[
"function",
"restoreFontSize",
"(",
")",
"{",
"var",
"fsStyle",
"=",
"prefs",
".",
"get",
"(",
"\"fontSize\"",
")",
",",
"fsAdjustment",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"fontSizeAdjustment\"",
")",
";",
"if",
"(",
"fsAdjustment",
")",
"{",
"PreferencesManager",
".",
"setViewState",
"(",
"\"fontSizeAdjustment\"",
")",
";",
"if",
"(",
"!",
"fsStyle",
")",
"{",
"fsStyle",
"=",
"(",
"DEFAULT_FONT_SIZE",
"+",
"fsAdjustment",
")",
"+",
"\"px\"",
";",
"prefs",
".",
"set",
"(",
"\"fontSize\"",
",",
"fsStyle",
")",
";",
"}",
"}",
"if",
"(",
"fsStyle",
")",
"{",
"_removeDynamicFontSize",
"(",
")",
";",
"_addDynamicFontSize",
"(",
"fsStyle",
")",
";",
"}",
"}"
] |
Restores the font size using the saved style and migrates the old fontSizeAdjustment
view state to the new fontSize, when required
|
[
"Restores",
"the",
"font",
"size",
"using",
"the",
"saved",
"style",
"and",
"migrates",
"the",
"old",
"fontSizeAdjustment",
"view",
"state",
"to",
"the",
"new",
"fontSize",
"when",
"required"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L405-L424
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
CubicBezier
|
function CubicBezier(coordinates) {
if (typeof coordinates === "string") {
this.coordinates = coordinates.split(",");
} else {
this.coordinates = coordinates;
}
if (!this.coordinates) {
throw "No offsets were defined";
}
this.coordinates = this.coordinates.map(function (n) { return +n; });
var i;
for (i = 3; i >= 0; i--) {
var xy = this.coordinates[i];
if (isNaN(xy) || (((i % 2) === 0) && (xy < 0 || xy > 1))) {
throw "Wrong coordinate at " + i + "(" + xy + ")";
}
}
}
|
javascript
|
function CubicBezier(coordinates) {
if (typeof coordinates === "string") {
this.coordinates = coordinates.split(",");
} else {
this.coordinates = coordinates;
}
if (!this.coordinates) {
throw "No offsets were defined";
}
this.coordinates = this.coordinates.map(function (n) { return +n; });
var i;
for (i = 3; i >= 0; i--) {
var xy = this.coordinates[i];
if (isNaN(xy) || (((i % 2) === 0) && (xy < 0 || xy > 1))) {
throw "Wrong coordinate at " + i + "(" + xy + ")";
}
}
}
|
[
"function",
"CubicBezier",
"(",
"coordinates",
")",
"{",
"if",
"(",
"typeof",
"coordinates",
"===",
"\"string\"",
")",
"{",
"this",
".",
"coordinates",
"=",
"coordinates",
".",
"split",
"(",
"\",\"",
")",
";",
"}",
"else",
"{",
"this",
".",
"coordinates",
"=",
"coordinates",
";",
"}",
"if",
"(",
"!",
"this",
".",
"coordinates",
")",
"{",
"throw",
"\"No offsets were defined\"",
";",
"}",
"this",
".",
"coordinates",
"=",
"this",
".",
"coordinates",
".",
"map",
"(",
"function",
"(",
"n",
")",
"{",
"return",
"+",
"n",
";",
"}",
")",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"3",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"xy",
"=",
"this",
".",
"coordinates",
"[",
"i",
"]",
";",
"if",
"(",
"isNaN",
"(",
"xy",
")",
"||",
"(",
"(",
"(",
"i",
"%",
"2",
")",
"===",
"0",
")",
"&&",
"(",
"xy",
"<",
"0",
"||",
"xy",
">",
"1",
")",
")",
")",
"{",
"throw",
"\"Wrong coordinate at \"",
"+",
"i",
"+",
"\"(\"",
"+",
"xy",
"+",
"\")\"",
";",
"}",
"}",
"}"
] |
CubicBezier object constructor
@param {string|Array.number[4]} coordinates Four parameters passes to cubic-bezier()
either in string or array format.
|
[
"CubicBezier",
"object",
"constructor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L50-L70
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
BezierCanvas
|
function BezierCanvas(canvas, bezier, padding) {
this.canvas = canvas;
this.bezier = bezier;
this.padding = this.getPadding(padding);
// Convert to a cartesian coordinate system with axes from 0 to 1
var ctx = this.canvas.getContext("2d"),
p = this.padding;
ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * 0.5 * (1 - p[0] - p[2]));
ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2])) - 0.5);
}
|
javascript
|
function BezierCanvas(canvas, bezier, padding) {
this.canvas = canvas;
this.bezier = bezier;
this.padding = this.getPadding(padding);
// Convert to a cartesian coordinate system with axes from 0 to 1
var ctx = this.canvas.getContext("2d"),
p = this.padding;
ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * 0.5 * (1 - p[0] - p[2]));
ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2])) - 0.5);
}
|
[
"function",
"BezierCanvas",
"(",
"canvas",
",",
"bezier",
",",
"padding",
")",
"{",
"this",
".",
"canvas",
"=",
"canvas",
";",
"this",
".",
"bezier",
"=",
"bezier",
";",
"this",
".",
"padding",
"=",
"this",
".",
"getPadding",
"(",
"padding",
")",
";",
"var",
"ctx",
"=",
"this",
".",
"canvas",
".",
"getContext",
"(",
"\"2d\"",
")",
",",
"p",
"=",
"this",
".",
"padding",
";",
"ctx",
".",
"scale",
"(",
"canvas",
".",
"width",
"*",
"(",
"1",
"-",
"p",
"[",
"1",
"]",
"-",
"p",
"[",
"3",
"]",
")",
",",
"-",
"canvas",
".",
"height",
"*",
"0.5",
"*",
"(",
"1",
"-",
"p",
"[",
"0",
"]",
"-",
"p",
"[",
"2",
"]",
")",
")",
";",
"ctx",
".",
"translate",
"(",
"p",
"[",
"3",
"]",
"/",
"(",
"1",
"-",
"p",
"[",
"1",
"]",
"-",
"p",
"[",
"3",
"]",
")",
",",
"(",
"-",
"1",
"-",
"p",
"[",
"0",
"]",
"/",
"(",
"1",
"-",
"p",
"[",
"0",
"]",
"-",
"p",
"[",
"2",
"]",
")",
")",
"-",
"0.5",
")",
";",
"}"
] |
BezierCanvas object constructor
@param {Element} canvas Inline editor <canvas> element
@param {CubicBezier} bezier Associated CubicBezier object
@param {number|Array.number} padding Element padding
|
[
"BezierCanvas",
"object",
"constructor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L79-L90
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
function (element) {
var p = this.padding,
w = this.canvas.width,
h = this.canvas.height * 0.5;
// Convert padding percentage to actual padding
p = p.map(function (a, i) {
return a * ((i % 2) ? w : h);
});
return [
this.prettify((parseInt($(element).css("left"), 10) - p[3]) / (w + p[1] + p[3])),
this.prettify((h - parseInt($(element).css("top"), 10) - p[2]) / (h - p[0] - p[2]))
];
}
|
javascript
|
function (element) {
var p = this.padding,
w = this.canvas.width,
h = this.canvas.height * 0.5;
// Convert padding percentage to actual padding
p = p.map(function (a, i) {
return a * ((i % 2) ? w : h);
});
return [
this.prettify((parseInt($(element).css("left"), 10) - p[3]) / (w + p[1] + p[3])),
this.prettify((h - parseInt($(element).css("top"), 10) - p[2]) / (h - p[0] - p[2]))
];
}
|
[
"function",
"(",
"element",
")",
"{",
"var",
"p",
"=",
"this",
".",
"padding",
",",
"w",
"=",
"this",
".",
"canvas",
".",
"width",
",",
"h",
"=",
"this",
".",
"canvas",
".",
"height",
"*",
"0.5",
";",
"p",
"=",
"p",
".",
"map",
"(",
"function",
"(",
"a",
",",
"i",
")",
"{",
"return",
"a",
"*",
"(",
"(",
"i",
"%",
"2",
")",
"?",
"w",
":",
"h",
")",
";",
"}",
")",
";",
"return",
"[",
"this",
".",
"prettify",
"(",
"(",
"parseInt",
"(",
"$",
"(",
"element",
")",
".",
"css",
"(",
"\"left\"",
")",
",",
"10",
")",
"-",
"p",
"[",
"3",
"]",
")",
"/",
"(",
"w",
"+",
"p",
"[",
"1",
"]",
"+",
"p",
"[",
"3",
"]",
")",
")",
",",
"this",
".",
"prettify",
"(",
"(",
"h",
"-",
"parseInt",
"(",
"$",
"(",
"element",
")",
".",
"css",
"(",
"\"top\"",
")",
",",
"10",
")",
"-",
"p",
"[",
"2",
"]",
")",
"/",
"(",
"h",
"-",
"p",
"[",
"0",
"]",
"-",
"p",
"[",
"2",
"]",
")",
")",
"]",
";",
"}"
] |
Get CSS left, top offsets for endpoint handle
@param {Element} element Endpoint handle <button> element
@return {Array.string[2]}
|
[
"Get",
"CSS",
"left",
"top",
"offsets",
"for",
"endpoint",
"handle"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L129-L143
|
train
|
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
function (padding) {
var p = (typeof padding === "number") ? [padding] : padding;
if (p.length === 1) {
p[1] = p[0];
}
if (p.length === 2) {
p[2] = p[0];
}
if (p.length === 3) {
p[3] = p[1];
}
return p;
}
|
javascript
|
function (padding) {
var p = (typeof padding === "number") ? [padding] : padding;
if (p.length === 1) {
p[1] = p[0];
}
if (p.length === 2) {
p[2] = p[0];
}
if (p.length === 3) {
p[3] = p[1];
}
return p;
}
|
[
"function",
"(",
"padding",
")",
"{",
"var",
"p",
"=",
"(",
"typeof",
"padding",
"===",
"\"number\"",
")",
"?",
"[",
"padding",
"]",
":",
"padding",
";",
"if",
"(",
"p",
".",
"length",
"===",
"1",
")",
"{",
"p",
"[",
"1",
"]",
"=",
"p",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"p",
".",
"length",
"===",
"2",
")",
"{",
"p",
"[",
"2",
"]",
"=",
"p",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"p",
".",
"length",
"===",
"3",
")",
"{",
"p",
"[",
"3",
"]",
"=",
"p",
"[",
"1",
"]",
";",
"}",
"return",
"p",
";",
"}"
] |
Convert CSS padding shorthand to longhand
@param {number|Array.number} padding Element padding
@return {Array.number}
|
[
"Convert",
"CSS",
"padding",
"shorthand",
"to",
"longhand"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L218-L232
|
train
|
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
handlePointMove
|
function handlePointMove(e, x, y) {
var self = e.target,
bezierEditor = self.bezierEditor;
// Helper function to redraw curve
function mouseMoveRedraw() {
if (!bezierEditor.dragElement) {
animationRequest = null;
return;
}
// Update code
bezierEditor._commitTimingFunction();
bezierEditor._updateCanvas();
animationRequest = window.requestAnimationFrame(mouseMoveRedraw);
}
// This is a dragging state, but left button is no longer down, so mouse
// exited element, was released, and re-entered element. Treat like a drop.
if (bezierEditor.dragElement && (e.which !== 1)) {
bezierEditor.dragElement = null;
bezierEditor._commitTimingFunction();
bezierEditor._updateCanvas();
bezierEditor = null;
return;
}
// Constrain time (x-axis) to 0 to 1 range. Progression (y-axis) is
// theoretically not constrained, although canvas to drawing curve is
// arbitrarily constrained to -0.5 to 1.5 range.
x = Math.min(Math.max(0, x), WIDTH_MAIN);
if (bezierEditor.dragElement) {
$(bezierEditor.dragElement).css({
left: x + "px",
top: y + "px"
});
}
// update coords
bezierEditor._cubicBezierCoords = bezierEditor.bezierCanvas
.offsetsToCoordinates(bezierEditor.P1)
.concat(bezierEditor.bezierCanvas.offsetsToCoordinates(bezierEditor.P2));
if (!animationRequest) {
animationRequest = window.requestAnimationFrame(mouseMoveRedraw);
}
}
|
javascript
|
function handlePointMove(e, x, y) {
var self = e.target,
bezierEditor = self.bezierEditor;
// Helper function to redraw curve
function mouseMoveRedraw() {
if (!bezierEditor.dragElement) {
animationRequest = null;
return;
}
// Update code
bezierEditor._commitTimingFunction();
bezierEditor._updateCanvas();
animationRequest = window.requestAnimationFrame(mouseMoveRedraw);
}
// This is a dragging state, but left button is no longer down, so mouse
// exited element, was released, and re-entered element. Treat like a drop.
if (bezierEditor.dragElement && (e.which !== 1)) {
bezierEditor.dragElement = null;
bezierEditor._commitTimingFunction();
bezierEditor._updateCanvas();
bezierEditor = null;
return;
}
// Constrain time (x-axis) to 0 to 1 range. Progression (y-axis) is
// theoretically not constrained, although canvas to drawing curve is
// arbitrarily constrained to -0.5 to 1.5 range.
x = Math.min(Math.max(0, x), WIDTH_MAIN);
if (bezierEditor.dragElement) {
$(bezierEditor.dragElement).css({
left: x + "px",
top: y + "px"
});
}
// update coords
bezierEditor._cubicBezierCoords = bezierEditor.bezierCanvas
.offsetsToCoordinates(bezierEditor.P1)
.concat(bezierEditor.bezierCanvas.offsetsToCoordinates(bezierEditor.P2));
if (!animationRequest) {
animationRequest = window.requestAnimationFrame(mouseMoveRedraw);
}
}
|
[
"function",
"handlePointMove",
"(",
"e",
",",
"x",
",",
"y",
")",
"{",
"var",
"self",
"=",
"e",
".",
"target",
",",
"bezierEditor",
"=",
"self",
".",
"bezierEditor",
";",
"function",
"mouseMoveRedraw",
"(",
")",
"{",
"if",
"(",
"!",
"bezierEditor",
".",
"dragElement",
")",
"{",
"animationRequest",
"=",
"null",
";",
"return",
";",
"}",
"bezierEditor",
".",
"_commitTimingFunction",
"(",
")",
";",
"bezierEditor",
".",
"_updateCanvas",
"(",
")",
";",
"animationRequest",
"=",
"window",
".",
"requestAnimationFrame",
"(",
"mouseMoveRedraw",
")",
";",
"}",
"if",
"(",
"bezierEditor",
".",
"dragElement",
"&&",
"(",
"e",
".",
"which",
"!==",
"1",
")",
")",
"{",
"bezierEditor",
".",
"dragElement",
"=",
"null",
";",
"bezierEditor",
".",
"_commitTimingFunction",
"(",
")",
";",
"bezierEditor",
".",
"_updateCanvas",
"(",
")",
";",
"bezierEditor",
"=",
"null",
";",
"return",
";",
"}",
"x",
"=",
"Math",
".",
"min",
"(",
"Math",
".",
"max",
"(",
"0",
",",
"x",
")",
",",
"WIDTH_MAIN",
")",
";",
"if",
"(",
"bezierEditor",
".",
"dragElement",
")",
"{",
"$",
"(",
"bezierEditor",
".",
"dragElement",
")",
".",
"css",
"(",
"{",
"left",
":",
"x",
"+",
"\"px\"",
",",
"top",
":",
"y",
"+",
"\"px\"",
"}",
")",
";",
"}",
"bezierEditor",
".",
"_cubicBezierCoords",
"=",
"bezierEditor",
".",
"bezierCanvas",
".",
"offsetsToCoordinates",
"(",
"bezierEditor",
".",
"P1",
")",
".",
"concat",
"(",
"bezierEditor",
".",
"bezierCanvas",
".",
"offsetsToCoordinates",
"(",
"bezierEditor",
".",
"P2",
")",
")",
";",
"if",
"(",
"!",
"animationRequest",
")",
"{",
"animationRequest",
"=",
"window",
".",
"requestAnimationFrame",
"(",
"mouseMoveRedraw",
")",
";",
"}",
"}"
] |
Helper function for handling point move
@param {Event} e Mouse move event
@param {number} x New horizontal position
@param {number} y New vertical position
|
[
"Helper",
"function",
"for",
"handling",
"point",
"move"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L286-L334
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
mouseMoveRedraw
|
function mouseMoveRedraw() {
if (!bezierEditor.dragElement) {
animationRequest = null;
return;
}
// Update code
bezierEditor._commitTimingFunction();
bezierEditor._updateCanvas();
animationRequest = window.requestAnimationFrame(mouseMoveRedraw);
}
|
javascript
|
function mouseMoveRedraw() {
if (!bezierEditor.dragElement) {
animationRequest = null;
return;
}
// Update code
bezierEditor._commitTimingFunction();
bezierEditor._updateCanvas();
animationRequest = window.requestAnimationFrame(mouseMoveRedraw);
}
|
[
"function",
"mouseMoveRedraw",
"(",
")",
"{",
"if",
"(",
"!",
"bezierEditor",
".",
"dragElement",
")",
"{",
"animationRequest",
"=",
"null",
";",
"return",
";",
"}",
"bezierEditor",
".",
"_commitTimingFunction",
"(",
")",
";",
"bezierEditor",
".",
"_updateCanvas",
"(",
")",
";",
"animationRequest",
"=",
"window",
".",
"requestAnimationFrame",
"(",
"mouseMoveRedraw",
")",
";",
"}"
] |
Helper function to redraw curve
|
[
"Helper",
"function",
"to",
"redraw",
"curve"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L291-L302
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
|
BezierCurveEditor
|
function BezierCurveEditor($parent, bezierCurve, callback) {
// Create the DOM structure, filling in localized strings via Mustache
this.$element = $(Mustache.render(BezierCurveEditorTemplate, Strings));
$parent.append(this.$element);
this._callback = callback;
this.dragElement = null;
// current cubic-bezier() function params
this._cubicBezierCoords = this._getCubicBezierCoords(bezierCurve);
this.hint = {};
this.hint.elem = $(".hint", this.$element);
// If function was auto-corrected, then originalString holds the original function,
// and an informational message needs to be shown
if (bezierCurve.originalString) {
TimingFunctionUtils.showHideHint(this.hint, true, bezierCurve.originalString, "cubic-bezier(" + this._cubicBezierCoords.join(", ") + ")");
} else {
TimingFunctionUtils.showHideHint(this.hint, false);
}
this.P1 = this.$element.find(".P1")[0];
this.P2 = this.$element.find(".P2")[0];
this.curve = this.$element.find(".curve")[0];
this.P1.bezierEditor = this.P2.bezierEditor = this.curve.bezierEditor = this;
this.bezierCanvas = new BezierCanvas(this.curve, null, [0, 0]);
// redraw canvas
this._updateCanvas();
$(this.curve)
.on("click", _curveClick)
.on("mousemove", _curveMouseMove);
$(this.P1)
.on("mousemove", _pointMouseMove)
.on("mousedown", _pointMouseDown)
.on("mouseup", _pointMouseUp)
.on("keydown", _pointKeyDown);
$(this.P2)
.on("mousemove", _pointMouseMove)
.on("mousedown", _pointMouseDown)
.on("mouseup", _pointMouseUp)
.on("keydown", _pointKeyDown);
}
|
javascript
|
function BezierCurveEditor($parent, bezierCurve, callback) {
// Create the DOM structure, filling in localized strings via Mustache
this.$element = $(Mustache.render(BezierCurveEditorTemplate, Strings));
$parent.append(this.$element);
this._callback = callback;
this.dragElement = null;
// current cubic-bezier() function params
this._cubicBezierCoords = this._getCubicBezierCoords(bezierCurve);
this.hint = {};
this.hint.elem = $(".hint", this.$element);
// If function was auto-corrected, then originalString holds the original function,
// and an informational message needs to be shown
if (bezierCurve.originalString) {
TimingFunctionUtils.showHideHint(this.hint, true, bezierCurve.originalString, "cubic-bezier(" + this._cubicBezierCoords.join(", ") + ")");
} else {
TimingFunctionUtils.showHideHint(this.hint, false);
}
this.P1 = this.$element.find(".P1")[0];
this.P2 = this.$element.find(".P2")[0];
this.curve = this.$element.find(".curve")[0];
this.P1.bezierEditor = this.P2.bezierEditor = this.curve.bezierEditor = this;
this.bezierCanvas = new BezierCanvas(this.curve, null, [0, 0]);
// redraw canvas
this._updateCanvas();
$(this.curve)
.on("click", _curveClick)
.on("mousemove", _curveMouseMove);
$(this.P1)
.on("mousemove", _pointMouseMove)
.on("mousedown", _pointMouseDown)
.on("mouseup", _pointMouseUp)
.on("keydown", _pointKeyDown);
$(this.P2)
.on("mousemove", _pointMouseMove)
.on("mousedown", _pointMouseDown)
.on("mouseup", _pointMouseUp)
.on("keydown", _pointKeyDown);
}
|
[
"function",
"BezierCurveEditor",
"(",
"$parent",
",",
"bezierCurve",
",",
"callback",
")",
"{",
"this",
".",
"$element",
"=",
"$",
"(",
"Mustache",
".",
"render",
"(",
"BezierCurveEditorTemplate",
",",
"Strings",
")",
")",
";",
"$parent",
".",
"append",
"(",
"this",
".",
"$element",
")",
";",
"this",
".",
"_callback",
"=",
"callback",
";",
"this",
".",
"dragElement",
"=",
"null",
";",
"this",
".",
"_cubicBezierCoords",
"=",
"this",
".",
"_getCubicBezierCoords",
"(",
"bezierCurve",
")",
";",
"this",
".",
"hint",
"=",
"{",
"}",
";",
"this",
".",
"hint",
".",
"elem",
"=",
"$",
"(",
"\".hint\"",
",",
"this",
".",
"$element",
")",
";",
"if",
"(",
"bezierCurve",
".",
"originalString",
")",
"{",
"TimingFunctionUtils",
".",
"showHideHint",
"(",
"this",
".",
"hint",
",",
"true",
",",
"bezierCurve",
".",
"originalString",
",",
"\"cubic-bezier(\"",
"+",
"this",
".",
"_cubicBezierCoords",
".",
"join",
"(",
"\", \"",
")",
"+",
"\")\"",
")",
";",
"}",
"else",
"{",
"TimingFunctionUtils",
".",
"showHideHint",
"(",
"this",
".",
"hint",
",",
"false",
")",
";",
"}",
"this",
".",
"P1",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".P1\"",
")",
"[",
"0",
"]",
";",
"this",
".",
"P2",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".P2\"",
")",
"[",
"0",
"]",
";",
"this",
".",
"curve",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".curve\"",
")",
"[",
"0",
"]",
";",
"this",
".",
"P1",
".",
"bezierEditor",
"=",
"this",
".",
"P2",
".",
"bezierEditor",
"=",
"this",
".",
"curve",
".",
"bezierEditor",
"=",
"this",
";",
"this",
".",
"bezierCanvas",
"=",
"new",
"BezierCanvas",
"(",
"this",
".",
"curve",
",",
"null",
",",
"[",
"0",
",",
"0",
"]",
")",
";",
"this",
".",
"_updateCanvas",
"(",
")",
";",
"$",
"(",
"this",
".",
"curve",
")",
".",
"on",
"(",
"\"click\"",
",",
"_curveClick",
")",
".",
"on",
"(",
"\"mousemove\"",
",",
"_curveMouseMove",
")",
";",
"$",
"(",
"this",
".",
"P1",
")",
".",
"on",
"(",
"\"mousemove\"",
",",
"_pointMouseMove",
")",
".",
"on",
"(",
"\"mousedown\"",
",",
"_pointMouseDown",
")",
".",
"on",
"(",
"\"mouseup\"",
",",
"_pointMouseUp",
")",
".",
"on",
"(",
"\"keydown\"",
",",
"_pointKeyDown",
")",
";",
"$",
"(",
"this",
".",
"P2",
")",
".",
"on",
"(",
"\"mousemove\"",
",",
"_pointMouseMove",
")",
".",
"on",
"(",
"\"mousedown\"",
",",
"_pointMouseDown",
")",
".",
"on",
"(",
"\"mouseup\"",
",",
"_pointMouseUp",
")",
".",
"on",
"(",
"\"keydown\"",
",",
"_pointKeyDown",
")",
";",
"}"
] |
Constructor for BezierCurveEditor Object. This control may be used standalone
or within an InlineTimingFunctionEditor inline widget.
@param {!jQuery} $parent DOM node into which to append the root of the bezier curve editor UI
@param {!RegExpMatch} bezierCurve RegExp match object of initially selected bezierCurve
@param {!function(string)} callback Called whenever selected bezierCurve changes
|
[
"Constructor",
"for",
"BezierCurveEditor",
"Object",
".",
"This",
"control",
"may",
"be",
"used",
"standalone",
"or",
"within",
"an",
"InlineTimingFunctionEditor",
"inline",
"widget",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L515-L560
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/StepEditor.js
|
StepCanvas
|
function StepCanvas(canvas, stepParams, padding) {
this.canvas = canvas;
this.stepParams = stepParams;
this.padding = this.getPadding(padding);
// Convert to a cartesian coordinate system with axes from 0 to 1
var ctx = this.canvas.getContext("2d"),
p = this.padding;
ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * (1 - p[0] - p[2]));
ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2])));
}
|
javascript
|
function StepCanvas(canvas, stepParams, padding) {
this.canvas = canvas;
this.stepParams = stepParams;
this.padding = this.getPadding(padding);
// Convert to a cartesian coordinate system with axes from 0 to 1
var ctx = this.canvas.getContext("2d"),
p = this.padding;
ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * (1 - p[0] - p[2]));
ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2])));
}
|
[
"function",
"StepCanvas",
"(",
"canvas",
",",
"stepParams",
",",
"padding",
")",
"{",
"this",
".",
"canvas",
"=",
"canvas",
";",
"this",
".",
"stepParams",
"=",
"stepParams",
";",
"this",
".",
"padding",
"=",
"this",
".",
"getPadding",
"(",
"padding",
")",
";",
"var",
"ctx",
"=",
"this",
".",
"canvas",
".",
"getContext",
"(",
"\"2d\"",
")",
",",
"p",
"=",
"this",
".",
"padding",
";",
"ctx",
".",
"scale",
"(",
"canvas",
".",
"width",
"*",
"(",
"1",
"-",
"p",
"[",
"1",
"]",
"-",
"p",
"[",
"3",
"]",
")",
",",
"-",
"canvas",
".",
"height",
"*",
"(",
"1",
"-",
"p",
"[",
"0",
"]",
"-",
"p",
"[",
"2",
"]",
")",
")",
";",
"ctx",
".",
"translate",
"(",
"p",
"[",
"3",
"]",
"/",
"(",
"1",
"-",
"p",
"[",
"1",
"]",
"-",
"p",
"[",
"3",
"]",
")",
",",
"(",
"-",
"1",
"-",
"p",
"[",
"0",
"]",
"/",
"(",
"1",
"-",
"p",
"[",
"0",
"]",
"-",
"p",
"[",
"2",
"]",
")",
")",
")",
";",
"}"
] |
StepCanvas object constructor
@param {Element} canvas Inline editor <canvas> element
@param {StepParameters} stepParams Associated StepParameters object
@param {number|Array.number} padding Element padding
|
[
"StepCanvas",
"object",
"constructor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/StepEditor.js#L62-L73
|
train
|
adobe/brackets
|
src/extensions/default/InlineTimingFunctionEditor/StepEditor.js
|
StepEditor
|
function StepEditor($parent, stepMatch, callback) {
// Create the DOM structure, filling in localized strings via Mustache
this.$element = $(Mustache.render(StepEditorTemplate, Strings));
$parent.append(this.$element);
this._callback = callback;
// current step function params
this._stepParams = this._getStepParams(stepMatch);
this.hint = {};
this.hint.elem = $(".hint", this.$element);
// If function was auto-corrected, then originalString holds the original function,
// and an informational message needs to be shown
if (stepMatch.originalString) {
TimingFunctionUtils.showHideHint(this.hint, true, stepMatch.originalString, "steps(" + this._stepParams.count.toString() + ", " + this._stepParams.timing + ")");
} else {
TimingFunctionUtils.showHideHint(this.hint, false);
}
this.canvas = this.$element.find(".steps")[0];
this.canvas.stepEditor = this;
// Padding (3rd param)is scaled, so 0.1 translates to 15px
// Note that this is rendered inside canvas CSS "content"
// (i.e. this does not map to CSS padding)
this.stepCanvas = new StepCanvas(this.canvas, null, [0.1]);
// redraw canvas
this._updateCanvas();
$(this.canvas).on("keydown", _canvasKeyDown);
}
|
javascript
|
function StepEditor($parent, stepMatch, callback) {
// Create the DOM structure, filling in localized strings via Mustache
this.$element = $(Mustache.render(StepEditorTemplate, Strings));
$parent.append(this.$element);
this._callback = callback;
// current step function params
this._stepParams = this._getStepParams(stepMatch);
this.hint = {};
this.hint.elem = $(".hint", this.$element);
// If function was auto-corrected, then originalString holds the original function,
// and an informational message needs to be shown
if (stepMatch.originalString) {
TimingFunctionUtils.showHideHint(this.hint, true, stepMatch.originalString, "steps(" + this._stepParams.count.toString() + ", " + this._stepParams.timing + ")");
} else {
TimingFunctionUtils.showHideHint(this.hint, false);
}
this.canvas = this.$element.find(".steps")[0];
this.canvas.stepEditor = this;
// Padding (3rd param)is scaled, so 0.1 translates to 15px
// Note that this is rendered inside canvas CSS "content"
// (i.e. this does not map to CSS padding)
this.stepCanvas = new StepCanvas(this.canvas, null, [0.1]);
// redraw canvas
this._updateCanvas();
$(this.canvas).on("keydown", _canvasKeyDown);
}
|
[
"function",
"StepEditor",
"(",
"$parent",
",",
"stepMatch",
",",
"callback",
")",
"{",
"this",
".",
"$element",
"=",
"$",
"(",
"Mustache",
".",
"render",
"(",
"StepEditorTemplate",
",",
"Strings",
")",
")",
";",
"$parent",
".",
"append",
"(",
"this",
".",
"$element",
")",
";",
"this",
".",
"_callback",
"=",
"callback",
";",
"this",
".",
"_stepParams",
"=",
"this",
".",
"_getStepParams",
"(",
"stepMatch",
")",
";",
"this",
".",
"hint",
"=",
"{",
"}",
";",
"this",
".",
"hint",
".",
"elem",
"=",
"$",
"(",
"\".hint\"",
",",
"this",
".",
"$element",
")",
";",
"if",
"(",
"stepMatch",
".",
"originalString",
")",
"{",
"TimingFunctionUtils",
".",
"showHideHint",
"(",
"this",
".",
"hint",
",",
"true",
",",
"stepMatch",
".",
"originalString",
",",
"\"steps(\"",
"+",
"this",
".",
"_stepParams",
".",
"count",
".",
"toString",
"(",
")",
"+",
"\", \"",
"+",
"this",
".",
"_stepParams",
".",
"timing",
"+",
"\")\"",
")",
";",
"}",
"else",
"{",
"TimingFunctionUtils",
".",
"showHideHint",
"(",
"this",
".",
"hint",
",",
"false",
")",
";",
"}",
"this",
".",
"canvas",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".steps\"",
")",
"[",
"0",
"]",
";",
"this",
".",
"canvas",
".",
"stepEditor",
"=",
"this",
";",
"this",
".",
"stepCanvas",
"=",
"new",
"StepCanvas",
"(",
"this",
".",
"canvas",
",",
"null",
",",
"[",
"0.1",
"]",
")",
";",
"this",
".",
"_updateCanvas",
"(",
")",
";",
"$",
"(",
"this",
".",
"canvas",
")",
".",
"on",
"(",
"\"keydown\"",
",",
"_canvasKeyDown",
")",
";",
"}"
] |
Constructor for StepEditor Object. This control may be used standalone
or within an InlineTimingFunctionEditor inline widget.
@param {!jQuery} $parent DOM node into which to append the root of the step editor UI
@param {!RegExpMatch} stepMatch RegExp match object of initially selected step function
@param {!function(string)} callback Called whenever selected step function changes
|
[
"Constructor",
"for",
"StepEditor",
"Object",
".",
"This",
"control",
"may",
"be",
"used",
"standalone",
"or",
"within",
"an",
"InlineTimingFunctionEditor",
"inline",
"widget",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/StepEditor.js#L295-L328
|
train
|
adobe/brackets
|
src/editor/CodeHintList.js
|
CodeHintList
|
function CodeHintList(editor, insertHintOnTab, maxResults) {
/**
* The list of hints to display
*
* @type {Array.<string|jQueryObject>}
*/
this.hints = [];
/**
* The selected position in the list; otherwise -1.
*
* @type {number}
*/
this.selectedIndex = -1;
/**
* The maximum number of hints to display. Can be overriden via maxCodeHints pref
*
* @type {number}
*/
this.maxResults = ValidationUtils.isIntegerInRange(maxResults, 1, 1000) ? maxResults : 50;
/**
* Is the list currently open?
*
* @type {boolean}
*/
this.opened = false;
/**
* The editor context
*
* @type {Editor}
*/
this.editor = editor;
/**
* Whether the currently selected hint should be inserted on a tab key event
*
* @type {boolean}
*/
this.insertHintOnTab = insertHintOnTab;
/**
* Pending text insertion
*
* @type {string}
*/
this.pendingText = "";
/**
* The hint selection callback function
*
* @type {Function}
*/
this.handleSelect = null;
/**
* The hint list closure callback function
*
* @type {Function}
*/
this.handleClose = null;
/**
* The hint list menu object
*
* @type {jQuery.Object}
*/
this.$hintMenu =
$("<li class='dropdown codehint-menu'></li>")
.append($("<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>")
.hide())
.append("<ul class='dropdown-menu'></ul>");
this._keydownHook = this._keydownHook.bind(this);
}
|
javascript
|
function CodeHintList(editor, insertHintOnTab, maxResults) {
/**
* The list of hints to display
*
* @type {Array.<string|jQueryObject>}
*/
this.hints = [];
/**
* The selected position in the list; otherwise -1.
*
* @type {number}
*/
this.selectedIndex = -1;
/**
* The maximum number of hints to display. Can be overriden via maxCodeHints pref
*
* @type {number}
*/
this.maxResults = ValidationUtils.isIntegerInRange(maxResults, 1, 1000) ? maxResults : 50;
/**
* Is the list currently open?
*
* @type {boolean}
*/
this.opened = false;
/**
* The editor context
*
* @type {Editor}
*/
this.editor = editor;
/**
* Whether the currently selected hint should be inserted on a tab key event
*
* @type {boolean}
*/
this.insertHintOnTab = insertHintOnTab;
/**
* Pending text insertion
*
* @type {string}
*/
this.pendingText = "";
/**
* The hint selection callback function
*
* @type {Function}
*/
this.handleSelect = null;
/**
* The hint list closure callback function
*
* @type {Function}
*/
this.handleClose = null;
/**
* The hint list menu object
*
* @type {jQuery.Object}
*/
this.$hintMenu =
$("<li class='dropdown codehint-menu'></li>")
.append($("<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>")
.hide())
.append("<ul class='dropdown-menu'></ul>");
this._keydownHook = this._keydownHook.bind(this);
}
|
[
"function",
"CodeHintList",
"(",
"editor",
",",
"insertHintOnTab",
",",
"maxResults",
")",
"{",
"this",
".",
"hints",
"=",
"[",
"]",
";",
"this",
".",
"selectedIndex",
"=",
"-",
"1",
";",
"this",
".",
"maxResults",
"=",
"ValidationUtils",
".",
"isIntegerInRange",
"(",
"maxResults",
",",
"1",
",",
"1000",
")",
"?",
"maxResults",
":",
"50",
";",
"this",
".",
"opened",
"=",
"false",
";",
"this",
".",
"editor",
"=",
"editor",
";",
"this",
".",
"insertHintOnTab",
"=",
"insertHintOnTab",
";",
"this",
".",
"pendingText",
"=",
"\"\"",
";",
"this",
".",
"handleSelect",
"=",
"null",
";",
"this",
".",
"handleClose",
"=",
"null",
";",
"this",
".",
"$hintMenu",
"=",
"$",
"(",
"\"<li class='dropdown codehint-menu'></li>\"",
")",
".",
"append",
"(",
"$",
"(",
"\"<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>\"",
")",
".",
"hide",
"(",
")",
")",
".",
"append",
"(",
"\"<ul class='dropdown-menu'></ul>\"",
")",
";",
"this",
".",
"_keydownHook",
"=",
"this",
".",
"_keydownHook",
".",
"bind",
"(",
"this",
")",
";",
"}"
] |
Displays a popup list of hints for a given editor context.
@constructor
@param {Editor} editor
@param {boolean} insertHintOnTab Whether pressing tab inserts the selected hint
@param {number} maxResults Maximum hints displayed at once. Defaults to 50
|
[
"Displays",
"a",
"popup",
"list",
"of",
"hints",
"for",
"a",
"given",
"editor",
"context",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintList.js#L47-L124
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.