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
var minindent, minline, doc = cm.doc;
[2500] Fix | Delete
var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
[2501] Fix | Delete
for (var search = n; search > lim; --search) {
[2502] Fix | Delete
if (search <= doc.first) return doc.first;
[2503] Fix | Delete
var line = getLine(doc, search - 1);
[2504] Fix | Delete
if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
[2505] Fix | Delete
var indented = countColumn(line.text, null, cm.options.tabSize);
[2506] Fix | Delete
if (minline == null || minindent > indented) {
[2507] Fix | Delete
minline = search - 1;
[2508] Fix | Delete
minindent = indented;
[2509] Fix | Delete
}
[2510] Fix | Delete
}
[2511] Fix | Delete
return minline;
[2512] Fix | Delete
}
[2513] Fix | Delete
[2514] Fix | Delete
function getStateBefore(cm, n, precise) {
[2515] Fix | Delete
var doc = cm.doc, display = cm.display;
[2516] Fix | Delete
if (!doc.mode.startState) return true;
[2517] Fix | Delete
var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
[2518] Fix | Delete
if (!state) state = startState(doc.mode);
[2519] Fix | Delete
else state = copyState(doc.mode, state);
[2520] Fix | Delete
doc.iter(pos, n, function(line) {
[2521] Fix | Delete
processLine(cm, line.text, state);
[2522] Fix | Delete
var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
[2523] Fix | Delete
line.stateAfter = save ? copyState(doc.mode, state) : null;
[2524] Fix | Delete
++pos;
[2525] Fix | Delete
});
[2526] Fix | Delete
if (precise) doc.frontier = pos;
[2527] Fix | Delete
return state;
[2528] Fix | Delete
}
[2529] Fix | Delete
[2530] Fix | Delete
// POSITION MEASUREMENT
[2531] Fix | Delete
[2532] Fix | Delete
function paddingTop(display) {return display.lineSpace.offsetTop;}
[2533] Fix | Delete
function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
[2534] Fix | Delete
function paddingH(display) {
[2535] Fix | Delete
if (display.cachedPaddingH) return display.cachedPaddingH;
[2536] Fix | Delete
var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
[2537] Fix | Delete
var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
[2538] Fix | Delete
var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
[2539] Fix | Delete
if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
[2540] Fix | Delete
return data;
[2541] Fix | Delete
}
[2542] Fix | Delete
[2543] Fix | Delete
function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; }
[2544] Fix | Delete
function displayWidth(cm) {
[2545] Fix | Delete
return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
[2546] Fix | Delete
}
[2547] Fix | Delete
function displayHeight(cm) {
[2548] Fix | Delete
return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
[2549] Fix | Delete
}
[2550] Fix | Delete
[2551] Fix | Delete
// Ensure the lineView.wrapping.heights array is populated. This is
[2552] Fix | Delete
// an array of bottom offsets for the lines that make up a drawn
[2553] Fix | Delete
// line. When lineWrapping is on, there might be more than one
[2554] Fix | Delete
// height.
[2555] Fix | Delete
function ensureLineHeights(cm, lineView, rect) {
[2556] Fix | Delete
var wrapping = cm.options.lineWrapping;
[2557] Fix | Delete
var curWidth = wrapping && displayWidth(cm);
[2558] Fix | Delete
if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
[2559] Fix | Delete
var heights = lineView.measure.heights = [];
[2560] Fix | Delete
if (wrapping) {
[2561] Fix | Delete
lineView.measure.width = curWidth;
[2562] Fix | Delete
var rects = lineView.text.firstChild.getClientRects();
[2563] Fix | Delete
for (var i = 0; i < rects.length - 1; i++) {
[2564] Fix | Delete
var cur = rects[i], next = rects[i + 1];
[2565] Fix | Delete
if (Math.abs(cur.bottom - next.bottom) > 2)
[2566] Fix | Delete
heights.push((cur.bottom + next.top) / 2 - rect.top);
[2567] Fix | Delete
}
[2568] Fix | Delete
}
[2569] Fix | Delete
heights.push(rect.bottom - rect.top);
[2570] Fix | Delete
}
[2571] Fix | Delete
}
[2572] Fix | Delete
[2573] Fix | Delete
// Find a line map (mapping character offsets to text nodes) and a
[2574] Fix | Delete
// measurement cache for the given line number. (A line view might
[2575] Fix | Delete
// contain multiple lines when collapsed ranges are present.)
[2576] Fix | Delete
function mapFromLineView(lineView, line, lineN) {
[2577] Fix | Delete
if (lineView.line == line)
[2578] Fix | Delete
return {map: lineView.measure.map, cache: lineView.measure.cache};
[2579] Fix | Delete
for (var i = 0; i < lineView.rest.length; i++)
[2580] Fix | Delete
if (lineView.rest[i] == line)
[2581] Fix | Delete
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
[2582] Fix | Delete
for (var i = 0; i < lineView.rest.length; i++)
[2583] Fix | Delete
if (lineNo(lineView.rest[i]) > lineN)
[2584] Fix | Delete
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
[2585] Fix | Delete
}
[2586] Fix | Delete
[2587] Fix | Delete
// Render a line into the hidden node display.externalMeasured. Used
[2588] Fix | Delete
// when measurement is needed for a line that's not in the viewport.
[2589] Fix | Delete
function updateExternalMeasurement(cm, line) {
[2590] Fix | Delete
line = visualLine(line);
[2591] Fix | Delete
var lineN = lineNo(line);
[2592] Fix | Delete
var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
[2593] Fix | Delete
view.lineN = lineN;
[2594] Fix | Delete
var built = view.built = buildLineContent(cm, view);
[2595] Fix | Delete
view.text = built.pre;
[2596] Fix | Delete
removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
[2597] Fix | Delete
return view;
[2598] Fix | Delete
}
[2599] Fix | Delete
[2600] Fix | Delete
// Get a {top, bottom, left, right} box (in line-local coordinates)
[2601] Fix | Delete
// for a given character.
[2602] Fix | Delete
function measureChar(cm, line, ch, bias) {
[2603] Fix | Delete
return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
[2604] Fix | Delete
}
[2605] Fix | Delete
[2606] Fix | Delete
// Find a line view that corresponds to the given line number.
[2607] Fix | Delete
function findViewForLine(cm, lineN) {
[2608] Fix | Delete
if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
[2609] Fix | Delete
return cm.display.view[findViewIndex(cm, lineN)];
[2610] Fix | Delete
var ext = cm.display.externalMeasured;
[2611] Fix | Delete
if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
[2612] Fix | Delete
return ext;
[2613] Fix | Delete
}
[2614] Fix | Delete
[2615] Fix | Delete
// Measurement can be split in two steps, the set-up work that
[2616] Fix | Delete
// applies to the whole line, and the measurement of the actual
[2617] Fix | Delete
// character. Functions like coordsChar, that need to do a lot of
[2618] Fix | Delete
// measurements in a row, can thus ensure that the set-up work is
[2619] Fix | Delete
// only done once.
[2620] Fix | Delete
function prepareMeasureForLine(cm, line) {
[2621] Fix | Delete
var lineN = lineNo(line);
[2622] Fix | Delete
var view = findViewForLine(cm, lineN);
[2623] Fix | Delete
if (view && !view.text) {
[2624] Fix | Delete
view = null;
[2625] Fix | Delete
} else if (view && view.changes) {
[2626] Fix | Delete
updateLineForChanges(cm, view, lineN, getDimensions(cm));
[2627] Fix | Delete
cm.curOp.forceUpdate = true;
[2628] Fix | Delete
}
[2629] Fix | Delete
if (!view)
[2630] Fix | Delete
view = updateExternalMeasurement(cm, line);
[2631] Fix | Delete
[2632] Fix | Delete
var info = mapFromLineView(view, line, lineN);
[2633] Fix | Delete
return {
[2634] Fix | Delete
line: line, view: view, rect: null,
[2635] Fix | Delete
map: info.map, cache: info.cache, before: info.before,
[2636] Fix | Delete
hasHeights: false
[2637] Fix | Delete
};
[2638] Fix | Delete
}
[2639] Fix | Delete
[2640] Fix | Delete
// Given a prepared measurement object, measures the position of an
[2641] Fix | Delete
// actual character (or fetches it from the cache).
[2642] Fix | Delete
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
[2643] Fix | Delete
if (prepared.before) ch = -1;
[2644] Fix | Delete
var key = ch + (bias || ""), found;
[2645] Fix | Delete
if (prepared.cache.hasOwnProperty(key)) {
[2646] Fix | Delete
found = prepared.cache[key];
[2647] Fix | Delete
} else {
[2648] Fix | Delete
if (!prepared.rect)
[2649] Fix | Delete
prepared.rect = prepared.view.text.getBoundingClientRect();
[2650] Fix | Delete
if (!prepared.hasHeights) {
[2651] Fix | Delete
ensureLineHeights(cm, prepared.view, prepared.rect);
[2652] Fix | Delete
prepared.hasHeights = true;
[2653] Fix | Delete
}
[2654] Fix | Delete
found = measureCharInner(cm, prepared, ch, bias);
[2655] Fix | Delete
if (!found.bogus) prepared.cache[key] = found;
[2656] Fix | Delete
}
[2657] Fix | Delete
return {left: found.left, right: found.right,
[2658] Fix | Delete
top: varHeight ? found.rtop : found.top,
[2659] Fix | Delete
bottom: varHeight ? found.rbottom : found.bottom};
[2660] Fix | Delete
}
[2661] Fix | Delete
[2662] Fix | Delete
var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
[2663] Fix | Delete
[2664] Fix | Delete
function nodeAndOffsetInLineMap(map, ch, bias) {
[2665] Fix | Delete
var node, start, end, collapse;
[2666] Fix | Delete
// First, search the line map for the text node corresponding to,
[2667] Fix | Delete
// or closest to, the target character.
[2668] Fix | Delete
for (var i = 0; i < map.length; i += 3) {
[2669] Fix | Delete
var mStart = map[i], mEnd = map[i + 1];
[2670] Fix | Delete
if (ch < mStart) {
[2671] Fix | Delete
start = 0; end = 1;
[2672] Fix | Delete
collapse = "left";
[2673] Fix | Delete
} else if (ch < mEnd) {
[2674] Fix | Delete
start = ch - mStart;
[2675] Fix | Delete
end = start + 1;
[2676] Fix | Delete
} else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
[2677] Fix | Delete
end = mEnd - mStart;
[2678] Fix | Delete
start = end - 1;
[2679] Fix | Delete
if (ch >= mEnd) collapse = "right";
[2680] Fix | Delete
}
[2681] Fix | Delete
if (start != null) {
[2682] Fix | Delete
node = map[i + 2];
[2683] Fix | Delete
if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
[2684] Fix | Delete
collapse = bias;
[2685] Fix | Delete
if (bias == "left" && start == 0)
[2686] Fix | Delete
while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
[2687] Fix | Delete
node = map[(i -= 3) + 2];
[2688] Fix | Delete
collapse = "left";
[2689] Fix | Delete
}
[2690] Fix | Delete
if (bias == "right" && start == mEnd - mStart)
[2691] Fix | Delete
while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
[2692] Fix | Delete
node = map[(i += 3) + 2];
[2693] Fix | Delete
collapse = "right";
[2694] Fix | Delete
}
[2695] Fix | Delete
break;
[2696] Fix | Delete
}
[2697] Fix | Delete
}
[2698] Fix | Delete
return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd};
[2699] Fix | Delete
}
[2700] Fix | Delete
[2701] Fix | Delete
function getUsefulRect(rects, bias) {
[2702] Fix | Delete
var rect = nullRect
[2703] Fix | Delete
if (bias == "left") for (var i = 0; i < rects.length; i++) {
[2704] Fix | Delete
if ((rect = rects[i]).left != rect.right) break
[2705] Fix | Delete
} else for (var i = rects.length - 1; i >= 0; i--) {
[2706] Fix | Delete
if ((rect = rects[i]).left != rect.right) break
[2707] Fix | Delete
}
[2708] Fix | Delete
return rect
[2709] Fix | Delete
}
[2710] Fix | Delete
[2711] Fix | Delete
function measureCharInner(cm, prepared, ch, bias) {
[2712] Fix | Delete
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
[2713] Fix | Delete
var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
[2714] Fix | Delete
[2715] Fix | Delete
var rect;
[2716] Fix | Delete
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
[2717] Fix | Delete
for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned
[2718] Fix | Delete
while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) --start;
[2719] Fix | Delete
while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) ++end;
[2720] Fix | Delete
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
[2721] Fix | Delete
rect = node.parentNode.getBoundingClientRect();
[2722] Fix | Delete
else
[2723] Fix | Delete
rect = getUsefulRect(range(node, start, end).getClientRects(), bias)
[2724] Fix | Delete
if (rect.left || rect.right || start == 0) break;
[2725] Fix | Delete
end = start;
[2726] Fix | Delete
start = start - 1;
[2727] Fix | Delete
collapse = "right";
[2728] Fix | Delete
}
[2729] Fix | Delete
if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
[2730] Fix | Delete
} else { // If it is a widget, simply get the box for the whole widget.
[2731] Fix | Delete
if (start > 0) collapse = bias = "right";
[2732] Fix | Delete
var rects;
[2733] Fix | Delete
if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
[2734] Fix | Delete
rect = rects[bias == "right" ? rects.length - 1 : 0];
[2735] Fix | Delete
else
[2736] Fix | Delete
rect = node.getBoundingClientRect();
[2737] Fix | Delete
}
[2738] Fix | Delete
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
[2739] Fix | Delete
var rSpan = node.parentNode.getClientRects()[0];
[2740] Fix | Delete
if (rSpan)
[2741] Fix | Delete
rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom};
[2742] Fix | Delete
else
[2743] Fix | Delete
rect = nullRect;
[2744] Fix | Delete
}
[2745] Fix | Delete
[2746] Fix | Delete
var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
[2747] Fix | Delete
var mid = (rtop + rbot) / 2;
[2748] Fix | Delete
var heights = prepared.view.measure.heights;
[2749] Fix | Delete
for (var i = 0; i < heights.length - 1; i++)
[2750] Fix | Delete
if (mid < heights[i]) break;
[2751] Fix | Delete
var top = i ? heights[i - 1] : 0, bot = heights[i];
[2752] Fix | Delete
var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
[2753] Fix | Delete
right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
[2754] Fix | Delete
top: top, bottom: bot};
[2755] Fix | Delete
if (!rect.left && !rect.right) result.bogus = true;
[2756] Fix | Delete
if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
[2757] Fix | Delete
[2758] Fix | Delete
return result;
[2759] Fix | Delete
}
[2760] Fix | Delete
[2761] Fix | Delete
// Work around problem with bounding client rects on ranges being
[2762] Fix | Delete
// returned incorrectly when zoomed on IE10 and below.
[2763] Fix | Delete
function maybeUpdateRectForZooming(measure, rect) {
[2764] Fix | Delete
if (!window.screen || screen.logicalXDPI == null ||
[2765] Fix | Delete
screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
[2766] Fix | Delete
return rect;
[2767] Fix | Delete
var scaleX = screen.logicalXDPI / screen.deviceXDPI;
[2768] Fix | Delete
var scaleY = screen.logicalYDPI / screen.deviceYDPI;
[2769] Fix | Delete
return {left: rect.left * scaleX, right: rect.right * scaleX,
[2770] Fix | Delete
top: rect.top * scaleY, bottom: rect.bottom * scaleY};
[2771] Fix | Delete
}
[2772] Fix | Delete
[2773] Fix | Delete
function clearLineMeasurementCacheFor(lineView) {
[2774] Fix | Delete
if (lineView.measure) {
[2775] Fix | Delete
lineView.measure.cache = {};
[2776] Fix | Delete
lineView.measure.heights = null;
[2777] Fix | Delete
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
[2778] Fix | Delete
lineView.measure.caches[i] = {};
[2779] Fix | Delete
}
[2780] Fix | Delete
}
[2781] Fix | Delete
[2782] Fix | Delete
function clearLineMeasurementCache(cm) {
[2783] Fix | Delete
cm.display.externalMeasure = null;
[2784] Fix | Delete
removeChildren(cm.display.lineMeasure);
[2785] Fix | Delete
for (var i = 0; i < cm.display.view.length; i++)
[2786] Fix | Delete
clearLineMeasurementCacheFor(cm.display.view[i]);
[2787] Fix | Delete
}
[2788] Fix | Delete
[2789] Fix | Delete
function clearCaches(cm) {
[2790] Fix | Delete
clearLineMeasurementCache(cm);
[2791] Fix | Delete
cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
[2792] Fix | Delete
if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
[2793] Fix | Delete
cm.display.lineNumChars = null;
[2794] Fix | Delete
}
[2795] Fix | Delete
[2796] Fix | Delete
function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
[2797] Fix | Delete
function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
[2798] Fix | Delete
[2799] Fix | Delete
// Converts a {top, bottom, left, right} box from line-local
[2800] Fix | Delete
// coordinates into another coordinate system. Context may be one of
[2801] Fix | Delete
// "line", "div" (display.lineDiv), "local"/null (editor), "window",
[2802] Fix | Delete
// or "page".
[2803] Fix | Delete
function intoCoordSystem(cm, lineObj, rect, context) {
[2804] Fix | Delete
if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
[2805] Fix | Delete
var size = widgetHeight(lineObj.widgets[i]);
[2806] Fix | Delete
rect.top += size; rect.bottom += size;
[2807] Fix | Delete
}
[2808] Fix | Delete
if (context == "line") return rect;
[2809] Fix | Delete
if (!context) context = "local";
[2810] Fix | Delete
var yOff = heightAtLine(lineObj);
[2811] Fix | Delete
if (context == "local") yOff += paddingTop(cm.display);
[2812] Fix | Delete
else yOff -= cm.display.viewOffset;
[2813] Fix | Delete
if (context == "page" || context == "window") {
[2814] Fix | Delete
var lOff = cm.display.lineSpace.getBoundingClientRect();
[2815] Fix | Delete
yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
[2816] Fix | Delete
var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
[2817] Fix | Delete
rect.left += xOff; rect.right += xOff;
[2818] Fix | Delete
}
[2819] Fix | Delete
rect.top += yOff; rect.bottom += yOff;
[2820] Fix | Delete
return rect;
[2821] Fix | Delete
}
[2822] Fix | Delete
[2823] Fix | Delete
// Coverts a box from "div" coords to another coordinate system.
[2824] Fix | Delete
// Context may be "window", "page", "div", or "local"/null.
[2825] Fix | Delete
function fromCoordSystem(cm, coords, context) {
[2826] Fix | Delete
if (context == "div") return coords;
[2827] Fix | Delete
var left = coords.left, top = coords.top;
[2828] Fix | Delete
// First move into "page" coordinate system
[2829] Fix | Delete
if (context == "page") {
[2830] Fix | Delete
left -= pageScrollX();
[2831] Fix | Delete
top -= pageScrollY();
[2832] Fix | Delete
} else if (context == "local" || !context) {
[2833] Fix | Delete
var localBox = cm.display.sizer.getBoundingClientRect();
[2834] Fix | Delete
left += localBox.left;
[2835] Fix | Delete
top += localBox.top;
[2836] Fix | Delete
}
[2837] Fix | Delete
[2838] Fix | Delete
var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
[2839] Fix | Delete
return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
[2840] Fix | Delete
}
[2841] Fix | Delete
[2842] Fix | Delete
function charCoords(cm, pos, context, lineObj, bias) {
[2843] Fix | Delete
if (!lineObj) lineObj = getLine(cm.doc, pos.line);
[2844] Fix | Delete
return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
[2845] Fix | Delete
}
[2846] Fix | Delete
[2847] Fix | Delete
// Returns a box for a given cursor position, which may have an
[2848] Fix | Delete
// 'other' property containing the position of the secondary cursor
[2849] Fix | Delete
// on a bidi boundary.
[2850] Fix | Delete
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
[2851] Fix | Delete
lineObj = lineObj || getLine(cm.doc, pos.line);
[2852] Fix | Delete
if (!preparedMeasure) preparedMeasure = prepareMeasureForLine(cm, lineObj);
[2853] Fix | Delete
function get(ch, right) {
[2854] Fix | Delete
var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
[2855] Fix | Delete
if (right) m.left = m.right; else m.right = m.left;
[2856] Fix | Delete
return intoCoordSystem(cm, lineObj, m, context);
[2857] Fix | Delete
}
[2858] Fix | Delete
function getBidi(ch, partPos) {
[2859] Fix | Delete
var part = order[partPos], right = part.level % 2;
[2860] Fix | Delete
if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
[2861] Fix | Delete
part = order[--partPos];
[2862] Fix | Delete
ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
[2863] Fix | Delete
right = true;
[2864] Fix | Delete
} else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
[2865] Fix | Delete
part = order[++partPos];
[2866] Fix | Delete
ch = bidiLeft(part) - part.level % 2;
[2867] Fix | Delete
right = false;
[2868] Fix | Delete
}
[2869] Fix | Delete
if (right && ch == part.to && ch > part.from) return get(ch - 1);
[2870] Fix | Delete
return get(ch, right);
[2871] Fix | Delete
}
[2872] Fix | Delete
var order = getOrder(lineObj), ch = pos.ch;
[2873] Fix | Delete
if (!order) return get(ch);
[2874] Fix | Delete
var partPos = getBidiPartAt(order, ch);
[2875] Fix | Delete
var val = getBidi(ch, partPos);
[2876] Fix | Delete
if (bidiOther != null) val.other = getBidi(ch, bidiOther);
[2877] Fix | Delete
return val;
[2878] Fix | Delete
}
[2879] Fix | Delete
[2880] Fix | Delete
// Used to cheaply estimate the coordinates for a position. Used for
[2881] Fix | Delete
// intermediate scroll updates.
[2882] Fix | Delete
function estimateCoords(cm, pos) {
[2883] Fix | Delete
var left = 0, pos = clipPos(cm.doc, pos);
[2884] Fix | Delete
if (!cm.options.lineWrapping) left = charWidth(cm.display) * pos.ch;
[2885] Fix | Delete
var lineObj = getLine(cm.doc, pos.line);
[2886] Fix | Delete
var top = heightAtLine(lineObj) + paddingTop(cm.display);
[2887] Fix | Delete
return {left: left, right: left, top: top, bottom: top + lineObj.height};
[2888] Fix | Delete
}
[2889] Fix | Delete
[2890] Fix | Delete
// Positions returned by coordsChar contain some extra information.
[2891] Fix | Delete
// xRel is the relative x position of the input coordinates compared
[2892] Fix | Delete
// to the found position (so xRel > 0 means the coordinates are to
[2893] Fix | Delete
// the right of the character position, for example). When outside
[2894] Fix | Delete
// is true, that means the coordinates lie outside the line's
[2895] Fix | Delete
// vertical range.
[2896] Fix | Delete
function PosWithInfo(line, ch, outside, xRel) {
[2897] Fix | Delete
var pos = Pos(line, ch);
[2898] Fix | Delete
pos.xRel = xRel;
[2899] Fix | Delete
if (outside) pos.outside = true;
[2900] Fix | Delete
return pos;
[2901] Fix | Delete
}
[2902] Fix | Delete
[2903] Fix | Delete
// Compute the character position closest to the given coordinates.
[2904] Fix | Delete
// Input must be lineSpace-local ("div" coordinate system).
[2905] Fix | Delete
function coordsChar(cm, x, y) {
[2906] Fix | Delete
var doc = cm.doc;
[2907] Fix | Delete
y += cm.display.viewOffset;
[2908] Fix | Delete
if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
[2909] Fix | Delete
var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
[2910] Fix | Delete
if (lineN > last)
[2911] Fix | Delete
return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
[2912] Fix | Delete
if (x < 0) x = 0;
[2913] Fix | Delete
[2914] Fix | Delete
var lineObj = getLine(doc, lineN);
[2915] Fix | Delete
for (;;) {
[2916] Fix | Delete
var found = coordsCharInner(cm, lineObj, lineN, x, y);
[2917] Fix | Delete
var merged = collapsedSpanAtEnd(lineObj);
[2918] Fix | Delete
var mergedPos = merged && merged.find(0, true);
[2919] Fix | Delete
if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
[2920] Fix | Delete
lineN = lineNo(lineObj = mergedPos.to.line);
[2921] Fix | Delete
else
[2922] Fix | Delete
return found;
[2923] Fix | Delete
}
[2924] Fix | Delete
}
[2925] Fix | Delete
[2926] Fix | Delete
function coordsCharInner(cm, lineObj, lineNo, x, y) {
[2927] Fix | Delete
var innerOff = y - heightAtLine(lineObj);
[2928] Fix | Delete
var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
[2929] Fix | Delete
var preparedMeasure = prepareMeasureForLine(cm, lineObj);
[2930] Fix | Delete
[2931] Fix | Delete
function getX(ch) {
[2932] Fix | Delete
var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
[2933] Fix | Delete
wrongLine = true;
[2934] Fix | Delete
if (innerOff > sp.bottom) return sp.left - adjust;
[2935] Fix | Delete
else if (innerOff < sp.top) return sp.left + adjust;
[2936] Fix | Delete
else wrongLine = false;
[2937] Fix | Delete
return sp.left;
[2938] Fix | Delete
}
[2939] Fix | Delete
[2940] Fix | Delete
var bidi = getOrder(lineObj), dist = lineObj.text.length;
[2941] Fix | Delete
var from = lineLeft(lineObj), to = lineRight(lineObj);
[2942] Fix | Delete
var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
[2943] Fix | Delete
[2944] Fix | Delete
if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
[2945] Fix | Delete
// Do a binary search between these bounds.
[2946] Fix | Delete
for (;;) {
[2947] Fix | Delete
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
[2948] Fix | Delete
var ch = x < fromX || x - fromX <= toX - x ? from : to;
[2949] Fix | Delete
var outside = ch == from ? fromOutside : toOutside
[2950] Fix | Delete
var xDiff = x - (ch == from ? fromX : toX);
[2951] Fix | Delete
// This is a kludge to handle the case where the coordinates
[2952] Fix | Delete
// are after a line-wrapped line. We should replace it with a
[2953] Fix | Delete
// more general handling of cursor positions around line
[2954] Fix | Delete
// breaks. (Issue #4078)
[2955] Fix | Delete
if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 &&
[2956] Fix | Delete
ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) {
[2957] Fix | Delete
var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right");
[2958] Fix | Delete
if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) {
[2959] Fix | Delete
outside = false
[2960] Fix | Delete
ch++
[2961] Fix | Delete
xDiff = x - charSize.right
[2962] Fix | Delete
}
[2963] Fix | Delete
}
[2964] Fix | Delete
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
[2965] Fix | Delete
var pos = PosWithInfo(lineNo, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
[2966] Fix | Delete
return pos;
[2967] Fix | Delete
}
[2968] Fix | Delete
var step = Math.ceil(dist / 2), middle = from + step;
[2969] Fix | Delete
if (bidi) {
[2970] Fix | Delete
middle = from;
[2971] Fix | Delete
for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
[2972] Fix | Delete
}
[2973] Fix | Delete
var middleX = getX(middle);
[2974] Fix | Delete
if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
[2975] Fix | Delete
else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
[2976] Fix | Delete
}
[2977] Fix | Delete
}
[2978] Fix | Delete
[2979] Fix | Delete
var measureText;
[2980] Fix | Delete
// Compute the default text height.
[2981] Fix | Delete
function textHeight(display) {
[2982] Fix | Delete
if (display.cachedTextHeight != null) return display.cachedTextHeight;
[2983] Fix | Delete
if (measureText == null) {
[2984] Fix | Delete
measureText = elt("pre");
[2985] Fix | Delete
// Measure a bunch of lines, for browsers that compute
[2986] Fix | Delete
// fractional heights.
[2987] Fix | Delete
for (var i = 0; i < 49; ++i) {
[2988] Fix | Delete
measureText.appendChild(document.createTextNode("x"));
[2989] Fix | Delete
measureText.appendChild(elt("br"));
[2990] Fix | Delete
}
[2991] Fix | Delete
measureText.appendChild(document.createTextNode("x"));
[2992] Fix | Delete
}
[2993] Fix | Delete
removeChildrenAndAdd(display.measure, measureText);
[2994] Fix | Delete
var height = measureText.offsetHeight / 50;
[2995] Fix | Delete
if (height > 3) display.cachedTextHeight = height;
[2996] Fix | Delete
removeChildren(display.measure);
[2997] Fix | Delete
return height || 1;
[2998] Fix | Delete
}
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function