still very broken but getting more test coverage at least -_-

page-down-up-bugfix
John McLear 2020-12-31 11:27:04 +00:00
parent a30b120b0e
commit cdce13ca25
2 changed files with 56 additions and 24 deletions

View File

@ -3071,6 +3071,9 @@ function Ace2Inner() {
const isPageUp = evt.which === 33;
const linesLength = rep.lines.length();
// 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]);
// input is a line
// returned is the number of characters in that index that are currently
// visible in the viewport
@ -3111,15 +3114,32 @@ function Ace2Inner() {
};
if (isPageUp) {
// go to the top of the visible content
rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0];
if (!shiftKey) rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0];
// if the new rep is beyond the viewport or first line,
if (rep.selStart[0] <= 0) {
// would the new location be before the document?
// top.console.log(rep.selEnd[0] - (visibleLineRange[1] - visibleLineRange[0]));
const targetLine = rep.selEnd[0] - (visibleLineRange[1] - visibleLineRange[0]);
const beforeViewport = targetLine <= 0;
top.console.log('beforeVP', beforeViewport);
top.console.log('highlighting', highlighting);
top.console.log('shitKey', shiftKey);
if (extendSelection) {
if (beforeViewport || targetLine === 1) {
// lets assume we select end of document then hit page up
if (highlighting) {
top.console.log('resetting...');
// put the caret on the first line in the first position
if (shiftKey) rep.selStart = [0, 0];
if (shiftKey) rep.selEnd = [0, 0];
} else {
// we should always keep our selEnd..
rep.selStart = [0, 0];
if (!shiftKey) rep.selEnd = [0, 0];
}
// TODO Handle long lines!
} else {
top.console.log('MAM');
if (shiftKey) rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0];
if (!shiftKey) rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0];
let line;
// need current character length of line
try {
@ -3136,6 +3156,7 @@ function Ace2Inner() {
if (!shiftKey) rep.selEnd[1] = previousCharacterOffset;
}
}
}
// TODO/JM: Handle page up in really long lines
}

View File

@ -1,5 +1,4 @@
'use strict';
/*
describe('Page Up/Down', function () {
beforeEach(function (cb) {
helper.newPad({
@ -296,7 +295,6 @@ describe('Viewport based Page Up/Down', function () {
await helper.waitForPromise(() => currentLineNumber < 5);
});
});
*/
describe('Shift Page Up/Down', function () {
beforeEach(function (cb) {
helper.newPad({
@ -373,4 +371,17 @@ describe('Shift Page Up/Down', function () {
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
it('highlights from 3rd line on page up twice should keep highlight', async function () {
await helper.edit('xxx', 3); // caret is offset 6
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
helper.pageUp({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
});