reverse reps are a brain truck

This commit is contained in:
John McLear 2021-01-03 12:36:04 +00:00
parent e48f2d0190
commit 81e4c14fc0
2 changed files with 39 additions and 26 deletions

View file

@ -3057,6 +3057,15 @@ function Ace2Inner() {
const linesLength = rep.lines.length(); const linesLength = rep.lines.length();
let previousCharacterOffset; let previousCharacterOffset;
top.console.log('previousCharacterOffset', previousCharacterOffset);
// boolean - reflects if the user is attempting to highlight content
const highlighting = shiftKey && (rep.selStart[0] !== rep.selEnd[0] || rep.selStart[1] !== rep.selEnd[1]);
const isShiftKey = shiftKey;
if (isPageUp) {
// Approach #99991248928174 to solve this problem....
// only make history of x offset if it's not 0. // only make history of x offset if it's not 0.
if (rep.selStart[1] !== 0 && rep.selEnd[1] !== 0) { if (rep.selStart[1] !== 0 && rep.selEnd[1] !== 0) {
previousCharacterOffset = [ previousCharacterOffset = [
@ -3066,17 +3075,11 @@ function Ace2Inner() {
} else { } else {
previousCharacterOffset = [0, 0]; previousCharacterOffset = [0, 0];
} }
top.console.log('previousCharacterOffset', previousCharacterOffset);
// boolean - reflects if the user is attempting to highlight content
const highlighting = shiftKey && (rep.selStart[0] !== rep.selEnd[0] || rep.selStart[1] !== rep.selEnd[1]);
if (isPageUp) {
// Approach #99991248928174 to solve this problem....
scroll.movePage('up'); scroll.movePage('up');
const modifiedRep = scroll.getFirstVisibleCharacter('up', rep); const modifiedRep = scroll.getFirstVisibleCharacter('up', rep);
rep.selStart[0] = modifiedRep.selStart[0]; rep.selStart[0] = modifiedRep.selStart[0];
rep.selEnd[0] = modifiedRep.selEnd[0]; if (!isShiftKey) rep.selEnd[0] = modifiedRep.selEnd[0];
// Should we try to maintain X position? // Should we try to maintain X position?
if (previousCharacterOffset[0] >= 1 || previousCharacterOffset[1] >= 1) { if (previousCharacterOffset[0] >= 1 || previousCharacterOffset[1] >= 1) {
@ -3088,16 +3091,25 @@ function Ace2Inner() {
rep.selStart[1] = lengthOfFirstLine; rep.selStart[1] = lengthOfFirstLine;
} }
if (previousCharacterOffset[1] <= lengthOfLastLine) { if (previousCharacterOffset[1] <= lengthOfLastLine) {
rep.selEnd[1] = previousCharacterOffset[1]; // shift key on page up only modifies selStart, never selEnd!
} else { if (!isShiftKey) rep.selEnd[1] = previousCharacterOffset[1];
rep.selEnd[1] = lengthOfLastLine; } else if (!isShiftKey) { rep.selEnd[1] = lengthOfLastLine; }
}
} else { } else {
rep.selStart[1] = modifiedRep.selStart[1]; rep.selStart[1] = modifiedRep.selStart[1];
rep.selEnd[1] = modifiedRep.selEnd[1]; if (!isShiftKey) rep.selEnd[1] = modifiedRep.selEnd[1];
} }
} }
if (isPageDown) { if (isPageDown) {
// only make history of x offset if it's not 0.
if (rep.selStart[1] !== 0 && rep.selEnd[1] !== 0) {
previousCharacterOffset = [
rep.selStart[1],
rep.selEnd[1],
];
} else {
previousCharacterOffset = [0, 0];
}
/** * /** *
* Bottom of document - do nothing if we are at the very end * Bottom of document - do nothing if we are at the very end
*/ */
@ -3122,16 +3134,17 @@ function Ace2Inner() {
*/ */
const modifiedRep = scroll.getFirstVisibleCharacter('down', rep); const modifiedRep = scroll.getFirstVisibleCharacter('down', rep);
rep.selStart[0] = modifiedRep.selStart[0]; // shift key on page down only modifies selEnd, never selStart!
if (!isShiftKey) rep.selStart[0] = modifiedRep.selStart[0];
rep.selEnd[0] = modifiedRep.selEnd[0]; rep.selEnd[0] = modifiedRep.selEnd[0];
rep.selStart[1] = modifiedRep.selStart[1]; if (!isShiftKey) rep.selStart[1] = modifiedRep.selStart[1];
rep.selEnd[1] = modifiedRep.selEnd[1]; rep.selEnd[1] = modifiedRep.selEnd[1];
if (!hasMoved) { if (!hasMoved) {
// we're at the bottom so select the last bit of content. // we're at the bottom so select the last bit of content.
rep.selStart[0] = rep.lines.length() - 1; if (!isShiftKey) rep.selStart[0] = rep.lines.length() - 1;
rep.selEnd[0] = rep.lines.length() - 1; rep.selEnd[0] = rep.lines.length() - 1;
rep.selStart[1] = rep.lines.atIndex(rep.selStart[0]).length; if (!isShiftKey) rep.selStart[1] = rep.lines.atIndex(rep.selStart[0]).length;
rep.selEnd[1] = rep.lines.atIndex(rep.selStart[0]).length; rep.selEnd[1] = rep.lines.atIndex(rep.selStart[0]).length;
} else { } else {
// Should we try to maintain X position? // Should we try to maintain X position?
@ -3139,21 +3152,19 @@ function Ace2Inner() {
const lengthOfFirstLine = rep.lines.atIndex(rep.selStart[0]).width - 1; const lengthOfFirstLine = rep.lines.atIndex(rep.selStart[0]).width - 1;
const lengthOfLastLine = rep.lines.atIndex(rep.selEnd[0]).width - 1; const lengthOfLastLine = rep.lines.atIndex(rep.selEnd[0]).width - 1;
if (previousCharacterOffset[0] <= lengthOfFirstLine) { if (previousCharacterOffset[0] <= lengthOfFirstLine) {
rep.selStart[1] = previousCharacterOffset[0]; if (!isShiftKey) rep.selStart[1] = previousCharacterOffset[0];
} else { } else if (!isShiftKey) { rep.selStart[1] = lengthOfFirstLine; }
rep.selStart[1] = lengthOfFirstLine;
}
if (previousCharacterOffset[1] <= lengthOfLastLine) { if (previousCharacterOffset[1] <= lengthOfLastLine) {
rep.selEnd[1] = previousCharacterOffset[1]; rep.selEnd[1] = previousCharacterOffset[1];
} else { } else {
rep.selEnd[1] = lengthOfLastLine; rep.selEnd[1] = lengthOfLastLine;
} }
} else { } else {
rep.selStart[1] = modifiedRep.selStart[1]; if (!isShiftKey) rep.selStart[1] = modifiedRep.selStart[1];
rep.selEnd[1] = modifiedRep.selEnd[1]; rep.selEnd[1] = modifiedRep.selEnd[1];
} }
// we moved, this will need modifying to support remembered x offset // we moved, this will need modifying to support remembered x offset
rep.selStart[0] = modifiedRep.selStart[0]; if (!isShiftKey) rep.selStart[0] = modifiedRep.selStart[0];
rep.selEnd[0] = modifiedRep.selEnd[0]; rep.selEnd[0] = modifiedRep.selEnd[0];
} }
} }

View file

@ -426,12 +426,13 @@ Scroll.prototype.getCountOfVisibleCharsInViewport = (line, viewport) => {
const parentElement = document.getElementById(line.domInfo.node.id).childNodes; const parentElement = document.getElementById(line.domInfo.node.id).childNodes;
const charNumber = []; const charNumber = [];
// top.console.log(parentElement); // top.console.log(parentElement);
for (let node of parentElement) { for (const node of parentElement) {
// each span.. // each span..
// top.console.log('span', node); // shows all nodes from the collection // top.console.log('span', node); // shows all nodes from the collection
// top.console.log('span length', node.offsetTop); // shows all nodes from the collection // top.console.log('span length', node.offsetTop); // shows all nodes from the collection
// each character // each character
/*
let i = 0; let i = 0;
console.log(node); console.log(node);
if (!node || !node.childNodes) return; if (!node || !node.childNodes) return;
@ -477,6 +478,7 @@ Scroll.prototype.getCountOfVisibleCharsInViewport = (line, viewport) => {
i++; i++;
} }
top.console.log('charNumber', charNumber); top.console.log('charNumber', charNumber);
*/
return; // TEMPJM CAKE remove once stable return; // TEMPJM CAKE remove once stable
} }
return 1000; return 1000;