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
// Since the delta values reported on mouse wheel events are
[4000] Fix | Delete
// unstandardized between browsers and even browser versions, and
[4001] Fix | Delete
// generally horribly unpredictable, this code starts by measuring
[4002] Fix | Delete
// the scroll effect that the first few mouse wheel events have,
[4003] Fix | Delete
// and, from that, detects the way it can convert deltas to pixel
[4004] Fix | Delete
// offsets afterwards.
[4005] Fix | Delete
//
[4006] Fix | Delete
// The reason we want to know the amount a wheel event will scroll
[4007] Fix | Delete
// is that it gives us a chance to update the display before the
[4008] Fix | Delete
// actual scrolling happens, reducing flickering.
[4009] Fix | Delete
[4010] Fix | Delete
var wheelSamples = 0, wheelPixelsPerUnit = null;
[4011] Fix | Delete
// Fill in a browser-detected starting value on browsers where we
[4012] Fix | Delete
// know one. These don't have to be accurate -- the result of them
[4013] Fix | Delete
// being wrong would just be a slight flicker on the first wheel
[4014] Fix | Delete
// scroll (if it is large enough).
[4015] Fix | Delete
if (ie) wheelPixelsPerUnit = -.53;
[4016] Fix | Delete
else if (gecko) wheelPixelsPerUnit = 15;
[4017] Fix | Delete
else if (chrome) wheelPixelsPerUnit = -.7;
[4018] Fix | Delete
else if (safari) wheelPixelsPerUnit = -1/3;
[4019] Fix | Delete
[4020] Fix | Delete
var wheelEventDelta = function(e) {
[4021] Fix | Delete
var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
[4022] Fix | Delete
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
[4023] Fix | Delete
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
[4024] Fix | Delete
else if (dy == null) dy = e.wheelDelta;
[4025] Fix | Delete
return {x: dx, y: dy};
[4026] Fix | Delete
};
[4027] Fix | Delete
CodeMirror.wheelEventPixels = function(e) {
[4028] Fix | Delete
var delta = wheelEventDelta(e);
[4029] Fix | Delete
delta.x *= wheelPixelsPerUnit;
[4030] Fix | Delete
delta.y *= wheelPixelsPerUnit;
[4031] Fix | Delete
return delta;
[4032] Fix | Delete
};
[4033] Fix | Delete
[4034] Fix | Delete
function onScrollWheel(cm, e) {
[4035] Fix | Delete
var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
[4036] Fix | Delete
[4037] Fix | Delete
var display = cm.display, scroll = display.scroller;
[4038] Fix | Delete
// Quit if there's nothing to scroll here
[4039] Fix | Delete
var canScrollX = scroll.scrollWidth > scroll.clientWidth;
[4040] Fix | Delete
var canScrollY = scroll.scrollHeight > scroll.clientHeight;
[4041] Fix | Delete
if (!(dx && canScrollX || dy && canScrollY)) return;
[4042] Fix | Delete
[4043] Fix | Delete
// Webkit browsers on OS X abort momentum scrolls when the target
[4044] Fix | Delete
// of the scroll event is removed from the scrollable element.
[4045] Fix | Delete
// This hack (see related code in patchDisplay) makes sure the
[4046] Fix | Delete
// element is kept around.
[4047] Fix | Delete
if (dy && mac && webkit) {
[4048] Fix | Delete
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
[4049] Fix | Delete
for (var i = 0; i < view.length; i++) {
[4050] Fix | Delete
if (view[i].node == cur) {
[4051] Fix | Delete
cm.display.currentWheelTarget = cur;
[4052] Fix | Delete
break outer;
[4053] Fix | Delete
}
[4054] Fix | Delete
}
[4055] Fix | Delete
}
[4056] Fix | Delete
}
[4057] Fix | Delete
[4058] Fix | Delete
// On some browsers, horizontal scrolling will cause redraws to
[4059] Fix | Delete
// happen before the gutter has been realigned, causing it to
[4060] Fix | Delete
// wriggle around in a most unseemly way. When we have an
[4061] Fix | Delete
// estimated pixels/delta value, we just handle horizontal
[4062] Fix | Delete
// scrolling entirely here. It'll be slightly off from native, but
[4063] Fix | Delete
// better than glitching out.
[4064] Fix | Delete
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
[4065] Fix | Delete
if (dy && canScrollY)
[4066] Fix | Delete
setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
[4067] Fix | Delete
setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
[4068] Fix | Delete
// Only prevent default scrolling if vertical scrolling is
[4069] Fix | Delete
// actually possible. Otherwise, it causes vertical scroll
[4070] Fix | Delete
// jitter on OSX trackpads when deltaX is small and deltaY
[4071] Fix | Delete
// is large (issue #3579)
[4072] Fix | Delete
if (!dy || (dy && canScrollY))
[4073] Fix | Delete
e_preventDefault(e);
[4074] Fix | Delete
display.wheelStartX = null; // Abort measurement, if in progress
[4075] Fix | Delete
return;
[4076] Fix | Delete
}
[4077] Fix | Delete
[4078] Fix | Delete
// 'Project' the visible viewport to cover the area that is being
[4079] Fix | Delete
// scrolled into view (if we know enough to estimate it).
[4080] Fix | Delete
if (dy && wheelPixelsPerUnit != null) {
[4081] Fix | Delete
var pixels = dy * wheelPixelsPerUnit;
[4082] Fix | Delete
var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
[4083] Fix | Delete
if (pixels < 0) top = Math.max(0, top + pixels - 50);
[4084] Fix | Delete
else bot = Math.min(cm.doc.height, bot + pixels + 50);
[4085] Fix | Delete
updateDisplaySimple(cm, {top: top, bottom: bot});
[4086] Fix | Delete
}
[4087] Fix | Delete
[4088] Fix | Delete
if (wheelSamples < 20) {
[4089] Fix | Delete
if (display.wheelStartX == null) {
[4090] Fix | Delete
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
[4091] Fix | Delete
display.wheelDX = dx; display.wheelDY = dy;
[4092] Fix | Delete
setTimeout(function() {
[4093] Fix | Delete
if (display.wheelStartX == null) return;
[4094] Fix | Delete
var movedX = scroll.scrollLeft - display.wheelStartX;
[4095] Fix | Delete
var movedY = scroll.scrollTop - display.wheelStartY;
[4096] Fix | Delete
var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
[4097] Fix | Delete
(movedX && display.wheelDX && movedX / display.wheelDX);
[4098] Fix | Delete
display.wheelStartX = display.wheelStartY = null;
[4099] Fix | Delete
if (!sample) return;
[4100] Fix | Delete
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
[4101] Fix | Delete
++wheelSamples;
[4102] Fix | Delete
}, 200);
[4103] Fix | Delete
} else {
[4104] Fix | Delete
display.wheelDX += dx; display.wheelDY += dy;
[4105] Fix | Delete
}
[4106] Fix | Delete
}
[4107] Fix | Delete
}
[4108] Fix | Delete
[4109] Fix | Delete
// KEY EVENTS
[4110] Fix | Delete
[4111] Fix | Delete
// Run a handler that was bound to a key.
[4112] Fix | Delete
function doHandleBinding(cm, bound, dropShift) {
[4113] Fix | Delete
if (typeof bound == "string") {
[4114] Fix | Delete
bound = commands[bound];
[4115] Fix | Delete
if (!bound) return false;
[4116] Fix | Delete
}
[4117] Fix | Delete
// Ensure previous input has been read, so that the handler sees a
[4118] Fix | Delete
// consistent view of the document
[4119] Fix | Delete
cm.display.input.ensurePolled();
[4120] Fix | Delete
var prevShift = cm.display.shift, done = false;
[4121] Fix | Delete
try {
[4122] Fix | Delete
if (cm.isReadOnly()) cm.state.suppressEdits = true;
[4123] Fix | Delete
if (dropShift) cm.display.shift = false;
[4124] Fix | Delete
done = bound(cm) != Pass;
[4125] Fix | Delete
} finally {
[4126] Fix | Delete
cm.display.shift = prevShift;
[4127] Fix | Delete
cm.state.suppressEdits = false;
[4128] Fix | Delete
}
[4129] Fix | Delete
return done;
[4130] Fix | Delete
}
[4131] Fix | Delete
[4132] Fix | Delete
function lookupKeyForEditor(cm, name, handle) {
[4133] Fix | Delete
for (var i = 0; i < cm.state.keyMaps.length; i++) {
[4134] Fix | Delete
var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
[4135] Fix | Delete
if (result) return result;
[4136] Fix | Delete
}
[4137] Fix | Delete
return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
[4138] Fix | Delete
|| lookupKey(name, cm.options.keyMap, handle, cm);
[4139] Fix | Delete
}
[4140] Fix | Delete
[4141] Fix | Delete
var stopSeq = new Delayed;
[4142] Fix | Delete
function dispatchKey(cm, name, e, handle) {
[4143] Fix | Delete
var seq = cm.state.keySeq;
[4144] Fix | Delete
if (seq) {
[4145] Fix | Delete
if (isModifierKey(name)) return "handled";
[4146] Fix | Delete
stopSeq.set(50, function() {
[4147] Fix | Delete
if (cm.state.keySeq == seq) {
[4148] Fix | Delete
cm.state.keySeq = null;
[4149] Fix | Delete
cm.display.input.reset();
[4150] Fix | Delete
}
[4151] Fix | Delete
});
[4152] Fix | Delete
name = seq + " " + name;
[4153] Fix | Delete
}
[4154] Fix | Delete
var result = lookupKeyForEditor(cm, name, handle);
[4155] Fix | Delete
[4156] Fix | Delete
if (result == "multi")
[4157] Fix | Delete
cm.state.keySeq = name;
[4158] Fix | Delete
if (result == "handled")
[4159] Fix | Delete
signalLater(cm, "keyHandled", cm, name, e);
[4160] Fix | Delete
[4161] Fix | Delete
if (result == "handled" || result == "multi") {
[4162] Fix | Delete
e_preventDefault(e);
[4163] Fix | Delete
restartBlink(cm);
[4164] Fix | Delete
}
[4165] Fix | Delete
[4166] Fix | Delete
if (seq && !result && /\'$/.test(name)) {
[4167] Fix | Delete
e_preventDefault(e);
[4168] Fix | Delete
return true;
[4169] Fix | Delete
}
[4170] Fix | Delete
return !!result;
[4171] Fix | Delete
}
[4172] Fix | Delete
[4173] Fix | Delete
// Handle a key from the keydown event.
[4174] Fix | Delete
function handleKeyBinding(cm, e) {
[4175] Fix | Delete
var name = keyName(e, true);
[4176] Fix | Delete
if (!name) return false;
[4177] Fix | Delete
[4178] Fix | Delete
if (e.shiftKey && !cm.state.keySeq) {
[4179] Fix | Delete
// First try to resolve full name (including 'Shift-'). Failing
[4180] Fix | Delete
// that, see if there is a cursor-motion command (starting with
[4181] Fix | Delete
// 'go') bound to the keyname without 'Shift-'.
[4182] Fix | Delete
return dispatchKey(cm, "Shift-" + name, e, function(b) {return doHandleBinding(cm, b, true);})
[4183] Fix | Delete
|| dispatchKey(cm, name, e, function(b) {
[4184] Fix | Delete
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
[4185] Fix | Delete
return doHandleBinding(cm, b);
[4186] Fix | Delete
});
[4187] Fix | Delete
} else {
[4188] Fix | Delete
return dispatchKey(cm, name, e, function(b) { return doHandleBinding(cm, b); });
[4189] Fix | Delete
}
[4190] Fix | Delete
}
[4191] Fix | Delete
[4192] Fix | Delete
// Handle a key from the keypress event
[4193] Fix | Delete
function handleCharBinding(cm, e, ch) {
[4194] Fix | Delete
return dispatchKey(cm, "'" + ch + "'", e,
[4195] Fix | Delete
function(b) { return doHandleBinding(cm, b, true); });
[4196] Fix | Delete
}
[4197] Fix | Delete
[4198] Fix | Delete
var lastStoppedKey = null;
[4199] Fix | Delete
function onKeyDown(e) {
[4200] Fix | Delete
var cm = this;
[4201] Fix | Delete
cm.curOp.focus = activeElt();
[4202] Fix | Delete
if (signalDOMEvent(cm, e)) return;
[4203] Fix | Delete
// IE does strange things with escape.
[4204] Fix | Delete
if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false;
[4205] Fix | Delete
var code = e.keyCode;
[4206] Fix | Delete
cm.display.shift = code == 16 || e.shiftKey;
[4207] Fix | Delete
var handled = handleKeyBinding(cm, e);
[4208] Fix | Delete
if (presto) {
[4209] Fix | Delete
lastStoppedKey = handled ? code : null;
[4210] Fix | Delete
// Opera has no cut event... we try to at least catch the key combo
[4211] Fix | Delete
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
[4212] Fix | Delete
cm.replaceSelection("", null, "cut");
[4213] Fix | Delete
}
[4214] Fix | Delete
[4215] Fix | Delete
// Turn mouse into crosshair when Alt is held on Mac.
[4216] Fix | Delete
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
[4217] Fix | Delete
showCrossHair(cm);
[4218] Fix | Delete
}
[4219] Fix | Delete
[4220] Fix | Delete
function showCrossHair(cm) {
[4221] Fix | Delete
var lineDiv = cm.display.lineDiv;
[4222] Fix | Delete
addClass(lineDiv, "CodeMirror-crosshair");
[4223] Fix | Delete
[4224] Fix | Delete
function up(e) {
[4225] Fix | Delete
if (e.keyCode == 18 || !e.altKey) {
[4226] Fix | Delete
rmClass(lineDiv, "CodeMirror-crosshair");
[4227] Fix | Delete
off(document, "keyup", up);
[4228] Fix | Delete
off(document, "mouseover", up);
[4229] Fix | Delete
}
[4230] Fix | Delete
}
[4231] Fix | Delete
on(document, "keyup", up);
[4232] Fix | Delete
on(document, "mouseover", up);
[4233] Fix | Delete
}
[4234] Fix | Delete
[4235] Fix | Delete
function onKeyUp(e) {
[4236] Fix | Delete
if (e.keyCode == 16) this.doc.sel.shift = false;
[4237] Fix | Delete
signalDOMEvent(this, e);
[4238] Fix | Delete
}
[4239] Fix | Delete
[4240] Fix | Delete
function onKeyPress(e) {
[4241] Fix | Delete
var cm = this;
[4242] Fix | Delete
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return;
[4243] Fix | Delete
var keyCode = e.keyCode, charCode = e.charCode;
[4244] Fix | Delete
if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
[4245] Fix | Delete
if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) return;
[4246] Fix | Delete
var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
[4247] Fix | Delete
if (handleCharBinding(cm, e, ch)) return;
[4248] Fix | Delete
cm.display.input.onKeyPress(e);
[4249] Fix | Delete
}
[4250] Fix | Delete
[4251] Fix | Delete
// FOCUS/BLUR EVENTS
[4252] Fix | Delete
[4253] Fix | Delete
function delayBlurEvent(cm) {
[4254] Fix | Delete
cm.state.delayingBlurEvent = true;
[4255] Fix | Delete
setTimeout(function() {
[4256] Fix | Delete
if (cm.state.delayingBlurEvent) {
[4257] Fix | Delete
cm.state.delayingBlurEvent = false;
[4258] Fix | Delete
onBlur(cm);
[4259] Fix | Delete
}
[4260] Fix | Delete
}, 100);
[4261] Fix | Delete
}
[4262] Fix | Delete
[4263] Fix | Delete
function onFocus(cm) {
[4264] Fix | Delete
if (cm.state.delayingBlurEvent) cm.state.delayingBlurEvent = false;
[4265] Fix | Delete
[4266] Fix | Delete
if (cm.options.readOnly == "nocursor") return;
[4267] Fix | Delete
if (!cm.state.focused) {
[4268] Fix | Delete
signal(cm, "focus", cm);
[4269] Fix | Delete
cm.state.focused = true;
[4270] Fix | Delete
addClass(cm.display.wrapper, "CodeMirror-focused");
[4271] Fix | Delete
// This test prevents this from firing when a context
[4272] Fix | Delete
// menu is closed (since the input reset would kill the
[4273] Fix | Delete
// select-all detection hack)
[4274] Fix | Delete
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
[4275] Fix | Delete
cm.display.input.reset();
[4276] Fix | Delete
if (webkit) setTimeout(function() { cm.display.input.reset(true); }, 20); // Issue #1730
[4277] Fix | Delete
}
[4278] Fix | Delete
cm.display.input.receivedFocus();
[4279] Fix | Delete
}
[4280] Fix | Delete
restartBlink(cm);
[4281] Fix | Delete
}
[4282] Fix | Delete
function onBlur(cm) {
[4283] Fix | Delete
if (cm.state.delayingBlurEvent) return;
[4284] Fix | Delete
[4285] Fix | Delete
if (cm.state.focused) {
[4286] Fix | Delete
signal(cm, "blur", cm);
[4287] Fix | Delete
cm.state.focused = false;
[4288] Fix | Delete
rmClass(cm.display.wrapper, "CodeMirror-focused");
[4289] Fix | Delete
}
[4290] Fix | Delete
clearInterval(cm.display.blinker);
[4291] Fix | Delete
setTimeout(function() {if (!cm.state.focused) cm.display.shift = false;}, 150);
[4292] Fix | Delete
}
[4293] Fix | Delete
[4294] Fix | Delete
// CONTEXT MENU HANDLING
[4295] Fix | Delete
[4296] Fix | Delete
// To make the context menu work, we need to briefly unhide the
[4297] Fix | Delete
// textarea (making it as unobtrusive as possible) to let the
[4298] Fix | Delete
// right-click take effect on it.
[4299] Fix | Delete
function onContextMenu(cm, e) {
[4300] Fix | Delete
if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) return;
[4301] Fix | Delete
if (signalDOMEvent(cm, e, "contextmenu")) return;
[4302] Fix | Delete
cm.display.input.onContextMenu(e);
[4303] Fix | Delete
}
[4304] Fix | Delete
[4305] Fix | Delete
function contextMenuInGutter(cm, e) {
[4306] Fix | Delete
if (!hasHandler(cm, "gutterContextMenu")) return false;
[4307] Fix | Delete
return gutterEvent(cm, e, "gutterContextMenu", false);
[4308] Fix | Delete
}
[4309] Fix | Delete
[4310] Fix | Delete
// UPDATING
[4311] Fix | Delete
[4312] Fix | Delete
// Compute the position of the end of a change (its 'to' property
[4313] Fix | Delete
// refers to the pre-change end).
[4314] Fix | Delete
var changeEnd = CodeMirror.changeEnd = function(change) {
[4315] Fix | Delete
if (!change.text) return change.to;
[4316] Fix | Delete
return Pos(change.from.line + change.text.length - 1,
[4317] Fix | Delete
lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
[4318] Fix | Delete
};
[4319] Fix | Delete
[4320] Fix | Delete
// Adjust a position to refer to the post-change position of the
[4321] Fix | Delete
// same text, or the end of the change if the change covers it.
[4322] Fix | Delete
function adjustForChange(pos, change) {
[4323] Fix | Delete
if (cmp(pos, change.from) < 0) return pos;
[4324] Fix | Delete
if (cmp(pos, change.to) <= 0) return changeEnd(change);
[4325] Fix | Delete
[4326] Fix | Delete
var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
[4327] Fix | Delete
if (pos.line == change.to.line) ch += changeEnd(change).ch - change.to.ch;
[4328] Fix | Delete
return Pos(line, ch);
[4329] Fix | Delete
}
[4330] Fix | Delete
[4331] Fix | Delete
function computeSelAfterChange(doc, change) {
[4332] Fix | Delete
var out = [];
[4333] Fix | Delete
for (var i = 0; i < doc.sel.ranges.length; i++) {
[4334] Fix | Delete
var range = doc.sel.ranges[i];
[4335] Fix | Delete
out.push(new Range(adjustForChange(range.anchor, change),
[4336] Fix | Delete
adjustForChange(range.head, change)));
[4337] Fix | Delete
}
[4338] Fix | Delete
return normalizeSelection(out, doc.sel.primIndex);
[4339] Fix | Delete
}
[4340] Fix | Delete
[4341] Fix | Delete
function offsetPos(pos, old, nw) {
[4342] Fix | Delete
if (pos.line == old.line)
[4343] Fix | Delete
return Pos(nw.line, pos.ch - old.ch + nw.ch);
[4344] Fix | Delete
else
[4345] Fix | Delete
return Pos(nw.line + (pos.line - old.line), pos.ch);
[4346] Fix | Delete
}
[4347] Fix | Delete
[4348] Fix | Delete
// Used by replaceSelections to allow moving the selection to the
[4349] Fix | Delete
// start or around the replaced test. Hint may be "start" or "around".
[4350] Fix | Delete
function computeReplacedSel(doc, changes, hint) {
[4351] Fix | Delete
var out = [];
[4352] Fix | Delete
var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
[4353] Fix | Delete
for (var i = 0; i < changes.length; i++) {
[4354] Fix | Delete
var change = changes[i];
[4355] Fix | Delete
var from = offsetPos(change.from, oldPrev, newPrev);
[4356] Fix | Delete
var to = offsetPos(changeEnd(change), oldPrev, newPrev);
[4357] Fix | Delete
oldPrev = change.to;
[4358] Fix | Delete
newPrev = to;
[4359] Fix | Delete
if (hint == "around") {
[4360] Fix | Delete
var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
[4361] Fix | Delete
out[i] = new Range(inv ? to : from, inv ? from : to);
[4362] Fix | Delete
} else {
[4363] Fix | Delete
out[i] = new Range(from, from);
[4364] Fix | Delete
}
[4365] Fix | Delete
}
[4366] Fix | Delete
return new Selection(out, doc.sel.primIndex);
[4367] Fix | Delete
}
[4368] Fix | Delete
[4369] Fix | Delete
// Allow "beforeChange" event handlers to influence a change
[4370] Fix | Delete
function filterChange(doc, change, update) {
[4371] Fix | Delete
var obj = {
[4372] Fix | Delete
canceled: false,
[4373] Fix | Delete
from: change.from,
[4374] Fix | Delete
to: change.to,
[4375] Fix | Delete
text: change.text,
[4376] Fix | Delete
origin: change.origin,
[4377] Fix | Delete
cancel: function() { this.canceled = true; }
[4378] Fix | Delete
};
[4379] Fix | Delete
if (update) obj.update = function(from, to, text, origin) {
[4380] Fix | Delete
if (from) this.from = clipPos(doc, from);
[4381] Fix | Delete
if (to) this.to = clipPos(doc, to);
[4382] Fix | Delete
if (text) this.text = text;
[4383] Fix | Delete
if (origin !== undefined) this.origin = origin;
[4384] Fix | Delete
};
[4385] Fix | Delete
signal(doc, "beforeChange", doc, obj);
[4386] Fix | Delete
if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
[4387] Fix | Delete
[4388] Fix | Delete
if (obj.canceled) return null;
[4389] Fix | Delete
return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
[4390] Fix | Delete
}
[4391] Fix | Delete
[4392] Fix | Delete
// Apply a change to a document, and add it to the document's
[4393] Fix | Delete
// history, and propagating it to all linked documents.
[4394] Fix | Delete
function makeChange(doc, change, ignoreReadOnly) {
[4395] Fix | Delete
if (doc.cm) {
[4396] Fix | Delete
if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
[4397] Fix | Delete
if (doc.cm.state.suppressEdits) return;
[4398] Fix | Delete
}
[4399] Fix | Delete
[4400] Fix | Delete
if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
[4401] Fix | Delete
change = filterChange(doc, change, true);
[4402] Fix | Delete
if (!change) return;
[4403] Fix | Delete
}
[4404] Fix | Delete
[4405] Fix | Delete
// Possibly split or suppress the update based on the presence
[4406] Fix | Delete
// of read-only spans in its range.
[4407] Fix | Delete
var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
[4408] Fix | Delete
if (split) {
[4409] Fix | Delete
for (var i = split.length - 1; i >= 0; --i)
[4410] Fix | Delete
makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text});
[4411] Fix | Delete
} else {
[4412] Fix | Delete
makeChangeInner(doc, change);
[4413] Fix | Delete
}
[4414] Fix | Delete
}
[4415] Fix | Delete
[4416] Fix | Delete
function makeChangeInner(doc, change) {
[4417] Fix | Delete
if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) return;
[4418] Fix | Delete
var selAfter = computeSelAfterChange(doc, change);
[4419] Fix | Delete
addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
[4420] Fix | Delete
[4421] Fix | Delete
makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
[4422] Fix | Delete
var rebased = [];
[4423] Fix | Delete
[4424] Fix | Delete
linkedDocs(doc, function(doc, sharedHist) {
[4425] Fix | Delete
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
[4426] Fix | Delete
rebaseHist(doc.history, change);
[4427] Fix | Delete
rebased.push(doc.history);
[4428] Fix | Delete
}
[4429] Fix | Delete
makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
[4430] Fix | Delete
});
[4431] Fix | Delete
}
[4432] Fix | Delete
[4433] Fix | Delete
// Revert a change stored in a document's history.
[4434] Fix | Delete
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
[4435] Fix | Delete
if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) return;
[4436] Fix | Delete
[4437] Fix | Delete
var hist = doc.history, event, selAfter = doc.sel;
[4438] Fix | Delete
var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
[4439] Fix | Delete
[4440] Fix | Delete
// Verify that there is a useable event (so that ctrl-z won't
[4441] Fix | Delete
// needlessly clear selection events)
[4442] Fix | Delete
for (var i = 0; i < source.length; i++) {
[4443] Fix | Delete
event = source[i];
[4444] Fix | Delete
if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
[4445] Fix | Delete
break;
[4446] Fix | Delete
}
[4447] Fix | Delete
if (i == source.length) return;
[4448] Fix | Delete
hist.lastOrigin = hist.lastSelOrigin = null;
[4449] Fix | Delete
[4450] Fix | Delete
for (;;) {
[4451] Fix | Delete
event = source.pop();
[4452] Fix | Delete
if (event.ranges) {
[4453] Fix | Delete
pushSelectionToHistory(event, dest);
[4454] Fix | Delete
if (allowSelectionOnly && !event.equals(doc.sel)) {
[4455] Fix | Delete
setSelection(doc, event, {clearRedo: false});
[4456] Fix | Delete
return;
[4457] Fix | Delete
}
[4458] Fix | Delete
selAfter = event;
[4459] Fix | Delete
}
[4460] Fix | Delete
else break;
[4461] Fix | Delete
}
[4462] Fix | Delete
[4463] Fix | Delete
// Build up a reverse change object to add to the opposite history
[4464] Fix | Delete
// stack (redo when undoing, and vice versa).
[4465] Fix | Delete
var antiChanges = [];
[4466] Fix | Delete
pushSelectionToHistory(selAfter, dest);
[4467] Fix | Delete
dest.push({changes: antiChanges, generation: hist.generation});
[4468] Fix | Delete
hist.generation = event.generation || ++hist.maxGeneration;
[4469] Fix | Delete
[4470] Fix | Delete
var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
[4471] Fix | Delete
[4472] Fix | Delete
for (var i = event.changes.length - 1; i >= 0; --i) {
[4473] Fix | Delete
var change = event.changes[i];
[4474] Fix | Delete
change.origin = type;
[4475] Fix | Delete
if (filter && !filterChange(doc, change, false)) {
[4476] Fix | Delete
source.length = 0;
[4477] Fix | Delete
return;
[4478] Fix | Delete
}
[4479] Fix | Delete
[4480] Fix | Delete
antiChanges.push(historyChangeFromChange(doc, change));
[4481] Fix | Delete
[4482] Fix | Delete
var after = i ? computeSelAfterChange(doc, change) : lst(source);
[4483] Fix | Delete
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
[4484] Fix | Delete
if (!i && doc.cm) doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)});
[4485] Fix | Delete
var rebased = [];
[4486] Fix | Delete
[4487] Fix | Delete
// Propagate to the linked documents
[4488] Fix | Delete
linkedDocs(doc, function(doc, sharedHist) {
[4489] Fix | Delete
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
[4490] Fix | Delete
rebaseHist(doc.history, change);
[4491] Fix | Delete
rebased.push(doc.history);
[4492] Fix | Delete
}
[4493] Fix | Delete
makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
[4494] Fix | Delete
});
[4495] Fix | Delete
}
[4496] Fix | Delete
}
[4497] Fix | Delete
[4498] Fix | Delete
// Sub-views need their line numbers shifted when text is added
[4499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function