Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.html(template)
.insertBefore("#editor-holder");
if (animate) {
this._$root.addClass("popout offscreen");
// Forcing the renderer to do a layout, which will cause it to apply the transform for the "offscreen"
// class, so it will animate when you remove the class.
window.getComputedStyle(this._$root.get(0)).getPropertyValue("top");
this._$root.removeClass("popout offscreen");
}
// If something *other* than an editor (like another modal bar) has focus, set the focus
// to the editor here, before opening up the new modal bar. This ensures that the old
// focused item has time to react and close before the new modal bar is opened.
// See bugs #4287 and #3424
if (!EditorManager.getFocusedEditor()) {
EditorManager.focusEditor();
}
if (autoClose) {
this._autoClose = true;
this._$root.on("keydown", this._handleKeydown);
window.document.body.addEventListener("focusin", this._handleFocusChange, true);
// Set focus to the first input field, or the first button if there is no input field.
// TODO: remove this logic?
var $firstInput = $("input[type='text']", this._$root).first();
if ($firstInput.length > 0) {
$firstInput.focus();
} else {
$("button", this._$root).first().focus();
}
function _startNewSession(editor) {
if (!editor) {
editor = EditorManager.getFocusedEditor();
}
if (editor) {
lastChar = null;
if (_inSession(editor)) {
_endSession();
}
// Begin a new explicit session
_beginSession(editor);
}
}
function duplicateText(editor) {
editor = editor || EditorManager.getFocusedEditor();
if (!editor) {
return;
}
var selections = editor.getSelections(),
delimiter = "",
edits = [],
rangeSels = [],
cursorSels = [],
doc = editor.document;
// When there are multiple selections, we want to handle all the cursors first (duplicating
// their lines), then all the ranges (duplicating the ranges).
_.each(selections, function (sel) {
if (CodeMirror.cmpPos(sel.start, sel.end) === 0) {
cursorSels.push(sel);
function addCursorToSelection(editor, dir) {
editor = editor || EditorManager.getFocusedEditor();
if (editor) {
var origSels = editor.getSelections(),
newSels = [];
_.each(origSels, function (sel) {
var pos, colOffset;
if ((dir === -1 && sel.start.line > editor.getFirstVisibleLine()) || (dir === 1 && sel.end.line < editor.getLastVisibleLine())) {
// Add a new cursor on the next line up/down. It's okay if it overlaps another selection, because CM
// will take care of throwing it away in that case. It will also take care of clipping the char position
// to the end of the new line if the line is shorter.
pos = _.clone(dir === -1 ? sel.start : sel.end);
// get sel column of current selection
colOffset = editor.getColOffset(pos);
pos.line += dir;
function openLine(editor, direction) {
editor = editor || EditorManager.getFocusedEditor();
if (!editor) {
return;
}
var selections = editor.getSelections(),
isInlineWidget = !!EditorManager.getFocusedInlineWidget(),
lastLine = editor.getLastVisibleLine(),
doc = editor.document,
edits = [],
newSelections,
line;
// First, insert all the newlines (skipping multiple selections on the same line),
// then indent them all. (We can't easily do them all at once, because doMultipleEdits()
// won't do the indentation for us, but we want its help tracking any selection changes
// as the result of the edits.)
function handleUndoRedo(operation) {
var editor = EditorManager.getFocusedEditor();
var result = new $.Deferred();
if (editor) {
editor[operation]();
result.resolve();
} else {
result.reject();
}
return result.promise();
}
function moveLine(editor, direction) {
editor = editor || EditorManager.getFocusedEditor();
if (!editor) {
return;
}
var doc = editor.document,
lineSelections = editor.convertToLineSelections(editor.getSelections()),
isInlineWidget = !!EditorManager.getFocusedInlineWidget(),
firstLine = editor.getFirstVisibleLine(),
lastLine = editor.getLastVisibleLine(),
totalLines = editor.lineCount(),
lineLength = 0,
edits = [],
newSels = [],
pos = {};
_.each(lineSelections, function (lineSel) {
function getCurrentEditorSelectedText() {
var currentEditor = EditorManager.getFocusedEditor();
return (currentEditor && currentEditor.getSelectedText()) || "";
}
function splitSelIntoLines(editor) {
editor = editor || EditorManager.getFocusedEditor();
if (editor) {
editor._codeMirror.execCommand("splitSelectionByLine");
}
}
function unindentText() {
var editor = EditorManager.getFocusedEditor();
if (!editor) {
return;
}
editor._codeMirror.execCommand("indentLess");
}