mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
Remove legacy mozilla specific code from ace inner
This commit is contained in:
parent
d30daccb10
commit
cba001341f
3 changed files with 2 additions and 349 deletions
|
@ -33,19 +33,6 @@ function object(o)
|
||||||
f.prototype = o;
|
f.prototype = o;
|
||||||
return new f();
|
return new f();
|
||||||
}
|
}
|
||||||
var userAgent = (((function () {return this;})().navigator || {}).userAgent || 'node-js').toLowerCase();
|
|
||||||
|
|
||||||
// Figure out what browser is being used (stolen from jquery 1.2.1)
|
|
||||||
var browser = {
|
|
||||||
version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
|
|
||||||
safari: /webkit/.test(userAgent),
|
|
||||||
opera: /opera/.test(userAgent),
|
|
||||||
msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
|
|
||||||
mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent),
|
|
||||||
windows: /windows/.test(userAgent),
|
|
||||||
mobile: /mobile/.test(userAgent) || /android/.test(userAgent)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
function getAssoc(obj, name)
|
function getAssoc(obj, name)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +84,6 @@ var noop = function(){};
|
||||||
|
|
||||||
exports.isNodeText = isNodeText;
|
exports.isNodeText = isNodeText;
|
||||||
exports.object = object;
|
exports.object = object;
|
||||||
exports.browser = browser;
|
|
||||||
exports.getAssoc = getAssoc;
|
exports.getAssoc = getAssoc;
|
||||||
exports.setAssoc = setAssoc;
|
exports.setAssoc = setAssoc;
|
||||||
exports.binarySearch = binarySearch;
|
exports.binarySearch = binarySearch;
|
||||||
|
|
|
@ -28,7 +28,7 @@ $ = jQuery = require('./rjquery').$;
|
||||||
_ = require("./underscore");
|
_ = require("./underscore");
|
||||||
|
|
||||||
var isNodeText = Ace2Common.isNodeText,
|
var isNodeText = Ace2Common.isNodeText,
|
||||||
browser = Ace2Common.browser,
|
browser = $.browser,
|
||||||
getAssoc = Ace2Common.getAssoc,
|
getAssoc = Ace2Common.getAssoc,
|
||||||
setAssoc = Ace2Common.setAssoc,
|
setAssoc = Ace2Common.setAssoc,
|
||||||
isTextNode = Ace2Common.isTextNode,
|
isTextNode = Ace2Common.isTextNode,
|
||||||
|
@ -2817,7 +2817,6 @@ function Ace2Inner(){
|
||||||
rep.selStart = selectStart;
|
rep.selStart = selectStart;
|
||||||
rep.selEnd = selectEnd;
|
rep.selEnd = selectEnd;
|
||||||
rep.selFocusAtStart = newSelFocusAtStart;
|
rep.selFocusAtStart = newSelFocusAtStart;
|
||||||
if (mozillaFakeArrows) mozillaFakeArrows.notifySelectionChanged();
|
|
||||||
currentCallStack.repChanged = true;
|
currentCallStack.repChanged = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3690,12 +3689,6 @@ function Ace2Inner(){
|
||||||
doDeleteKey();
|
doDeleteKey();
|
||||||
specialHandled = true;
|
specialHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mozillaFakeArrows && mozillaFakeArrows.handleKeyEvent(evt))
|
|
||||||
{
|
|
||||||
evt.preventDefault();
|
|
||||||
specialHandled = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == "keydown")
|
if (type == "keydown")
|
||||||
|
@ -5037,331 +5030,6 @@ function Ace2Inner(){
|
||||||
}
|
}
|
||||||
editorInfo.ace_doInsertUnorderedList = doInsertUnorderedList;
|
editorInfo.ace_doInsertUnorderedList = doInsertUnorderedList;
|
||||||
editorInfo.ace_doInsertOrderedList = doInsertOrderedList;
|
editorInfo.ace_doInsertOrderedList = doInsertOrderedList;
|
||||||
|
|
||||||
var mozillaFakeArrows = (browser.mozilla && (function()
|
|
||||||
{
|
|
||||||
// In Firefox 2, arrow keys are unstable while DOM-manipulating
|
|
||||||
// operations are going on. Specifically, if an operation
|
|
||||||
// (computation that ties up the event queue) is going on (in the
|
|
||||||
// call-stack of some event, like a timeout) that at some point
|
|
||||||
// mutates nodes involved in the selection, then the arrow
|
|
||||||
// keypress may (randomly) move the caret to the beginning or end
|
|
||||||
// of the document. If the operation also mutates the selection
|
|
||||||
// range, the old selection or the new selection may be used, or
|
|
||||||
// neither.
|
|
||||||
// As long as the arrow is pressed during the busy operation, it
|
|
||||||
// doesn't seem to matter that the keydown and keypress events
|
|
||||||
// aren't generated until afterwards, or that the arrow movement
|
|
||||||
// can still be stopped (meaning it hasn't been performed yet);
|
|
||||||
// Firefox must be preserving some old information about the
|
|
||||||
// selection or the DOM from when the key was initially pressed.
|
|
||||||
// However, it also doesn't seem to matter when the key was
|
|
||||||
// actually pressed relative to the time of the mutation within
|
|
||||||
// the prolonged operation. Also, even in very controlled tests
|
|
||||||
// (like a mutation followed by a long period of busyWaiting), the
|
|
||||||
// problem shows up often but not every time, with no discernable
|
|
||||||
// pattern. Who knows, it could have something to do with the
|
|
||||||
// caret-blinking timer, or DOM changes not being applied
|
|
||||||
// immediately.
|
|
||||||
// This problem, mercifully, does not show up at all in IE or
|
|
||||||
// Safari. My solution is to have my own, full-featured arrow-key
|
|
||||||
// implementation for Firefox.
|
|
||||||
// Note that the problem addressed here is potentially very subtle,
|
|
||||||
// especially if the operation is quick and is timed to usually happen
|
|
||||||
// when the user is idle.
|
|
||||||
// features:
|
|
||||||
// - 'up' and 'down' arrows preserve column when passing through shorter lines
|
|
||||||
// - shift-arrows extend the "focus" point, which may be start or end of range
|
|
||||||
// - the focus point is kept horizontally and vertically scrolled into view
|
|
||||||
// - arrows without shift cause caret to move to beginning or end of selection (left,right)
|
|
||||||
// or move focus point up or down a line (up,down)
|
|
||||||
// - command-(left,right,up,down) on Mac acts like (line-start, line-end, doc-start, doc-end)
|
|
||||||
// - takes wrapping into account when doesWrap is true, i.e. up-arrow and down-arrow move
|
|
||||||
// between the virtual lines within a wrapped line; this was difficult, and unfortunately
|
|
||||||
// requires mutating the DOM to get the necessary information
|
|
||||||
var savedFocusColumn = 0; // a value of 0 has no effect
|
|
||||||
var updatingSelectionNow = false;
|
|
||||||
|
|
||||||
function getVirtualLineView(lineNum)
|
|
||||||
{
|
|
||||||
var lineNode = rep.lines.atIndex(lineNum).lineNode;
|
|
||||||
while (lineNode.firstChild && isBlockElement(lineNode.firstChild))
|
|
||||||
{
|
|
||||||
lineNode = lineNode.firstChild;
|
|
||||||
}
|
|
||||||
return makeVirtualLineView(lineNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
function markerlessLineAndChar(line, chr)
|
|
||||||
{
|
|
||||||
return [line, chr - rep.lines.atIndex(line).lineMarker];
|
|
||||||
}
|
|
||||||
|
|
||||||
function markerfulLineAndChar(line, chr)
|
|
||||||
{
|
|
||||||
return [line, chr + rep.lines.atIndex(line).lineMarker];
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
notifySelectionChanged: function()
|
|
||||||
{
|
|
||||||
if (!updatingSelectionNow)
|
|
||||||
{
|
|
||||||
savedFocusColumn = 0;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handleKeyEvent: function(evt)
|
|
||||||
{
|
|
||||||
// returns "true" if handled
|
|
||||||
if (evt.type != "keypress") return false;
|
|
||||||
var keyCode = evt.keyCode;
|
|
||||||
if (keyCode < 37 || keyCode > 40) return false;
|
|
||||||
incorporateUserChanges();
|
|
||||||
|
|
||||||
if (!(rep.selStart && rep.selEnd)) return true;
|
|
||||||
|
|
||||||
// {byWord,toEnd,normal}
|
|
||||||
var moveMode = (evt.altKey ? "byWord" : (evt.ctrlKey ? "byWord" : (evt.metaKey ? "toEnd" : "normal")));
|
|
||||||
|
|
||||||
var anchorCaret = markerlessLineAndChar(rep.selStart[0], rep.selStart[1]);
|
|
||||||
var focusCaret = markerlessLineAndChar(rep.selEnd[0], rep.selEnd[1]);
|
|
||||||
var wasCaret = isCaret();
|
|
||||||
if (rep.selFocusAtStart)
|
|
||||||
{
|
|
||||||
var tmp = anchorCaret;
|
|
||||||
anchorCaret = focusCaret;
|
|
||||||
focusCaret = tmp;
|
|
||||||
}
|
|
||||||
var K_UP = 38,
|
|
||||||
K_DOWN = 40,
|
|
||||||
K_LEFT = 37,
|
|
||||||
K_RIGHT = 39;
|
|
||||||
var dontMove = false;
|
|
||||||
if (wasCaret && !evt.shiftKey)
|
|
||||||
{
|
|
||||||
// collapse, will mutate both together
|
|
||||||
anchorCaret = focusCaret;
|
|
||||||
}
|
|
||||||
else if ((!wasCaret) && (!evt.shiftKey))
|
|
||||||
{
|
|
||||||
if (keyCode == K_LEFT)
|
|
||||||
{
|
|
||||||
// place caret at beginning
|
|
||||||
if (rep.selFocusAtStart) anchorCaret = focusCaret;
|
|
||||||
else focusCaret = anchorCaret;
|
|
||||||
if (moveMode == "normal") dontMove = true;
|
|
||||||
}
|
|
||||||
else if (keyCode == K_RIGHT)
|
|
||||||
{
|
|
||||||
// place caret at end
|
|
||||||
if (rep.selFocusAtStart) focusCaret = anchorCaret;
|
|
||||||
else anchorCaret = focusCaret;
|
|
||||||
if (moveMode == "normal") dontMove = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// collapse, will mutate both together
|
|
||||||
anchorCaret = focusCaret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!dontMove)
|
|
||||||
{
|
|
||||||
function lineLength(i)
|
|
||||||
{
|
|
||||||
var entry = rep.lines.atIndex(i);
|
|
||||||
return entry.text.length - entry.lineMarker;
|
|
||||||
}
|
|
||||||
|
|
||||||
function lineText(i)
|
|
||||||
{
|
|
||||||
var entry = rep.lines.atIndex(i);
|
|
||||||
return entry.text.substring(entry.lineMarker);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyCode == K_UP || keyCode == K_DOWN)
|
|
||||||
{
|
|
||||||
var up = (keyCode == K_UP);
|
|
||||||
var canChangeLines = ((up && focusCaret[0]) || ((!up) && focusCaret[0] < rep.lines.length() - 1));
|
|
||||||
var virtualLineView, virtualLineSpot, canChangeVirtualLines = false;
|
|
||||||
if (doesWrap)
|
|
||||||
{
|
|
||||||
virtualLineView = getVirtualLineView(focusCaret[0]);
|
|
||||||
virtualLineSpot = virtualLineView.getVLineAndOffsetForChar(focusCaret[1]);
|
|
||||||
canChangeVirtualLines = ((up && virtualLineSpot.vline > 0) || ((!up) && virtualLineSpot.vline < (
|
|
||||||
virtualLineView.getNumVirtualLines() - 1)));
|
|
||||||
}
|
|
||||||
var newColByVirtualLineChange;
|
|
||||||
if (moveMode == "toEnd")
|
|
||||||
{
|
|
||||||
if (up)
|
|
||||||
{
|
|
||||||
focusCaret[0] = 0;
|
|
||||||
focusCaret[1] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
focusCaret[0] = rep.lines.length() - 1;
|
|
||||||
focusCaret[1] = lineLength(focusCaret[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (moveMode == "byWord")
|
|
||||||
{
|
|
||||||
// move by "paragraph", a feature that Firefox lacks but IE and Safari both have
|
|
||||||
if (up)
|
|
||||||
{
|
|
||||||
if (focusCaret[1] === 0 && canChangeLines)
|
|
||||||
{
|
|
||||||
focusCaret[0]--;
|
|
||||||
focusCaret[1] = 0;
|
|
||||||
}
|
|
||||||
else focusCaret[1] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var lineLen = lineLength(focusCaret[0]);
|
|
||||||
if (browser.windows)
|
|
||||||
{
|
|
||||||
if (canChangeLines)
|
|
||||||
{
|
|
||||||
focusCaret[0]++;
|
|
||||||
focusCaret[1] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
focusCaret[1] = lineLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (focusCaret[1] == lineLen && canChangeLines)
|
|
||||||
{
|
|
||||||
focusCaret[0]++;
|
|
||||||
focusCaret[1] = lineLength(focusCaret[0]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
focusCaret[1] = lineLen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
savedFocusColumn = 0;
|
|
||||||
}
|
|
||||||
else if (canChangeVirtualLines)
|
|
||||||
{
|
|
||||||
var vline = virtualLineSpot.vline;
|
|
||||||
var offset = virtualLineSpot.offset;
|
|
||||||
if (up) vline--;
|
|
||||||
else vline++;
|
|
||||||
if (savedFocusColumn > offset) offset = savedFocusColumn;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
savedFocusColumn = offset;
|
|
||||||
}
|
|
||||||
var newSpot = virtualLineView.getCharForVLineAndOffset(vline, offset);
|
|
||||||
focusCaret[1] = newSpot.lineChar;
|
|
||||||
}
|
|
||||||
else if (canChangeLines)
|
|
||||||
{
|
|
||||||
if (up) focusCaret[0]--;
|
|
||||||
else focusCaret[0]++;
|
|
||||||
var offset = focusCaret[1];
|
|
||||||
if (doesWrap)
|
|
||||||
{
|
|
||||||
offset = virtualLineSpot.offset;
|
|
||||||
}
|
|
||||||
if (savedFocusColumn > offset) offset = savedFocusColumn;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
savedFocusColumn = offset;
|
|
||||||
}
|
|
||||||
if (doesWrap)
|
|
||||||
{
|
|
||||||
var newLineView = getVirtualLineView(focusCaret[0]);
|
|
||||||
var vline = (up ? newLineView.getNumVirtualLines() - 1 : 0);
|
|
||||||
var newSpot = newLineView.getCharForVLineAndOffset(vline, offset);
|
|
||||||
focusCaret[1] = newSpot.lineChar;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var lineLen = lineLength(focusCaret[0]);
|
|
||||||
if (offset > lineLen) offset = lineLen;
|
|
||||||
focusCaret[1] = offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (up) focusCaret[1] = 0;
|
|
||||||
else focusCaret[1] = lineLength(focusCaret[0]);
|
|
||||||
savedFocusColumn = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (keyCode == K_LEFT || keyCode == K_RIGHT)
|
|
||||||
{
|
|
||||||
var left = (keyCode == K_LEFT);
|
|
||||||
if (left)
|
|
||||||
{
|
|
||||||
if (moveMode == "toEnd") focusCaret[1] = 0;
|
|
||||||
else if (focusCaret[1] > 0)
|
|
||||||
{
|
|
||||||
if (moveMode == "byWord")
|
|
||||||
{
|
|
||||||
focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
focusCaret[1]--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (focusCaret[0] > 0)
|
|
||||||
{
|
|
||||||
focusCaret[0]--;
|
|
||||||
focusCaret[1] = lineLength(focusCaret[0]);
|
|
||||||
if (moveMode == "byWord")
|
|
||||||
{
|
|
||||||
focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var lineLen = lineLength(focusCaret[0]);
|
|
||||||
if (moveMode == "toEnd") focusCaret[1] = lineLen;
|
|
||||||
else if (focusCaret[1] < lineLen)
|
|
||||||
{
|
|
||||||
if (moveMode == "byWord")
|
|
||||||
{
|
|
||||||
focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
focusCaret[1]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (focusCaret[0] < rep.lines.length() - 1)
|
|
||||||
{
|
|
||||||
focusCaret[0]++;
|
|
||||||
focusCaret[1] = 0;
|
|
||||||
if (moveMode == "byWord")
|
|
||||||
{
|
|
||||||
focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
savedFocusColumn = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var newSelFocusAtStart = ((focusCaret[0] < anchorCaret[0]) || (focusCaret[0] == anchorCaret[0] && focusCaret[1] < anchorCaret[1]));
|
|
||||||
var newSelStart = (newSelFocusAtStart ? focusCaret : anchorCaret);
|
|
||||||
var newSelEnd = (newSelFocusAtStart ? anchorCaret : focusCaret);
|
|
||||||
updatingSelectionNow = true;
|
|
||||||
performSelectionChange(markerfulLineAndChar(newSelStart[0], newSelStart[1]), markerfulLineAndChar(newSelEnd[0], newSelEnd[1]), newSelFocusAtStart);
|
|
||||||
updatingSelectionNow = false;
|
|
||||||
currentCallStack.userChangedSelection = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})());
|
|
||||||
|
|
||||||
var lineNumbersShown;
|
var lineNumbersShown;
|
||||||
var sideDivInner;
|
var sideDivInner;
|
||||||
|
|
|
@ -30,8 +30,7 @@ var Security = require('./security');
|
||||||
var hooks = require('./pluginfw/hooks');
|
var hooks = require('./pluginfw/hooks');
|
||||||
var _ = require('./underscore');
|
var _ = require('./underscore');
|
||||||
var lineAttributeMarker = require('./linestylefilter').lineAttributeMarker;
|
var lineAttributeMarker = require('./linestylefilter').lineAttributeMarker;
|
||||||
var Ace2Common = require('./ace2_common');
|
var noop = function(){};
|
||||||
var noop = Ace2Common.noop;
|
|
||||||
|
|
||||||
|
|
||||||
var domline = {};
|
var domline = {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue