ace2_inner: Formatting improvements

This commit is contained in:
Richard Hansen 2021-08-15 02:44:43 -04:00
parent 0ca5a3459f
commit e581ee01f2

View file

@ -528,9 +528,7 @@ function Ace2Inner(editorInfo, cssManagers) {
performDocumentApplyChangeset(changeset); performDocumentApplyChangeset(changeset);
performSelectionChange( performSelectionChange(
[0, rep.lines.atIndex(0).lineMarker], [0, rep.lines.atIndex(0).lineMarker], [0, rep.lines.atIndex(0).lineMarker]);
[0, rep.lines.atIndex(0).lineMarker]
);
idleWorkTimer.atMost(100); idleWorkTimer.atMost(100);
@ -1129,10 +1127,7 @@ function Ace2Inner(editorInfo, cssManagers) {
splicesToDo.push([a + netNumLinesChangeSoFar, b - a, entries, lineAttribs, spliceHints]); splicesToDo.push([a + netNumLinesChangeSoFar, b - a, entries, lineAttribs, spliceHints]);
netNumLinesChangeSoFar += (lines.length - (b - a)); netNumLinesChangeSoFar += (lines.length - (b - a));
} else if (b > a) { } else if (b > a) {
splicesToDo.push([a + netNumLinesChangeSoFar, splicesToDo.push([a + netNumLinesChangeSoFar, b - a, [], []]);
b - a,
[],
[]]);
} }
i++; i++;
} }
@ -1271,12 +1266,8 @@ function Ace2Inner(editorInfo, cssManagers) {
}); });
}; };
const isCaret = () => ( const isCaret = () => (rep.selStart && rep.selEnd &&
rep.selStart && rep.selStart[0] === rep.selEnd[0] && rep.selStart[1] === rep.selEnd[1]);
rep.selEnd &&
rep.selStart[0] === rep.selEnd[0] &&
rep.selStart[1] === rep.selEnd[1]
);
editorInfo.ace_isCaret = isCaret; editorInfo.ace_isCaret = isCaret;
// prereq: isCaret() // prereq: isCaret()
@ -1473,12 +1464,9 @@ function Ace2Inner(editorInfo, cssManagers) {
if (requiredSelectionSetting) { if (requiredSelectionSetting) {
performSelectionChange( performSelectionChange(
lineAndColumnFromChar( lineAndColumnFromChar(requiredSelectionSetting[0]),
requiredSelectionSetting[0]
),
lineAndColumnFromChar(requiredSelectionSetting[1]), lineAndColumnFromChar(requiredSelectionSetting[1]),
requiredSelectionSetting[2] requiredSelectionSetting[2]);
);
} }
}; };
@ -1553,8 +1541,8 @@ function Ace2Inner(editorInfo, cssManagers) {
newText = newText.substring(0, newText.length - 1); newText = newText.substring(0, newText.length - 1);
} }
} }
performDocumentReplaceRange(lineAndColumnFromChar(startChar), performDocumentReplaceRange(
lineAndColumnFromChar(endChar), newText); lineAndColumnFromChar(startChar), lineAndColumnFromChar(endChar), newText);
}; };
const performDocumentApplyAttributesToCharRange = (start, end, attribs) => { const performDocumentApplyAttributesToCharRange = (start, end, attribs) => {
@ -1697,10 +1685,7 @@ function Ace2Inner(editorInfo, cssManagers) {
const attributeValue = selectionAllHasIt ? '' : 'true'; const attributeValue = selectionAllHasIt ? '' : 'true';
documentAttributeManager.setAttributesOnRange( documentAttributeManager.setAttributesOnRange(
rep.selStart, rep.selStart, rep.selEnd, [[attributeName, attributeValue]]);
rep.selEnd,
[[attributeName, attributeValue]]
);
if (attribIsFormattingStyle(attributeName)) { if (attribIsFormattingStyle(attributeName)) {
updateStyleButtonState(attributeName, !selectionAllHasIt); // italic, bold, ... updateStyleButtonState(attributeName, !selectionAllHasIt); // italic, bold, ...
} }
@ -1750,9 +1735,8 @@ function Ace2Inner(editorInfo, cssManagers) {
const oldText = rep.alltext.substring(startOldChar, endOldChar); const oldText = rep.alltext.substring(startOldChar, endOldChar);
const oldAttribs = rep.alines.slice(startLine, startLine + deleteCount).join(''); const oldAttribs = rep.alines.slice(startLine, startLine + deleteCount).join('');
const newAttribs = `${lineAttribs.join('|1+1')}|1+1`; // not valid in a changeset const newAttribs = `${lineAttribs.join('|1+1')}|1+1`; // not valid in a changeset
const analysis = analyzeChange( const analysis =
oldText, newText, oldAttribs, newAttribs, selStartHintChar, selEndHintChar analyzeChange(oldText, newText, oldAttribs, newAttribs, selStartHintChar, selEndHintChar);
);
const commonStart = analysis[0]; const commonStart = analysis[0];
let commonEnd = analysis[1]; let commonEnd = analysis[1];
let shortOldText = oldText.substring(commonStart, oldText.length - commonEnd); let shortOldText = oldText.substring(commonStart, oldText.length - commonEnd);
@ -1837,9 +1821,7 @@ function Ace2Inner(editorInfo, cssManagers) {
return rep.apool.putAttrib([k, '']); return rep.apool.putAttrib([k, '']);
} }
return false; return false;
} }));
)
);
const builder1 = startBuilder(); const builder1 = startBuilder();
if (shiftFinalNewlineToBeforeNewText) { if (shiftFinalNewlineToBeforeNewText) {
@ -2078,8 +2060,7 @@ function Ace2Inner(editorInfo, cssManagers) {
isScrollableEditEvent(currentCallStack.type); isScrollableEditEvent(currentCallStack.type);
const innerHeight = getInnerHeight(); const innerHeight = getInnerHeight();
scroll.scrollWhenCaretIsInTheLastLineOfViewportWhenNecessary( scroll.scrollWhenCaretIsInTheLastLineOfViewportWhenNecessary(
rep, isScrollableEvent, innerHeight * 2 rep, isScrollableEvent, innerHeight * 2);
);
} }
return true; return true;
@ -2087,11 +2068,7 @@ function Ace2Inner(editorInfo, cssManagers) {
return false; return false;
}; };
const isPadLoading = (eventType) => ( const isPadLoading = (t) => t === 'setup' || t === 'setBaseText' || t === 'importText';
eventType === 'setup') ||
(eventType === 'setBaseText') ||
(eventType === 'importText'
);
const updateStyleButtonState = (attribName, hasStyleOnRepSelection) => { const updateStyleButtonState = (attribName, hasStyleOnRepSelection) => {
const $formattingButton = parent.parent.$(`[data-key="${attribName}"]`).find('a'); const $formattingButton = parent.parent.$(`[data-key="${attribName}"]`).find('a');
@ -2475,11 +2452,10 @@ function Ace2Inner(editorInfo, cssManagers) {
const doIndentOutdent = (isOut) => { const doIndentOutdent = (isOut) => {
if (!((rep.selStart && rep.selEnd) || if (!((rep.selStart && rep.selEnd) ||
((rep.selStart[0] === rep.selEnd[0]) && (rep.selStart[0] === rep.selEnd[0] &&
(rep.selStart[1] === rep.selEnd[1]) && rep.selStart[1] === rep.selEnd[1] &&
rep.selEnd[1] > 1)) && rep.selEnd[1] > 1)) &&
(isOut !== true) isOut !== true) {
) {
return false; return false;
} }
@ -2553,9 +2529,7 @@ function Ace2Inner(editorInfo, cssManagers) {
if (prevLineBlank && !prevLineListType) { if (prevLineBlank && !prevLineListType) {
// previous line is blank, remove it // previous line is blank, remove it
performDocumentReplaceRange( performDocumentReplaceRange(
[theLine - 1, prevLineEntry.text.length], [theLine - 1, prevLineEntry.text.length], [theLine, 0], '');
[theLine, 0], ''
);
} else { } else {
// delistify // delistify
performDocumentReplaceRange([theLine, 0], [theLine, lineEntry.lineMarker], ''); performDocumentReplaceRange([theLine, 0], [theLine, lineEntry.lineMarker], '');
@ -2563,15 +2537,11 @@ function Ace2Inner(editorInfo, cssManagers) {
} else if (thisLineHasMarker && prevLineEntry) { } else if (thisLineHasMarker && prevLineEntry) {
// If the line has any attributes assigned, remove them by removing the marker '*' // If the line has any attributes assigned, remove them by removing the marker '*'
performDocumentReplaceRange( performDocumentReplaceRange(
[theLine - 1, prevLineEntry.text.length], [theLine - 1, prevLineEntry.text.length], [theLine, lineEntry.lineMarker], '');
[theLine, lineEntry.lineMarker], ''
);
} else if (theLine > 0) { } else if (theLine > 0) {
// remove newline // remove newline
performDocumentReplaceRange( performDocumentReplaceRange(
[theLine - 1, prevLineEntry.text.length], [theLine - 1, prevLineEntry.text.length], [theLine, 0], '');
[theLine, 0], ''
);
} }
} else { } else {
const docChar = caretDocChar(); const docChar = caretDocChar();
@ -2624,29 +2594,24 @@ function Ace2Inner(editorInfo, cssManagers) {
// 224 is the command-key under Mac Firefox. // 224 is the command-key under Mac Firefox.
// 91 is the Windows key in IE; it is ASCII for open-bracket but isn't the keycode for that key // 91 is the Windows key in IE; it is ASCII for open-bracket but isn't the keycode for that key
// 20 is capslock in IE. // 20 is capslock in IE.
const isModKey = ((!charCode) && const isModKey = !charCode && (type === 'keyup' || type === 'keydown') &&
((type === 'keyup') || (type === 'keydown')) && (keyCode === 16 || keyCode === 17 || keyCode === 18 ||
( keyCode === 20 || keyCode === 224 || keyCode === 91);
keyCode === 16 || keyCode === 17 || keyCode === 18 ||
keyCode === 20 || keyCode === 224 || keyCode === 91
));
if (isModKey) return; if (isModKey) return;
// If the key is a keypress and the browser is opera and the key is enter, // If the key is a keypress and the browser is opera and the key is enter,
// do nothign at all as this fires twice. // do nothign at all as this fires twice.
if (keyCode === 13 && browser.opera && (type === 'keypress')) { if (keyCode === 13 && browser.opera && type === 'keypress') {
// This stops double enters in Opera but double Tabs still show on single // This stops double enters in Opera but double Tabs still show on single
// tab keypress, adding keyCode == 9 to this doesn't help as the event is fired twice // tab keypress, adding keyCode == 9 to this doesn't help as the event is fired twice
return; return;
} }
let specialHandled = false; let specialHandled = false;
const isTypeForSpecialKey = ((browser.safari || const isTypeForSpecialKey = browser.safari || browser.chrome || browser.firefox
browser.chrome || ? type === 'keydown' : type === 'keypress';
browser.firefox) ? (type === 'keydown') : (type === 'keypress')); const isTypeForCmdKey = browser.safari || browser.chrome || browser.firefox
const isTypeForCmdKey = ((browser.safari || ? type === 'keydown' : type === 'keypress';
browser.chrome ||
browser.firefox) ? (type === 'keydown') : (type === 'keypress'));
let stopped = false; let stopped = false;
@ -2679,13 +2644,9 @@ function Ace2Inner(editorInfo, cssManagers) {
} }
const padShortcutEnabled = parent.parent.clientVars.padShortcutEnabled; const padShortcutEnabled = parent.parent.clientVars.padShortcutEnabled;
if ( if (!specialHandled && isTypeForSpecialKey &&
(!specialHandled) && altKey && keyCode === 120 &&
altKey && padShortcutEnabled.altF9) {
isTypeForSpecialKey &&
keyCode === 120 &&
padShortcutEnabled.altF9
) {
// Alt F9 focuses on the File Menu and/or editbar. // Alt F9 focuses on the File Menu and/or editbar.
// Note that while most editors use Alt F10 this is not desirable // Note that while most editors use Alt F10 this is not desirable
// As ubuntu cannot use Alt F10.... // As ubuntu cannot use Alt F10....
@ -2698,26 +2659,18 @@ function Ace2Inner(editorInfo, cssManagers) {
firstEditbarElement.focus(); firstEditbarElement.focus();
evt.preventDefault(); evt.preventDefault();
} }
if ( if (!specialHandled && type === 'keydown' &&
(!specialHandled) && altKey && keyCode === 67 &&
altKey && keyCode === 67 && padShortcutEnabled.altC) {
type === 'keydown' &&
padShortcutEnabled.altC
) {
// Alt c focuses on the Chat window // Alt c focuses on the Chat window
$(this).blur(); $(this).blur();
parent.parent.chat.show(); parent.parent.chat.show();
parent.parent.$('#chatinput').focus(); parent.parent.$('#chatinput').focus();
evt.preventDefault(); evt.preventDefault();
} }
if ( if (!specialHandled && type === 'keydown' &&
(!specialHandled) && evt.ctrlKey && shiftKey && keyCode === 50 &&
evt.ctrlKey && padShortcutEnabled.cmdShift2) {
shiftKey &&
keyCode === 50 &&
type === 'keydown' &&
padShortcutEnabled.cmdShift2
) {
// Control-Shift-2 shows a gritter popup showing a line author // Control-Shift-2 shows a gritter popup showing a line author
const lineNumber = rep.selEnd[0]; const lineNumber = rep.selEnd[0];
const alineAttrs = rep.alines[lineNumber]; const alineAttrs = rep.alines[lineNumber];
@ -2791,11 +2744,9 @@ function Ace2Inner(editorInfo, cssManagers) {
time: '4000', time: '4000',
}); });
} }
if ((!specialHandled) && if (!specialHandled && isTypeForSpecialKey &&
isTypeForSpecialKey && keyCode === 8 &&
keyCode === 8 && padShortcutEnabled.delete) {
padShortcutEnabled.delete
) {
// "delete" key; in mozilla, if we're at the beginning of a line, normalize now, // "delete" key; in mozilla, if we're at the beginning of a line, normalize now,
// or else deleting a blank line can take two delete presses. // or else deleting a blank line can take two delete presses.
// -- // --
@ -2808,11 +2759,9 @@ function Ace2Inner(editorInfo, cssManagers) {
doDeleteKey(evt); doDeleteKey(evt);
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForSpecialKey &&
isTypeForSpecialKey && keyCode === 13 &&
keyCode === 13 && padShortcutEnabled.return) {
padShortcutEnabled.return
) {
// return key, handle specially; // return key, handle specially;
// note that in mozilla we need to do an incorporation for proper return behavior anyway. // note that in mozilla we need to do an incorporation for proper return behavior anyway.
fastIncorp(4); fastIncorp(4);
@ -2823,11 +2772,9 @@ function Ace2Inner(editorInfo, cssManagers) {
}, 0); }, 0);
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForSpecialKey &&
isTypeForSpecialKey && keyCode === 27 &&
keyCode === 27 && padShortcutEnabled.esc) {
padShortcutEnabled.esc
) {
// prevent esc key; // prevent esc key;
// in mozilla versions 14-19 avoid reconnecting pad. // in mozilla versions 14-19 avoid reconnecting pad.
@ -2838,15 +2785,11 @@ function Ace2Inner(editorInfo, cssManagers) {
// close all gritters when the user hits escape key // close all gritters when the user hits escape key
parent.parent.$.gritter.removeAll(); parent.parent.$.gritter.removeAll();
} }
if ( if (!specialHandled && isTypeForCmdKey &&
(!specialHandled) && /* Do a saved revision on ctrl S */
/* Do a saved revision on ctrl S */ (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 's' &&
isTypeForCmdKey && !evt.altKey &&
String.fromCharCode(which).toLowerCase() === 's' && padShortcutEnabled.cmdS) {
(evt.metaKey || evt.ctrlKey) &&
!evt.altKey &&
padShortcutEnabled.cmdS
) {
evt.preventDefault(); evt.preventDefault();
const originalBackground = parent.parent.$('#revisionlink').css('background'); const originalBackground = parent.parent.$('#revisionlink').css('background');
parent.parent.$('#revisionlink').css({background: 'lightyellow'}); parent.parent.$('#revisionlink').css({background: 'lightyellow'});
@ -2857,25 +2800,21 @@ function Ace2Inner(editorInfo, cssManagers) {
parent.parent.pad.collabClient.sendMessage({type: 'SAVE_REVISION'}); parent.parent.pad.collabClient.sendMessage({type: 'SAVE_REVISION'});
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForSpecialKey &&
// tab // tab
isTypeForSpecialKey && keyCode === 9 &&
keyCode === 9 && !(evt.metaKey || evt.ctrlKey) &&
!(evt.metaKey || evt.ctrlKey) && padShortcutEnabled.tab) {
padShortcutEnabled.tab) {
fastIncorp(5); fastIncorp(5);
evt.preventDefault(); evt.preventDefault();
doTabKey(evt.shiftKey); doTabKey(evt.shiftKey);
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-Z (undo) // cmd-Z (undo)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'z' &&
String.fromCharCode(which).toLowerCase() === 'z' && !evt.altKey &&
(evt.metaKey || evt.ctrlKey) && padShortcutEnabled.cmdZ) {
!evt.altKey &&
padShortcutEnabled.cmdZ
) {
fastIncorp(6); fastIncorp(6);
evt.preventDefault(); evt.preventDefault();
if (evt.shiftKey) { if (evt.shiftKey) {
@ -2885,120 +2824,93 @@ function Ace2Inner(editorInfo, cssManagers) {
} }
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-Y (redo) // cmd-Y (redo)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'y' &&
String.fromCharCode(which).toLowerCase() === 'y' && padShortcutEnabled.cmdY) {
(evt.metaKey || evt.ctrlKey) &&
padShortcutEnabled.cmdY
) {
fastIncorp(10); fastIncorp(10);
evt.preventDefault(); evt.preventDefault();
doUndoRedo('redo'); doUndoRedo('redo');
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-B (bold) // cmd-B (bold)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'b' &&
String.fromCharCode(which).toLowerCase() === 'b' && padShortcutEnabled.cmdB) {
(evt.metaKey || evt.ctrlKey) &&
padShortcutEnabled.cmdB) {
fastIncorp(13); fastIncorp(13);
evt.preventDefault(); evt.preventDefault();
toggleAttributeOnSelection('bold'); toggleAttributeOnSelection('bold');
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-I (italic) // cmd-I (italic)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'i' &&
String.fromCharCode(which).toLowerCase() === 'i' && padShortcutEnabled.cmdI) {
(evt.metaKey || evt.ctrlKey) &&
padShortcutEnabled.cmdI
) {
fastIncorp(14); fastIncorp(14);
evt.preventDefault(); evt.preventDefault();
toggleAttributeOnSelection('italic'); toggleAttributeOnSelection('italic');
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
isTypeForCmdKey && // cmd-U (underline)
String.fromCharCode(which).toLowerCase() === 'u' && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'u' &&
(evt.metaKey || evt.ctrlKey) && padShortcutEnabled.cmdU) {
padShortcutEnabled.cmdU
) {
// cmd-U (underline)
fastIncorp(15); fastIncorp(15);
evt.preventDefault(); evt.preventDefault();
toggleAttributeOnSelection('underline'); toggleAttributeOnSelection('underline');
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-5 (strikethrough) // cmd-5 (strikethrough)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === '5' &&
String.fromCharCode(which).toLowerCase() === '5' && evt.altKey !== true &&
(evt.metaKey || evt.ctrlKey) && padShortcutEnabled.cmd5) {
evt.altKey !== true &&
padShortcutEnabled.cmd5
) {
fastIncorp(13); fastIncorp(13);
evt.preventDefault(); evt.preventDefault();
toggleAttributeOnSelection('strikethrough'); toggleAttributeOnSelection('strikethrough');
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-shift-L (unorderedlist) // cmd-shift-L (unorderedlist)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'l' &&
String.fromCharCode(which).toLowerCase() === 'l' && evt.shiftKey &&
(evt.metaKey || evt.ctrlKey) && padShortcutEnabled.cmdShiftL) {
evt.shiftKey &&
padShortcutEnabled.cmdShiftL
) {
fastIncorp(9); fastIncorp(9);
evt.preventDefault(); evt.preventDefault();
doInsertUnorderedList(); doInsertUnorderedList();
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-shift-N and cmd-shift-1 (orderedlist) // cmd-shift-N and cmd-shift-1 (orderedlist)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && evt.shiftKey &&
( ((String.fromCharCode(which).toLowerCase() === 'n' && padShortcutEnabled.cmdShiftN) ||
(String.fromCharCode(which).toLowerCase() === 'n' && (String.fromCharCode(which) === '1' && padShortcutEnabled.cmdShift1))) {
padShortcutEnabled.cmdShiftN) || (String.fromCharCode(which) === '1' &&
padShortcutEnabled.cmdShift1)
) && (evt.metaKey || evt.ctrlKey) &&
evt.shiftKey
) {
fastIncorp(9); fastIncorp(9);
evt.preventDefault(); evt.preventDefault();
doInsertOrderedList(); doInsertOrderedList();
specialHandled = true; specialHandled = true;
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-shift-C (clearauthorship) // cmd-shift-C (clearauthorship)
isTypeForCmdKey && (evt.metaKey || evt.ctrlKey) && evt.shiftKey &&
String.fromCharCode(which).toLowerCase() === 'c' && String.fromCharCode(which).toLowerCase() === 'c' &&
(evt.metaKey || evt.ctrlKey) && padShortcutEnabled.cmdShiftC) {
evt.shiftKey && padShortcutEnabled.cmdShiftC
) {
fastIncorp(9); fastIncorp(9);
evt.preventDefault(); evt.preventDefault();
CMDS.clearauthorship(); CMDS.clearauthorship();
} }
if ((!specialHandled) && if (!specialHandled && isTypeForCmdKey &&
// cmd-H (backspace) // cmd-H (backspace)
isTypeForCmdKey && (evt.ctrlKey) && String.fromCharCode(which).toLowerCase() === 'h' &&
String.fromCharCode(which).toLowerCase() === 'h' && padShortcutEnabled.cmdH) {
(evt.ctrlKey) &&
padShortcutEnabled.cmdH
) {
fastIncorp(20); fastIncorp(20);
evt.preventDefault(); evt.preventDefault();
doDeleteKey(); doDeleteKey();
specialHandled = true; specialHandled = true;
} }
if ((evt.which === 36 && evt.ctrlKey === true) && if (evt.ctrlKey === true && evt.which === 36 &&
// Control Home send to Y = 0 // Control Home send to Y = 0
padShortcutEnabled.ctrlHome) { padShortcutEnabled.ctrlHome) {
scroll.setScrollY(0); scroll.setScrollY(0);
} }
if ((evt.which === 33 || evt.which === 34) && type === 'keydown' && !evt.ctrlKey) { if ((evt.which === 33 || evt.which === 34) && type === 'keydown' && !evt.ctrlKey) {
@ -3099,10 +3011,9 @@ function Ace2Inner(editorInfo, cssManagers) {
thisKeyDoesntTriggerNormalize = true; thisKeyDoesntTriggerNormalize = true;
} }
if ((!specialHandled) && (!thisKeyDoesntTriggerNormalize) && (!inInternationalComposition)) { if (!specialHandled && !thisKeyDoesntTriggerNormalize && !inInternationalComposition &&
if (type !== 'keyup') { type !== 'keyup') {
observeChangesAroundSelection(); observeChangesAroundSelection();
}
} }
if (type === 'keyup') { if (type === 'keyup') {
@ -3128,12 +3039,9 @@ function Ace2Inner(editorInfo, cssManagers) {
} }
if (selectionInfo) { if (selectionInfo) {
performSelectionChange( performSelectionChange(
lineAndColumnFromChar( lineAndColumnFromChar(selectionInfo.selStart),
selectionInfo.selStart
),
lineAndColumnFromChar(selectionInfo.selEnd), lineAndColumnFromChar(selectionInfo.selEnd),
selectionInfo.selFocusAtStart selectionInfo.selFocusAtStart);
);
} }
const oldEvent = currentCallStack.startNewEvent(oldEventType, true); const oldEvent = currentCallStack.startNewEvent(oldEventType, true);
return oldEvent; return oldEvent;
@ -3173,15 +3081,13 @@ function Ace2Inner(editorInfo, cssManagers) {
// with background doesn't seem to show up... // with background doesn't seem to show up...
if (isNodeText(p.node) && p.index === p.maxIndex) { if (isNodeText(p.node) && p.index === p.maxIndex) {
let n = p.node; let n = p.node;
while ((!n.nextSibling) && (n !== root) && (n.parentNode !== root)) { while (!n.nextSibling && n !== root && n.parentNode !== root) {
n = n.parentNode; n = n.parentNode;
} }
if ( if (n.nextSibling &&
n.nextSibling && !(typeof n.nextSibling.tagName === 'string' &&
(!((typeof n.nextSibling.tagName) === 'string' && n.nextSibling.tagName.toLowerCase() === 'br') &&
n.nextSibling.tagName.toLowerCase() === 'br')) && n !== p.node && n !== root && n.parentNode !== root) {
(n !== p.node) && (n !== root) && (n.parentNode !== root)
) {
// found a parent, go to next node and dive in // found a parent, go to next node and dive in
p.node = n.nextSibling; p.node = n.nextSibling;
p.maxIndex = nodeMaxIndex(p.node); p.maxIndex = nodeMaxIndex(p.node);
@ -3212,19 +3118,13 @@ function Ace2Inner(editorInfo, cssManagers) {
if (browserSelection) { if (browserSelection) {
browserSelection.removeAllRanges(); browserSelection.removeAllRanges();
if (selection) { if (selection) {
isCollapsed = ( isCollapsed = (selection.startPoint.node === selection.endPoint.node &&
selection.startPoint.node === selection.endPoint.node && selection.startPoint.index === selection.endPoint.index);
selection.startPoint.index === selection.endPoint.index
);
const start = pointToRangeBound(selection.startPoint); const start = pointToRangeBound(selection.startPoint);
const end = pointToRangeBound(selection.endPoint); const end = pointToRangeBound(selection.endPoint);
if ( if (!isCollapsed && selection.focusAtStart &&
(!isCollapsed) && browserSelection.collapse && browserSelection.extend) {
selection.focusAtStart &&
browserSelection.collapse &&
browserSelection.extend
) {
// can handle "backwards"-oriented selection, shift-arrow-keys move start // can handle "backwards"-oriented selection, shift-arrow-keys move start
// of selection // of selection
browserSelection.collapse(end.container, end.offset); browserSelection.collapse(end.container, end.offset);
@ -3509,8 +3409,7 @@ function Ace2Inner(editorInfo, cssManagers) {
let charsToLeft = index; let charsToLeft = index;
let charsToRight = node.nodeValue.length - index; let charsToRight = node.nodeValue.length - index;
let n; let n;
for (n = node.previousSibling; n && for (n = node.previousSibling; n && isNodeText(n); n = n.previousSibling) {
isNodeText(n); n = n.previousSibling) {
charsToLeft += n.nodeValue; charsToLeft += n.nodeValue;
} }
const leftEdge = (n ? rightOf(n) : leftOf(node.parentNode)); const leftEdge = (n ? rightOf(n) : leftOf(node.parentNode));
@ -3560,9 +3459,8 @@ function Ace2Inner(editorInfo, cssManagers) {
if (!doesWrap) { if (!doesWrap) {
const browserSelection = getSelection(); const browserSelection = getSelection();
if (browserSelection) { if (browserSelection) {
const focusPoint = ( const focusPoint =
browserSelection.focusAtStart ? browserSelection.startPoint : browserSelection.endPoint browserSelection.focusAtStart ? browserSelection.startPoint : browserSelection.endPoint;
);
const selectionPointX = getSelectionPointX(focusPoint); const selectionPointX = getSelectionPointX(focusPoint);
scrollXHorizontallyIntoView(selectionPointX); scrollXHorizontallyIntoView(selectionPointX);
fixView(); fixView();
@ -3681,8 +3579,7 @@ function Ace2Inner(editorInfo, cssManagers) {
// extra margins/padding, but plugins might. // extra margins/padding, but plugins might.
h = docLine.nextSibling.offsetTop - parseInt( h = docLine.nextSibling.offsetTop - parseInt(
window.getComputedStyle(doc.body) window.getComputedStyle(doc.body)
.getPropertyValue('padding-top').split('px')[0] .getPropertyValue('padding-top').split('px')[0]);
);
} else { } else {
h = docLine.nextSibling.offsetTop - docLine.offsetTop; h = docLine.nextSibling.offsetTop - docLine.offsetTop;
} }