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
[3000] Fix | Delete
// Compute the default character width.
[3001] Fix | Delete
function charWidth(display) {
[3002] Fix | Delete
if (display.cachedCharWidth != null) return display.cachedCharWidth;
[3003] Fix | Delete
var anchor = elt("span", "xxxxxxxxxx");
[3004] Fix | Delete
var pre = elt("pre", [anchor]);
[3005] Fix | Delete
removeChildrenAndAdd(display.measure, pre);
[3006] Fix | Delete
var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
[3007] Fix | Delete
if (width > 2) display.cachedCharWidth = width;
[3008] Fix | Delete
return width || 10;
[3009] Fix | Delete
}
[3010] Fix | Delete
[3011] Fix | Delete
// OPERATIONS
[3012] Fix | Delete
[3013] Fix | Delete
// Operations are used to wrap a series of changes to the editor
[3014] Fix | Delete
// state in such a way that each change won't have to update the
[3015] Fix | Delete
// cursor and display (which would be awkward, slow, and
[3016] Fix | Delete
// error-prone). Instead, display updates are batched and then all
[3017] Fix | Delete
// combined and executed at once.
[3018] Fix | Delete
[3019] Fix | Delete
var operationGroup = null;
[3020] Fix | Delete
[3021] Fix | Delete
var nextOpId = 0;
[3022] Fix | Delete
// Start a new operation.
[3023] Fix | Delete
function startOperation(cm) {
[3024] Fix | Delete
cm.curOp = {
[3025] Fix | Delete
cm: cm,
[3026] Fix | Delete
viewChanged: false, // Flag that indicates that lines might need to be redrawn
[3027] Fix | Delete
startHeight: cm.doc.height, // Used to detect need to update scrollbar
[3028] Fix | Delete
forceUpdate: false, // Used to force a redraw
[3029] Fix | Delete
updateInput: null, // Whether to reset the input textarea
[3030] Fix | Delete
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
[3031] Fix | Delete
changeObjs: null, // Accumulated changes, for firing change events
[3032] Fix | Delete
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
[3033] Fix | Delete
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
[3034] Fix | Delete
selectionChanged: false, // Whether the selection needs to be redrawn
[3035] Fix | Delete
updateMaxLine: false, // Set when the widest line needs to be determined anew
[3036] Fix | Delete
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
[3037] Fix | Delete
scrollToPos: null, // Used to scroll to a specific position
[3038] Fix | Delete
focus: false,
[3039] Fix | Delete
id: ++nextOpId // Unique ID
[3040] Fix | Delete
};
[3041] Fix | Delete
if (operationGroup) {
[3042] Fix | Delete
operationGroup.ops.push(cm.curOp);
[3043] Fix | Delete
} else {
[3044] Fix | Delete
cm.curOp.ownsGroup = operationGroup = {
[3045] Fix | Delete
ops: [cm.curOp],
[3046] Fix | Delete
delayedCallbacks: []
[3047] Fix | Delete
};
[3048] Fix | Delete
}
[3049] Fix | Delete
}
[3050] Fix | Delete
[3051] Fix | Delete
function fireCallbacksForOps(group) {
[3052] Fix | Delete
// Calls delayed callbacks and cursorActivity handlers until no
[3053] Fix | Delete
// new ones appear
[3054] Fix | Delete
var callbacks = group.delayedCallbacks, i = 0;
[3055] Fix | Delete
do {
[3056] Fix | Delete
for (; i < callbacks.length; i++)
[3057] Fix | Delete
callbacks[i].call(null);
[3058] Fix | Delete
for (var j = 0; j < group.ops.length; j++) {
[3059] Fix | Delete
var op = group.ops[j];
[3060] Fix | Delete
if (op.cursorActivityHandlers)
[3061] Fix | Delete
while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
[3062] Fix | Delete
op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm);
[3063] Fix | Delete
}
[3064] Fix | Delete
} while (i < callbacks.length);
[3065] Fix | Delete
}
[3066] Fix | Delete
[3067] Fix | Delete
// Finish an operation, updating the display and signalling delayed events
[3068] Fix | Delete
function endOperation(cm) {
[3069] Fix | Delete
var op = cm.curOp, group = op.ownsGroup;
[3070] Fix | Delete
if (!group) return;
[3071] Fix | Delete
[3072] Fix | Delete
try { fireCallbacksForOps(group); }
[3073] Fix | Delete
finally {
[3074] Fix | Delete
operationGroup = null;
[3075] Fix | Delete
for (var i = 0; i < group.ops.length; i++)
[3076] Fix | Delete
group.ops[i].cm.curOp = null;
[3077] Fix | Delete
endOperations(group);
[3078] Fix | Delete
}
[3079] Fix | Delete
}
[3080] Fix | Delete
[3081] Fix | Delete
// The DOM updates done when an operation finishes are batched so
[3082] Fix | Delete
// that the minimum number of relayouts are required.
[3083] Fix | Delete
function endOperations(group) {
[3084] Fix | Delete
var ops = group.ops;
[3085] Fix | Delete
for (var i = 0; i < ops.length; i++) // Read DOM
[3086] Fix | Delete
endOperation_R1(ops[i]);
[3087] Fix | Delete
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
[3088] Fix | Delete
endOperation_W1(ops[i]);
[3089] Fix | Delete
for (var i = 0; i < ops.length; i++) // Read DOM
[3090] Fix | Delete
endOperation_R2(ops[i]);
[3091] Fix | Delete
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
[3092] Fix | Delete
endOperation_W2(ops[i]);
[3093] Fix | Delete
for (var i = 0; i < ops.length; i++) // Read DOM
[3094] Fix | Delete
endOperation_finish(ops[i]);
[3095] Fix | Delete
}
[3096] Fix | Delete
[3097] Fix | Delete
function endOperation_R1(op) {
[3098] Fix | Delete
var cm = op.cm, display = cm.display;
[3099] Fix | Delete
maybeClipScrollbars(cm);
[3100] Fix | Delete
if (op.updateMaxLine) findMaxLine(cm);
[3101] Fix | Delete
[3102] Fix | Delete
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
[3103] Fix | Delete
op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
[3104] Fix | Delete
op.scrollToPos.to.line >= display.viewTo) ||
[3105] Fix | Delete
display.maxLineChanged && cm.options.lineWrapping;
[3106] Fix | Delete
op.update = op.mustUpdate &&
[3107] Fix | Delete
new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
[3108] Fix | Delete
}
[3109] Fix | Delete
[3110] Fix | Delete
function endOperation_W1(op) {
[3111] Fix | Delete
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
[3112] Fix | Delete
}
[3113] Fix | Delete
[3114] Fix | Delete
function endOperation_R2(op) {
[3115] Fix | Delete
var cm = op.cm, display = cm.display;
[3116] Fix | Delete
if (op.updatedDisplay) updateHeightsInViewport(cm);
[3117] Fix | Delete
[3118] Fix | Delete
op.barMeasure = measureForScrollbars(cm);
[3119] Fix | Delete
[3120] Fix | Delete
// If the max line changed since it was last measured, measure it,
[3121] Fix | Delete
// and ensure the document's width matches it.
[3122] Fix | Delete
// updateDisplay_W2 will use these properties to do the actual resizing
[3123] Fix | Delete
if (display.maxLineChanged && !cm.options.lineWrapping) {
[3124] Fix | Delete
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
[3125] Fix | Delete
cm.display.sizerWidth = op.adjustWidthTo;
[3126] Fix | Delete
op.barMeasure.scrollWidth =
[3127] Fix | Delete
Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
[3128] Fix | Delete
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
[3129] Fix | Delete
}
[3130] Fix | Delete
[3131] Fix | Delete
if (op.updatedDisplay || op.selectionChanged)
[3132] Fix | Delete
op.preparedSelection = display.input.prepareSelection(op.focus);
[3133] Fix | Delete
}
[3134] Fix | Delete
[3135] Fix | Delete
function endOperation_W2(op) {
[3136] Fix | Delete
var cm = op.cm;
[3137] Fix | Delete
[3138] Fix | Delete
if (op.adjustWidthTo != null) {
[3139] Fix | Delete
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
[3140] Fix | Delete
if (op.maxScrollLeft < cm.doc.scrollLeft)
[3141] Fix | Delete
setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
[3142] Fix | Delete
cm.display.maxLineChanged = false;
[3143] Fix | Delete
}
[3144] Fix | Delete
[3145] Fix | Delete
var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus())
[3146] Fix | Delete
if (op.preparedSelection)
[3147] Fix | Delete
cm.display.input.showSelection(op.preparedSelection, takeFocus);
[3148] Fix | Delete
if (op.updatedDisplay || op.startHeight != cm.doc.height)
[3149] Fix | Delete
updateScrollbars(cm, op.barMeasure);
[3150] Fix | Delete
if (op.updatedDisplay)
[3151] Fix | Delete
setDocumentHeight(cm, op.barMeasure);
[3152] Fix | Delete
[3153] Fix | Delete
if (op.selectionChanged) restartBlink(cm);
[3154] Fix | Delete
[3155] Fix | Delete
if (cm.state.focused && op.updateInput)
[3156] Fix | Delete
cm.display.input.reset(op.typing);
[3157] Fix | Delete
if (takeFocus) ensureFocus(op.cm);
[3158] Fix | Delete
}
[3159] Fix | Delete
[3160] Fix | Delete
function endOperation_finish(op) {
[3161] Fix | Delete
var cm = op.cm, display = cm.display, doc = cm.doc;
[3162] Fix | Delete
[3163] Fix | Delete
if (op.updatedDisplay) postUpdateDisplay(cm, op.update);
[3164] Fix | Delete
[3165] Fix | Delete
// Abort mouse wheel delta measurement, when scrolling explicitly
[3166] Fix | Delete
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
[3167] Fix | Delete
display.wheelStartX = display.wheelStartY = null;
[3168] Fix | Delete
[3169] Fix | Delete
// Propagate the scroll position to the actual DOM scroller
[3170] Fix | Delete
if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
[3171] Fix | Delete
doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
[3172] Fix | Delete
display.scrollbars.setScrollTop(doc.scrollTop);
[3173] Fix | Delete
display.scroller.scrollTop = doc.scrollTop;
[3174] Fix | Delete
}
[3175] Fix | Delete
if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
[3176] Fix | Delete
doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft));
[3177] Fix | Delete
display.scrollbars.setScrollLeft(doc.scrollLeft);
[3178] Fix | Delete
display.scroller.scrollLeft = doc.scrollLeft;
[3179] Fix | Delete
alignHorizontally(cm);
[3180] Fix | Delete
}
[3181] Fix | Delete
// If we need to scroll a specific position into view, do so.
[3182] Fix | Delete
if (op.scrollToPos) {
[3183] Fix | Delete
var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
[3184] Fix | Delete
clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
[3185] Fix | Delete
if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
[3186] Fix | Delete
}
[3187] Fix | Delete
[3188] Fix | Delete
// Fire events for markers that are hidden/unidden by editing or
[3189] Fix | Delete
// undoing
[3190] Fix | Delete
var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
[3191] Fix | Delete
if (hidden) for (var i = 0; i < hidden.length; ++i)
[3192] Fix | Delete
if (!hidden[i].lines.length) signal(hidden[i], "hide");
[3193] Fix | Delete
if (unhidden) for (var i = 0; i < unhidden.length; ++i)
[3194] Fix | Delete
if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
[3195] Fix | Delete
[3196] Fix | Delete
if (display.wrapper.offsetHeight)
[3197] Fix | Delete
doc.scrollTop = cm.display.scroller.scrollTop;
[3198] Fix | Delete
[3199] Fix | Delete
// Fire change events, and delayed event handlers
[3200] Fix | Delete
if (op.changeObjs)
[3201] Fix | Delete
signal(cm, "changes", cm, op.changeObjs);
[3202] Fix | Delete
if (op.update)
[3203] Fix | Delete
op.update.finish();
[3204] Fix | Delete
}
[3205] Fix | Delete
[3206] Fix | Delete
// Run the given function in an operation
[3207] Fix | Delete
function runInOp(cm, f) {
[3208] Fix | Delete
if (cm.curOp) return f();
[3209] Fix | Delete
startOperation(cm);
[3210] Fix | Delete
try { return f(); }
[3211] Fix | Delete
finally { endOperation(cm); }
[3212] Fix | Delete
}
[3213] Fix | Delete
// Wraps a function in an operation. Returns the wrapped function.
[3214] Fix | Delete
function operation(cm, f) {
[3215] Fix | Delete
return function() {
[3216] Fix | Delete
if (cm.curOp) return f.apply(cm, arguments);
[3217] Fix | Delete
startOperation(cm);
[3218] Fix | Delete
try { return f.apply(cm, arguments); }
[3219] Fix | Delete
finally { endOperation(cm); }
[3220] Fix | Delete
};
[3221] Fix | Delete
}
[3222] Fix | Delete
// Used to add methods to editor and doc instances, wrapping them in
[3223] Fix | Delete
// operations.
[3224] Fix | Delete
function methodOp(f) {
[3225] Fix | Delete
return function() {
[3226] Fix | Delete
if (this.curOp) return f.apply(this, arguments);
[3227] Fix | Delete
startOperation(this);
[3228] Fix | Delete
try { return f.apply(this, arguments); }
[3229] Fix | Delete
finally { endOperation(this); }
[3230] Fix | Delete
};
[3231] Fix | Delete
}
[3232] Fix | Delete
function docMethodOp(f) {
[3233] Fix | Delete
return function() {
[3234] Fix | Delete
var cm = this.cm;
[3235] Fix | Delete
if (!cm || cm.curOp) return f.apply(this, arguments);
[3236] Fix | Delete
startOperation(cm);
[3237] Fix | Delete
try { return f.apply(this, arguments); }
[3238] Fix | Delete
finally { endOperation(cm); }
[3239] Fix | Delete
};
[3240] Fix | Delete
}
[3241] Fix | Delete
[3242] Fix | Delete
// VIEW TRACKING
[3243] Fix | Delete
[3244] Fix | Delete
// These objects are used to represent the visible (currently drawn)
[3245] Fix | Delete
// part of the document. A LineView may correspond to multiple
[3246] Fix | Delete
// logical lines, if those are connected by collapsed ranges.
[3247] Fix | Delete
function LineView(doc, line, lineN) {
[3248] Fix | Delete
// The starting line
[3249] Fix | Delete
this.line = line;
[3250] Fix | Delete
// Continuing lines, if any
[3251] Fix | Delete
this.rest = visualLineContinued(line);
[3252] Fix | Delete
// Number of logical lines in this visual line
[3253] Fix | Delete
this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
[3254] Fix | Delete
this.node = this.text = null;
[3255] Fix | Delete
this.hidden = lineIsHidden(doc, line);
[3256] Fix | Delete
}
[3257] Fix | Delete
[3258] Fix | Delete
// Create a range of LineView objects for the given lines.
[3259] Fix | Delete
function buildViewArray(cm, from, to) {
[3260] Fix | Delete
var array = [], nextPos;
[3261] Fix | Delete
for (var pos = from; pos < to; pos = nextPos) {
[3262] Fix | Delete
var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
[3263] Fix | Delete
nextPos = pos + view.size;
[3264] Fix | Delete
array.push(view);
[3265] Fix | Delete
}
[3266] Fix | Delete
return array;
[3267] Fix | Delete
}
[3268] Fix | Delete
[3269] Fix | Delete
// Updates the display.view data structure for a given change to the
[3270] Fix | Delete
// document. From and to are in pre-change coordinates. Lendiff is
[3271] Fix | Delete
// the amount of lines added or subtracted by the change. This is
[3272] Fix | Delete
// used for changes that span multiple lines, or change the way
[3273] Fix | Delete
// lines are divided into visual lines. regLineChange (below)
[3274] Fix | Delete
// registers single-line changes.
[3275] Fix | Delete
function regChange(cm, from, to, lendiff) {
[3276] Fix | Delete
if (from == null) from = cm.doc.first;
[3277] Fix | Delete
if (to == null) to = cm.doc.first + cm.doc.size;
[3278] Fix | Delete
if (!lendiff) lendiff = 0;
[3279] Fix | Delete
[3280] Fix | Delete
var display = cm.display;
[3281] Fix | Delete
if (lendiff && to < display.viewTo &&
[3282] Fix | Delete
(display.updateLineNumbers == null || display.updateLineNumbers > from))
[3283] Fix | Delete
display.updateLineNumbers = from;
[3284] Fix | Delete
[3285] Fix | Delete
cm.curOp.viewChanged = true;
[3286] Fix | Delete
[3287] Fix | Delete
if (from >= display.viewTo) { // Change after
[3288] Fix | Delete
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
[3289] Fix | Delete
resetView(cm);
[3290] Fix | Delete
} else if (to <= display.viewFrom) { // Change before
[3291] Fix | Delete
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
[3292] Fix | Delete
resetView(cm);
[3293] Fix | Delete
} else {
[3294] Fix | Delete
display.viewFrom += lendiff;
[3295] Fix | Delete
display.viewTo += lendiff;
[3296] Fix | Delete
}
[3297] Fix | Delete
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
[3298] Fix | Delete
resetView(cm);
[3299] Fix | Delete
} else if (from <= display.viewFrom) { // Top overlap
[3300] Fix | Delete
var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
[3301] Fix | Delete
if (cut) {
[3302] Fix | Delete
display.view = display.view.slice(cut.index);
[3303] Fix | Delete
display.viewFrom = cut.lineN;
[3304] Fix | Delete
display.viewTo += lendiff;
[3305] Fix | Delete
} else {
[3306] Fix | Delete
resetView(cm);
[3307] Fix | Delete
}
[3308] Fix | Delete
} else if (to >= display.viewTo) { // Bottom overlap
[3309] Fix | Delete
var cut = viewCuttingPoint(cm, from, from, -1);
[3310] Fix | Delete
if (cut) {
[3311] Fix | Delete
display.view = display.view.slice(0, cut.index);
[3312] Fix | Delete
display.viewTo = cut.lineN;
[3313] Fix | Delete
} else {
[3314] Fix | Delete
resetView(cm);
[3315] Fix | Delete
}
[3316] Fix | Delete
} else { // Gap in the middle
[3317] Fix | Delete
var cutTop = viewCuttingPoint(cm, from, from, -1);
[3318] Fix | Delete
var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
[3319] Fix | Delete
if (cutTop && cutBot) {
[3320] Fix | Delete
display.view = display.view.slice(0, cutTop.index)
[3321] Fix | Delete
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
[3322] Fix | Delete
.concat(display.view.slice(cutBot.index));
[3323] Fix | Delete
display.viewTo += lendiff;
[3324] Fix | Delete
} else {
[3325] Fix | Delete
resetView(cm);
[3326] Fix | Delete
}
[3327] Fix | Delete
}
[3328] Fix | Delete
[3329] Fix | Delete
var ext = display.externalMeasured;
[3330] Fix | Delete
if (ext) {
[3331] Fix | Delete
if (to < ext.lineN)
[3332] Fix | Delete
ext.lineN += lendiff;
[3333] Fix | Delete
else if (from < ext.lineN + ext.size)
[3334] Fix | Delete
display.externalMeasured = null;
[3335] Fix | Delete
}
[3336] Fix | Delete
}
[3337] Fix | Delete
[3338] Fix | Delete
// Register a change to a single line. Type must be one of "text",
[3339] Fix | Delete
// "gutter", "class", "widget"
[3340] Fix | Delete
function regLineChange(cm, line, type) {
[3341] Fix | Delete
cm.curOp.viewChanged = true;
[3342] Fix | Delete
var display = cm.display, ext = cm.display.externalMeasured;
[3343] Fix | Delete
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
[3344] Fix | Delete
display.externalMeasured = null;
[3345] Fix | Delete
[3346] Fix | Delete
if (line < display.viewFrom || line >= display.viewTo) return;
[3347] Fix | Delete
var lineView = display.view[findViewIndex(cm, line)];
[3348] Fix | Delete
if (lineView.node == null) return;
[3349] Fix | Delete
var arr = lineView.changes || (lineView.changes = []);
[3350] Fix | Delete
if (indexOf(arr, type) == -1) arr.push(type);
[3351] Fix | Delete
}
[3352] Fix | Delete
[3353] Fix | Delete
// Clear the view.
[3354] Fix | Delete
function resetView(cm) {
[3355] Fix | Delete
cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
[3356] Fix | Delete
cm.display.view = [];
[3357] Fix | Delete
cm.display.viewOffset = 0;
[3358] Fix | Delete
}
[3359] Fix | Delete
[3360] Fix | Delete
// Find the view element corresponding to a given line. Return null
[3361] Fix | Delete
// when the line isn't visible.
[3362] Fix | Delete
function findViewIndex(cm, n) {
[3363] Fix | Delete
if (n >= cm.display.viewTo) return null;
[3364] Fix | Delete
n -= cm.display.viewFrom;
[3365] Fix | Delete
if (n < 0) return null;
[3366] Fix | Delete
var view = cm.display.view;
[3367] Fix | Delete
for (var i = 0; i < view.length; i++) {
[3368] Fix | Delete
n -= view[i].size;
[3369] Fix | Delete
if (n < 0) return i;
[3370] Fix | Delete
}
[3371] Fix | Delete
}
[3372] Fix | Delete
[3373] Fix | Delete
function viewCuttingPoint(cm, oldN, newN, dir) {
[3374] Fix | Delete
var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
[3375] Fix | Delete
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
[3376] Fix | Delete
return {index: index, lineN: newN};
[3377] Fix | Delete
for (var i = 0, n = cm.display.viewFrom; i < index; i++)
[3378] Fix | Delete
n += view[i].size;
[3379] Fix | Delete
if (n != oldN) {
[3380] Fix | Delete
if (dir > 0) {
[3381] Fix | Delete
if (index == view.length - 1) return null;
[3382] Fix | Delete
diff = (n + view[index].size) - oldN;
[3383] Fix | Delete
index++;
[3384] Fix | Delete
} else {
[3385] Fix | Delete
diff = n - oldN;
[3386] Fix | Delete
}
[3387] Fix | Delete
oldN += diff; newN += diff;
[3388] Fix | Delete
}
[3389] Fix | Delete
while (visualLineNo(cm.doc, newN) != newN) {
[3390] Fix | Delete
if (index == (dir < 0 ? 0 : view.length - 1)) return null;
[3391] Fix | Delete
newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
[3392] Fix | Delete
index += dir;
[3393] Fix | Delete
}
[3394] Fix | Delete
return {index: index, lineN: newN};
[3395] Fix | Delete
}
[3396] Fix | Delete
[3397] Fix | Delete
// Force the view to cover a given range, adding empty view element
[3398] Fix | Delete
// or clipping off existing ones as needed.
[3399] Fix | Delete
function adjustView(cm, from, to) {
[3400] Fix | Delete
var display = cm.display, view = display.view;
[3401] Fix | Delete
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
[3402] Fix | Delete
display.view = buildViewArray(cm, from, to);
[3403] Fix | Delete
display.viewFrom = from;
[3404] Fix | Delete
} else {
[3405] Fix | Delete
if (display.viewFrom > from)
[3406] Fix | Delete
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
[3407] Fix | Delete
else if (display.viewFrom < from)
[3408] Fix | Delete
display.view = display.view.slice(findViewIndex(cm, from));
[3409] Fix | Delete
display.viewFrom = from;
[3410] Fix | Delete
if (display.viewTo < to)
[3411] Fix | Delete
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
[3412] Fix | Delete
else if (display.viewTo > to)
[3413] Fix | Delete
display.view = display.view.slice(0, findViewIndex(cm, to));
[3414] Fix | Delete
}
[3415] Fix | Delete
display.viewTo = to;
[3416] Fix | Delete
}
[3417] Fix | Delete
[3418] Fix | Delete
// Count the number of lines in the view whose DOM representation is
[3419] Fix | Delete
// out of date (or nonexistent).
[3420] Fix | Delete
function countDirtyView(cm) {
[3421] Fix | Delete
var view = cm.display.view, dirty = 0;
[3422] Fix | Delete
for (var i = 0; i < view.length; i++) {
[3423] Fix | Delete
var lineView = view[i];
[3424] Fix | Delete
if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty;
[3425] Fix | Delete
}
[3426] Fix | Delete
return dirty;
[3427] Fix | Delete
}
[3428] Fix | Delete
[3429] Fix | Delete
// EVENT HANDLERS
[3430] Fix | Delete
[3431] Fix | Delete
// Attach the necessary event handlers when initializing the editor
[3432] Fix | Delete
function registerEventHandlers(cm) {
[3433] Fix | Delete
var d = cm.display;
[3434] Fix | Delete
on(d.scroller, "mousedown", operation(cm, onMouseDown));
[3435] Fix | Delete
// Older IE's will not fire a second mousedown for a double click
[3436] Fix | Delete
if (ie && ie_version < 11)
[3437] Fix | Delete
on(d.scroller, "dblclick", operation(cm, function(e) {
[3438] Fix | Delete
if (signalDOMEvent(cm, e)) return;
[3439] Fix | Delete
var pos = posFromMouse(cm, e);
[3440] Fix | Delete
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
[3441] Fix | Delete
e_preventDefault(e);
[3442] Fix | Delete
var word = cm.findWordAt(pos);
[3443] Fix | Delete
extendSelection(cm.doc, word.anchor, word.head);
[3444] Fix | Delete
}));
[3445] Fix | Delete
else
[3446] Fix | Delete
on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
[3447] Fix | Delete
// Some browsers fire contextmenu *after* opening the menu, at
[3448] Fix | Delete
// which point we can't mess with it anymore. Context menu is
[3449] Fix | Delete
// handled in onMouseDown for these browsers.
[3450] Fix | Delete
if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
[3451] Fix | Delete
[3452] Fix | Delete
// Used to suppress mouse event handling when a touch happens
[3453] Fix | Delete
var touchFinished, prevTouch = {end: 0};
[3454] Fix | Delete
function finishTouch() {
[3455] Fix | Delete
if (d.activeTouch) {
[3456] Fix | Delete
touchFinished = setTimeout(function() {d.activeTouch = null;}, 1000);
[3457] Fix | Delete
prevTouch = d.activeTouch;
[3458] Fix | Delete
prevTouch.end = +new Date;
[3459] Fix | Delete
}
[3460] Fix | Delete
};
[3461] Fix | Delete
function isMouseLikeTouchEvent(e) {
[3462] Fix | Delete
if (e.touches.length != 1) return false;
[3463] Fix | Delete
var touch = e.touches[0];
[3464] Fix | Delete
return touch.radiusX <= 1 && touch.radiusY <= 1;
[3465] Fix | Delete
}
[3466] Fix | Delete
function farAway(touch, other) {
[3467] Fix | Delete
if (other.left == null) return true;
[3468] Fix | Delete
var dx = other.left - touch.left, dy = other.top - touch.top;
[3469] Fix | Delete
return dx * dx + dy * dy > 20 * 20;
[3470] Fix | Delete
}
[3471] Fix | Delete
on(d.scroller, "touchstart", function(e) {
[3472] Fix | Delete
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
[3473] Fix | Delete
clearTimeout(touchFinished);
[3474] Fix | Delete
var now = +new Date;
[3475] Fix | Delete
d.activeTouch = {start: now, moved: false,
[3476] Fix | Delete
prev: now - prevTouch.end <= 300 ? prevTouch : null};
[3477] Fix | Delete
if (e.touches.length == 1) {
[3478] Fix | Delete
d.activeTouch.left = e.touches[0].pageX;
[3479] Fix | Delete
d.activeTouch.top = e.touches[0].pageY;
[3480] Fix | Delete
}
[3481] Fix | Delete
}
[3482] Fix | Delete
});
[3483] Fix | Delete
on(d.scroller, "touchmove", function() {
[3484] Fix | Delete
if (d.activeTouch) d.activeTouch.moved = true;
[3485] Fix | Delete
});
[3486] Fix | Delete
on(d.scroller, "touchend", function(e) {
[3487] Fix | Delete
var touch = d.activeTouch;
[3488] Fix | Delete
if (touch && !eventInWidget(d, e) && touch.left != null &&
[3489] Fix | Delete
!touch.moved && new Date - touch.start < 300) {
[3490] Fix | Delete
var pos = cm.coordsChar(d.activeTouch, "page"), range;
[3491] Fix | Delete
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
[3492] Fix | Delete
range = new Range(pos, pos);
[3493] Fix | Delete
else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
[3494] Fix | Delete
range = cm.findWordAt(pos);
[3495] Fix | Delete
else // Triple tap
[3496] Fix | Delete
range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
[3497] Fix | Delete
cm.setSelection(range.anchor, range.head);
[3498] Fix | Delete
cm.focus();
[3499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function