Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-file-.../lib/codemirr.../lib
File: codemirror.js
// above or below them in the parent document.
[4500] Fix | Delete
function shiftDoc(doc, distance) {
[4501] Fix | Delete
if (distance == 0) return;
[4502] Fix | Delete
doc.first += distance;
[4503] Fix | Delete
doc.sel = new Selection(map(doc.sel.ranges, function(range) {
[4504] Fix | Delete
return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
[4505] Fix | Delete
Pos(range.head.line + distance, range.head.ch));
[4506] Fix | Delete
}), doc.sel.primIndex);
[4507] Fix | Delete
if (doc.cm) {
[4508] Fix | Delete
regChange(doc.cm, doc.first, doc.first - distance, distance);
[4509] Fix | Delete
for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
[4510] Fix | Delete
regLineChange(doc.cm, l, "gutter");
[4511] Fix | Delete
}
[4512] Fix | Delete
}
[4513] Fix | Delete
[4514] Fix | Delete
// More lower-level change function, handling only a single document
[4515] Fix | Delete
// (not linked ones).
[4516] Fix | Delete
function makeChangeSingleDoc(doc, change, selAfter, spans) {
[4517] Fix | Delete
if (doc.cm && !doc.cm.curOp)
[4518] Fix | Delete
return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
[4519] Fix | Delete
[4520] Fix | Delete
if (change.to.line < doc.first) {
[4521] Fix | Delete
shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
[4522] Fix | Delete
return;
[4523] Fix | Delete
}
[4524] Fix | Delete
if (change.from.line > doc.lastLine()) return;
[4525] Fix | Delete
[4526] Fix | Delete
// Clip the change to the size of this doc
[4527] Fix | Delete
if (change.from.line < doc.first) {
[4528] Fix | Delete
var shift = change.text.length - 1 - (doc.first - change.from.line);
[4529] Fix | Delete
shiftDoc(doc, shift);
[4530] Fix | Delete
change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
[4531] Fix | Delete
text: [lst(change.text)], origin: change.origin};
[4532] Fix | Delete
}
[4533] Fix | Delete
var last = doc.lastLine();
[4534] Fix | Delete
if (change.to.line > last) {
[4535] Fix | Delete
change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
[4536] Fix | Delete
text: [change.text[0]], origin: change.origin};
[4537] Fix | Delete
}
[4538] Fix | Delete
[4539] Fix | Delete
change.removed = getBetween(doc, change.from, change.to);
[4540] Fix | Delete
[4541] Fix | Delete
if (!selAfter) selAfter = computeSelAfterChange(doc, change);
[4542] Fix | Delete
if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
[4543] Fix | Delete
else updateDoc(doc, change, spans);
[4544] Fix | Delete
setSelectionNoUndo(doc, selAfter, sel_dontScroll);
[4545] Fix | Delete
}
[4546] Fix | Delete
[4547] Fix | Delete
// Handle the interaction of a change to a document with the editor
[4548] Fix | Delete
// that this document is part of.
[4549] Fix | Delete
function makeChangeSingleDocInEditor(cm, change, spans) {
[4550] Fix | Delete
var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
[4551] Fix | Delete
[4552] Fix | Delete
var recomputeMaxLength = false, checkWidthStart = from.line;
[4553] Fix | Delete
if (!cm.options.lineWrapping) {
[4554] Fix | Delete
checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
[4555] Fix | Delete
doc.iter(checkWidthStart, to.line + 1, function(line) {
[4556] Fix | Delete
if (line == display.maxLine) {
[4557] Fix | Delete
recomputeMaxLength = true;
[4558] Fix | Delete
return true;
[4559] Fix | Delete
}
[4560] Fix | Delete
});
[4561] Fix | Delete
}
[4562] Fix | Delete
[4563] Fix | Delete
if (doc.sel.contains(change.from, change.to) > -1)
[4564] Fix | Delete
signalCursorActivity(cm);
[4565] Fix | Delete
[4566] Fix | Delete
updateDoc(doc, change, spans, estimateHeight(cm));
[4567] Fix | Delete
[4568] Fix | Delete
if (!cm.options.lineWrapping) {
[4569] Fix | Delete
doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
[4570] Fix | Delete
var len = lineLength(line);
[4571] Fix | Delete
if (len > display.maxLineLength) {
[4572] Fix | Delete
display.maxLine = line;
[4573] Fix | Delete
display.maxLineLength = len;
[4574] Fix | Delete
display.maxLineChanged = true;
[4575] Fix | Delete
recomputeMaxLength = false;
[4576] Fix | Delete
}
[4577] Fix | Delete
});
[4578] Fix | Delete
if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
[4579] Fix | Delete
}
[4580] Fix | Delete
[4581] Fix | Delete
// Adjust frontier, schedule worker
[4582] Fix | Delete
doc.frontier = Math.min(doc.frontier, from.line);
[4583] Fix | Delete
startWorker(cm, 400);
[4584] Fix | Delete
[4585] Fix | Delete
var lendiff = change.text.length - (to.line - from.line) - 1;
[4586] Fix | Delete
// Remember that these lines changed, for updating the display
[4587] Fix | Delete
if (change.full)
[4588] Fix | Delete
regChange(cm);
[4589] Fix | Delete
else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
[4590] Fix | Delete
regLineChange(cm, from.line, "text");
[4591] Fix | Delete
else
[4592] Fix | Delete
regChange(cm, from.line, to.line + 1, lendiff);
[4593] Fix | Delete
[4594] Fix | Delete
var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
[4595] Fix | Delete
if (changeHandler || changesHandler) {
[4596] Fix | Delete
var obj = {
[4597] Fix | Delete
from: from, to: to,
[4598] Fix | Delete
text: change.text,
[4599] Fix | Delete
removed: change.removed,
[4600] Fix | Delete
origin: change.origin
[4601] Fix | Delete
};
[4602] Fix | Delete
if (changeHandler) signalLater(cm, "change", cm, obj);
[4603] Fix | Delete
if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
[4604] Fix | Delete
}
[4605] Fix | Delete
cm.display.selForContextMenu = null;
[4606] Fix | Delete
}
[4607] Fix | Delete
[4608] Fix | Delete
function replaceRange(doc, code, from, to, origin) {
[4609] Fix | Delete
if (!to) to = from;
[4610] Fix | Delete
if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
[4611] Fix | Delete
if (typeof code == "string") code = doc.splitLines(code);
[4612] Fix | Delete
makeChange(doc, {from: from, to: to, text: code, origin: origin});
[4613] Fix | Delete
}
[4614] Fix | Delete
[4615] Fix | Delete
// SCROLLING THINGS INTO VIEW
[4616] Fix | Delete
[4617] Fix | Delete
// If an editor sits on the top or bottom of the window, partially
[4618] Fix | Delete
// scrolled out of view, this ensures that the cursor is visible.
[4619] Fix | Delete
function maybeScrollWindow(cm, coords) {
[4620] Fix | Delete
if (signalDOMEvent(cm, "scrollCursorIntoView")) return;
[4621] Fix | Delete
[4622] Fix | Delete
var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
[4623] Fix | Delete
if (coords.top + box.top < 0) doScroll = true;
[4624] Fix | Delete
else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
[4625] Fix | Delete
if (doScroll != null && !phantom) {
[4626] Fix | Delete
var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " +
[4627] Fix | Delete
(coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " +
[4628] Fix | Delete
(coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px; left: " +
[4629] Fix | Delete
coords.left + "px; width: 2px;");
[4630] Fix | Delete
cm.display.lineSpace.appendChild(scrollNode);
[4631] Fix | Delete
scrollNode.scrollIntoView(doScroll);
[4632] Fix | Delete
cm.display.lineSpace.removeChild(scrollNode);
[4633] Fix | Delete
}
[4634] Fix | Delete
}
[4635] Fix | Delete
[4636] Fix | Delete
// Scroll a given position into view (immediately), verifying that
[4637] Fix | Delete
// it actually became visible (as line heights are accurately
[4638] Fix | Delete
// measured, the position of something may 'drift' during drawing).
[4639] Fix | Delete
function scrollPosIntoView(cm, pos, end, margin) {
[4640] Fix | Delete
if (margin == null) margin = 0;
[4641] Fix | Delete
for (var limit = 0; limit < 5; limit++) {
[4642] Fix | Delete
var changed = false, coords = cursorCoords(cm, pos);
[4643] Fix | Delete
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
[4644] Fix | Delete
var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
[4645] Fix | Delete
Math.min(coords.top, endCoords.top) - margin,
[4646] Fix | Delete
Math.max(coords.left, endCoords.left),
[4647] Fix | Delete
Math.max(coords.bottom, endCoords.bottom) + margin);
[4648] Fix | Delete
var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
[4649] Fix | Delete
if (scrollPos.scrollTop != null) {
[4650] Fix | Delete
setScrollTop(cm, scrollPos.scrollTop);
[4651] Fix | Delete
if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
[4652] Fix | Delete
}
[4653] Fix | Delete
if (scrollPos.scrollLeft != null) {
[4654] Fix | Delete
setScrollLeft(cm, scrollPos.scrollLeft);
[4655] Fix | Delete
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
[4656] Fix | Delete
}
[4657] Fix | Delete
if (!changed) break;
[4658] Fix | Delete
}
[4659] Fix | Delete
return coords;
[4660] Fix | Delete
}
[4661] Fix | Delete
[4662] Fix | Delete
// Scroll a given set of coordinates into view (immediately).
[4663] Fix | Delete
function scrollIntoView(cm, x1, y1, x2, y2) {
[4664] Fix | Delete
var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
[4665] Fix | Delete
if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
[4666] Fix | Delete
if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
[4667] Fix | Delete
}
[4668] Fix | Delete
[4669] Fix | Delete
// Calculate a new scroll position needed to scroll the given
[4670] Fix | Delete
// rectangle into view. Returns an object with scrollTop and
[4671] Fix | Delete
// scrollLeft properties. When these are undefined, the
[4672] Fix | Delete
// vertical/horizontal position does not need to be adjusted.
[4673] Fix | Delete
function calculateScrollPos(cm, x1, y1, x2, y2) {
[4674] Fix | Delete
var display = cm.display, snapMargin = textHeight(cm.display);
[4675] Fix | Delete
if (y1 < 0) y1 = 0;
[4676] Fix | Delete
var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
[4677] Fix | Delete
var screen = displayHeight(cm), result = {};
[4678] Fix | Delete
if (y2 - y1 > screen) y2 = y1 + screen;
[4679] Fix | Delete
var docBottom = cm.doc.height + paddingVert(display);
[4680] Fix | Delete
var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
[4681] Fix | Delete
if (y1 < screentop) {
[4682] Fix | Delete
result.scrollTop = atTop ? 0 : y1;
[4683] Fix | Delete
} else if (y2 > screentop + screen) {
[4684] Fix | Delete
var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
[4685] Fix | Delete
if (newTop != screentop) result.scrollTop = newTop;
[4686] Fix | Delete
}
[4687] Fix | Delete
[4688] Fix | Delete
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
[4689] Fix | Delete
var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
[4690] Fix | Delete
var tooWide = x2 - x1 > screenw;
[4691] Fix | Delete
if (tooWide) x2 = x1 + screenw;
[4692] Fix | Delete
if (x1 < 10)
[4693] Fix | Delete
result.scrollLeft = 0;
[4694] Fix | Delete
else if (x1 < screenleft)
[4695] Fix | Delete
result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
[4696] Fix | Delete
else if (x2 > screenw + screenleft - 3)
[4697] Fix | Delete
result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
[4698] Fix | Delete
return result;
[4699] Fix | Delete
}
[4700] Fix | Delete
[4701] Fix | Delete
// Store a relative adjustment to the scroll position in the current
[4702] Fix | Delete
// operation (to be applied when the operation finishes).
[4703] Fix | Delete
function addToScrollPos(cm, left, top) {
[4704] Fix | Delete
if (left != null || top != null) resolveScrollToPos(cm);
[4705] Fix | Delete
if (left != null)
[4706] Fix | Delete
cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left;
[4707] Fix | Delete
if (top != null)
[4708] Fix | Delete
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
[4709] Fix | Delete
}
[4710] Fix | Delete
[4711] Fix | Delete
// Make sure that at the end of the operation the current cursor is
[4712] Fix | Delete
// shown.
[4713] Fix | Delete
function ensureCursorVisible(cm) {
[4714] Fix | Delete
resolveScrollToPos(cm);
[4715] Fix | Delete
var cur = cm.getCursor(), from = cur, to = cur;
[4716] Fix | Delete
if (!cm.options.lineWrapping) {
[4717] Fix | Delete
from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
[4718] Fix | Delete
to = Pos(cur.line, cur.ch + 1);
[4719] Fix | Delete
}
[4720] Fix | Delete
cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true};
[4721] Fix | Delete
}
[4722] Fix | Delete
[4723] Fix | Delete
// When an operation has its scrollToPos property set, and another
[4724] Fix | Delete
// scroll action is applied before the end of the operation, this
[4725] Fix | Delete
// 'simulates' scrolling that position into view in a cheap way, so
[4726] Fix | Delete
// that the effect of intermediate scroll commands is not ignored.
[4727] Fix | Delete
function resolveScrollToPos(cm) {
[4728] Fix | Delete
var range = cm.curOp.scrollToPos;
[4729] Fix | Delete
if (range) {
[4730] Fix | Delete
cm.curOp.scrollToPos = null;
[4731] Fix | Delete
var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
[4732] Fix | Delete
var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
[4733] Fix | Delete
Math.min(from.top, to.top) - range.margin,
[4734] Fix | Delete
Math.max(from.right, to.right),
[4735] Fix | Delete
Math.max(from.bottom, to.bottom) + range.margin);
[4736] Fix | Delete
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
[4737] Fix | Delete
}
[4738] Fix | Delete
}
[4739] Fix | Delete
[4740] Fix | Delete
// API UTILITIES
[4741] Fix | Delete
[4742] Fix | Delete
// Indent the given line. The how parameter can be "smart",
[4743] Fix | Delete
// "add"/null, "subtract", or "prev". When aggressive is false
[4744] Fix | Delete
// (typically set to true for forced single-line indents), empty
[4745] Fix | Delete
// lines are not indented, and places where the mode returns Pass
[4746] Fix | Delete
// are left alone.
[4747] Fix | Delete
function indentLine(cm, n, how, aggressive) {
[4748] Fix | Delete
var doc = cm.doc, state;
[4749] Fix | Delete
if (how == null) how = "add";
[4750] Fix | Delete
if (how == "smart") {
[4751] Fix | Delete
// Fall back to "prev" when the mode doesn't have an indentation
[4752] Fix | Delete
// method.
[4753] Fix | Delete
if (!doc.mode.indent) how = "prev";
[4754] Fix | Delete
else state = getStateBefore(cm, n);
[4755] Fix | Delete
}
[4756] Fix | Delete
[4757] Fix | Delete
var tabSize = cm.options.tabSize;
[4758] Fix | Delete
var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
[4759] Fix | Delete
if (line.stateAfter) line.stateAfter = null;
[4760] Fix | Delete
var curSpaceString = line.text.match(/^\s*/)[0], indentation;
[4761] Fix | Delete
if (!aggressive && !/\S/.test(line.text)) {
[4762] Fix | Delete
indentation = 0;
[4763] Fix | Delete
how = "not";
[4764] Fix | Delete
} else if (how == "smart") {
[4765] Fix | Delete
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
[4766] Fix | Delete
if (indentation == Pass || indentation > 150) {
[4767] Fix | Delete
if (!aggressive) return;
[4768] Fix | Delete
how = "prev";
[4769] Fix | Delete
}
[4770] Fix | Delete
}
[4771] Fix | Delete
if (how == "prev") {
[4772] Fix | Delete
if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
[4773] Fix | Delete
else indentation = 0;
[4774] Fix | Delete
} else if (how == "add") {
[4775] Fix | Delete
indentation = curSpace + cm.options.indentUnit;
[4776] Fix | Delete
} else if (how == "subtract") {
[4777] Fix | Delete
indentation = curSpace - cm.options.indentUnit;
[4778] Fix | Delete
} else if (typeof how == "number") {
[4779] Fix | Delete
indentation = curSpace + how;
[4780] Fix | Delete
}
[4781] Fix | Delete
indentation = Math.max(0, indentation);
[4782] Fix | Delete
[4783] Fix | Delete
var indentString = "", pos = 0;
[4784] Fix | Delete
if (cm.options.indentWithTabs)
[4785] Fix | Delete
for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
[4786] Fix | Delete
if (pos < indentation) indentString += spaceStr(indentation - pos);
[4787] Fix | Delete
[4788] Fix | Delete
if (indentString != curSpaceString) {
[4789] Fix | Delete
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
[4790] Fix | Delete
line.stateAfter = null;
[4791] Fix | Delete
return true;
[4792] Fix | Delete
} else {
[4793] Fix | Delete
// Ensure that, if the cursor was in the whitespace at the start
[4794] Fix | Delete
// of the line, it is moved to the end of that space.
[4795] Fix | Delete
for (var i = 0; i < doc.sel.ranges.length; i++) {
[4796] Fix | Delete
var range = doc.sel.ranges[i];
[4797] Fix | Delete
if (range.head.line == n && range.head.ch < curSpaceString.length) {
[4798] Fix | Delete
var pos = Pos(n, curSpaceString.length);
[4799] Fix | Delete
replaceOneSelection(doc, i, new Range(pos, pos));
[4800] Fix | Delete
break;
[4801] Fix | Delete
}
[4802] Fix | Delete
}
[4803] Fix | Delete
}
[4804] Fix | Delete
}
[4805] Fix | Delete
[4806] Fix | Delete
// Utility for applying a change to a line by handle or number,
[4807] Fix | Delete
// returning the number and optionally registering the line as
[4808] Fix | Delete
// changed.
[4809] Fix | Delete
function changeLine(doc, handle, changeType, op) {
[4810] Fix | Delete
var no = handle, line = handle;
[4811] Fix | Delete
if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
[4812] Fix | Delete
else no = lineNo(handle);
[4813] Fix | Delete
if (no == null) return null;
[4814] Fix | Delete
if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType);
[4815] Fix | Delete
return line;
[4816] Fix | Delete
}
[4817] Fix | Delete
[4818] Fix | Delete
// Helper for deleting text near the selection(s), used to implement
[4819] Fix | Delete
// backspace, delete, and similar functionality.
[4820] Fix | Delete
function deleteNearSelection(cm, compute) {
[4821] Fix | Delete
var ranges = cm.doc.sel.ranges, kill = [];
[4822] Fix | Delete
// Build up a set of ranges to kill first, merging overlapping
[4823] Fix | Delete
// ranges.
[4824] Fix | Delete
for (var i = 0; i < ranges.length; i++) {
[4825] Fix | Delete
var toKill = compute(ranges[i]);
[4826] Fix | Delete
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
[4827] Fix | Delete
var replaced = kill.pop();
[4828] Fix | Delete
if (cmp(replaced.from, toKill.from) < 0) {
[4829] Fix | Delete
toKill.from = replaced.from;
[4830] Fix | Delete
break;
[4831] Fix | Delete
}
[4832] Fix | Delete
}
[4833] Fix | Delete
kill.push(toKill);
[4834] Fix | Delete
}
[4835] Fix | Delete
// Next, remove those actual ranges.
[4836] Fix | Delete
runInOp(cm, function() {
[4837] Fix | Delete
for (var i = kill.length - 1; i >= 0; i--)
[4838] Fix | Delete
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
[4839] Fix | Delete
ensureCursorVisible(cm);
[4840] Fix | Delete
});
[4841] Fix | Delete
}
[4842] Fix | Delete
[4843] Fix | Delete
// Used for horizontal relative motion. Dir is -1 or 1 (left or
[4844] Fix | Delete
// right), unit can be "char", "column" (like char, but doesn't
[4845] Fix | Delete
// cross line boundaries), "word" (across next word), or "group" (to
[4846] Fix | Delete
// the start of next group of word or non-word-non-whitespace
[4847] Fix | Delete
// chars). The visually param controls whether, in right-to-left
[4848] Fix | Delete
// text, direction 1 means to move towards the next index in the
[4849] Fix | Delete
// string, or towards the character to the right of the current
[4850] Fix | Delete
// position. The resulting position will have a hitSide=true
[4851] Fix | Delete
// property if it reached the end of the document.
[4852] Fix | Delete
function findPosH(doc, pos, dir, unit, visually) {
[4853] Fix | Delete
var line = pos.line, ch = pos.ch, origDir = dir;
[4854] Fix | Delete
var lineObj = getLine(doc, line);
[4855] Fix | Delete
function findNextLine() {
[4856] Fix | Delete
var l = line + dir;
[4857] Fix | Delete
if (l < doc.first || l >= doc.first + doc.size) return false
[4858] Fix | Delete
line = l;
[4859] Fix | Delete
return lineObj = getLine(doc, l);
[4860] Fix | Delete
}
[4861] Fix | Delete
function moveOnce(boundToLine) {
[4862] Fix | Delete
var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
[4863] Fix | Delete
if (next == null) {
[4864] Fix | Delete
if (!boundToLine && findNextLine()) {
[4865] Fix | Delete
if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
[4866] Fix | Delete
else ch = dir < 0 ? lineObj.text.length : 0;
[4867] Fix | Delete
} else return false
[4868] Fix | Delete
} else ch = next;
[4869] Fix | Delete
return true;
[4870] Fix | Delete
}
[4871] Fix | Delete
[4872] Fix | Delete
if (unit == "char") {
[4873] Fix | Delete
moveOnce()
[4874] Fix | Delete
} else if (unit == "column") {
[4875] Fix | Delete
moveOnce(true)
[4876] Fix | Delete
} else if (unit == "word" || unit == "group") {
[4877] Fix | Delete
var sawType = null, group = unit == "group";
[4878] Fix | Delete
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
[4879] Fix | Delete
for (var first = true;; first = false) {
[4880] Fix | Delete
if (dir < 0 && !moveOnce(!first)) break;
[4881] Fix | Delete
var cur = lineObj.text.charAt(ch) || "\n";
[4882] Fix | Delete
var type = isWordChar(cur, helper) ? "w"
[4883] Fix | Delete
: group && cur == "\n" ? "n"
[4884] Fix | Delete
: !group || /\s/.test(cur) ? null
[4885] Fix | Delete
: "p";
[4886] Fix | Delete
if (group && !first && !type) type = "s";
[4887] Fix | Delete
if (sawType && sawType != type) {
[4888] Fix | Delete
if (dir < 0) {dir = 1; moveOnce();}
[4889] Fix | Delete
break;
[4890] Fix | Delete
}
[4891] Fix | Delete
[4892] Fix | Delete
if (type) sawType = type;
[4893] Fix | Delete
if (dir > 0 && !moveOnce(!first)) break;
[4894] Fix | Delete
}
[4895] Fix | Delete
}
[4896] Fix | Delete
var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true);
[4897] Fix | Delete
if (!cmp(pos, result)) result.hitSide = true;
[4898] Fix | Delete
return result;
[4899] Fix | Delete
}
[4900] Fix | Delete
[4901] Fix | Delete
// For relative vertical movement. Dir may be -1 or 1. Unit can be
[4902] Fix | Delete
// "page" or "line". The resulting position will have a hitSide=true
[4903] Fix | Delete
// property if it reached the end of the document.
[4904] Fix | Delete
function findPosV(cm, pos, dir, unit) {
[4905] Fix | Delete
var doc = cm.doc, x = pos.left, y;
[4906] Fix | Delete
if (unit == "page") {
[4907] Fix | Delete
var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
[4908] Fix | Delete
y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
[4909] Fix | Delete
} else if (unit == "line") {
[4910] Fix | Delete
y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
[4911] Fix | Delete
}
[4912] Fix | Delete
for (;;) {
[4913] Fix | Delete
var target = coordsChar(cm, x, y);
[4914] Fix | Delete
if (!target.outside) break;
[4915] Fix | Delete
if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
[4916] Fix | Delete
y += dir * 5;
[4917] Fix | Delete
}
[4918] Fix | Delete
return target;
[4919] Fix | Delete
}
[4920] Fix | Delete
[4921] Fix | Delete
// EDITOR METHODS
[4922] Fix | Delete
[4923] Fix | Delete
// The publicly visible API. Note that methodOp(f) means
[4924] Fix | Delete
// 'wrap f in an operation, performed on its `this` parameter'.
[4925] Fix | Delete
[4926] Fix | Delete
// This is not the complete set of editor methods. Most of the
[4927] Fix | Delete
// methods defined on the Doc type are also injected into
[4928] Fix | Delete
// CodeMirror.prototype, for backwards compatibility and
[4929] Fix | Delete
// convenience.
[4930] Fix | Delete
[4931] Fix | Delete
CodeMirror.prototype = {
[4932] Fix | Delete
constructor: CodeMirror,
[4933] Fix | Delete
focus: function(){window.focus(); this.display.input.focus();},
[4934] Fix | Delete
[4935] Fix | Delete
setOption: function(option, value) {
[4936] Fix | Delete
var options = this.options, old = options[option];
[4937] Fix | Delete
if (options[option] == value && option != "mode") return;
[4938] Fix | Delete
options[option] = value;
[4939] Fix | Delete
if (optionHandlers.hasOwnProperty(option))
[4940] Fix | Delete
operation(this, optionHandlers[option])(this, value, old);
[4941] Fix | Delete
},
[4942] Fix | Delete
[4943] Fix | Delete
getOption: function(option) {return this.options[option];},
[4944] Fix | Delete
getDoc: function() {return this.doc;},
[4945] Fix | Delete
[4946] Fix | Delete
addKeyMap: function(map, bottom) {
[4947] Fix | Delete
this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
[4948] Fix | Delete
},
[4949] Fix | Delete
removeKeyMap: function(map) {
[4950] Fix | Delete
var maps = this.state.keyMaps;
[4951] Fix | Delete
for (var i = 0; i < maps.length; ++i)
[4952] Fix | Delete
if (maps[i] == map || maps[i].name == map) {
[4953] Fix | Delete
maps.splice(i, 1);
[4954] Fix | Delete
return true;
[4955] Fix | Delete
}
[4956] Fix | Delete
},
[4957] Fix | Delete
[4958] Fix | Delete
addOverlay: methodOp(function(spec, options) {
[4959] Fix | Delete
var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
[4960] Fix | Delete
if (mode.startState) throw new Error("Overlays may not be stateful.");
[4961] Fix | Delete
insertSorted(this.state.overlays,
[4962] Fix | Delete
{mode: mode, modeSpec: spec, opaque: options && options.opaque,
[4963] Fix | Delete
priority: (options && options.priority) || 0},
[4964] Fix | Delete
function(overlay) { return overlay.priority })
[4965] Fix | Delete
this.state.modeGen++;
[4966] Fix | Delete
regChange(this);
[4967] Fix | Delete
}),
[4968] Fix | Delete
removeOverlay: methodOp(function(spec) {
[4969] Fix | Delete
var overlays = this.state.overlays;
[4970] Fix | Delete
for (var i = 0; i < overlays.length; ++i) {
[4971] Fix | Delete
var cur = overlays[i].modeSpec;
[4972] Fix | Delete
if (cur == spec || typeof spec == "string" && cur.name == spec) {
[4973] Fix | Delete
overlays.splice(i, 1);
[4974] Fix | Delete
this.state.modeGen++;
[4975] Fix | Delete
regChange(this);
[4976] Fix | Delete
return;
[4977] Fix | Delete
}
[4978] Fix | Delete
}
[4979] Fix | Delete
}),
[4980] Fix | Delete
[4981] Fix | Delete
indentLine: methodOp(function(n, dir, aggressive) {
[4982] Fix | Delete
if (typeof dir != "string" && typeof dir != "number") {
[4983] Fix | Delete
if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
[4984] Fix | Delete
else dir = dir ? "add" : "subtract";
[4985] Fix | Delete
}
[4986] Fix | Delete
if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
[4987] Fix | Delete
}),
[4988] Fix | Delete
indentSelection: methodOp(function(how) {
[4989] Fix | Delete
var ranges = this.doc.sel.ranges, end = -1;
[4990] Fix | Delete
for (var i = 0; i < ranges.length; i++) {
[4991] Fix | Delete
var range = ranges[i];
[4992] Fix | Delete
if (!range.empty()) {
[4993] Fix | Delete
var from = range.from(), to = range.to();
[4994] Fix | Delete
var start = Math.max(end, from.line);
[4995] Fix | Delete
end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
[4996] Fix | Delete
for (var j = start; j < end; ++j)
[4997] Fix | Delete
indentLine(this, j, how);
[4998] Fix | Delete
var newRanges = this.doc.sel.ranges;
[4999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function