still very broken but getting more test coverage at least -_-
parent
a30b120b0e
commit
cdce13ca25
|
@ -3071,6 +3071,9 @@ function Ace2Inner() {
|
||||||
const isPageUp = evt.which === 33;
|
const isPageUp = evt.which === 33;
|
||||||
const linesLength = rep.lines.length();
|
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
|
// input is a line
|
||||||
// returned is the number of characters in that index that are currently
|
// returned is the number of characters in that index that are currently
|
||||||
// visible in the viewport
|
// visible in the viewport
|
||||||
|
@ -3111,29 +3114,47 @@ function Ace2Inner() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isPageUp) {
|
if (isPageUp) {
|
||||||
// go to the top of the visible content
|
// would the new location be before the document?
|
||||||
rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0];
|
// top.console.log(rep.selEnd[0] - (visibleLineRange[1] - visibleLineRange[0]));
|
||||||
if (!shiftKey) rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0];
|
const targetLine = rep.selEnd[0] - (visibleLineRange[1] - visibleLineRange[0]);
|
||||||
// if the new rep is beyond the viewport or first line,
|
const beforeViewport = targetLine <= 0;
|
||||||
if (rep.selStart[0] <= 0) {
|
top.console.log('beforeVP', beforeViewport);
|
||||||
// put the caret on the first line in the first position
|
top.console.log('highlighting', highlighting);
|
||||||
rep.selStart = [0, 0];
|
top.console.log('shitKey', shiftKey);
|
||||||
if (!shiftKey) rep.selEnd = [0, 0];
|
|
||||||
} else {
|
|
||||||
let line;
|
|
||||||
// need current character length of line
|
|
||||||
try {
|
|
||||||
line = rep.lines.atIndex(rep.selEnd[0]);
|
|
||||||
} catch (e) {
|
|
||||||
// silently fail, no big deal..
|
|
||||||
line = rep.lines.atIndex(visibleLineRange[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const lineLength = line.width;
|
if (extendSelection) {
|
||||||
// Keep the X character offset on page down
|
if (beforeViewport || targetLine === 1) {
|
||||||
if (previousCharacterOffset <= line.width) {
|
// lets assume we select end of document then hit page up
|
||||||
rep.selStart[1] = previousCharacterOffset;
|
if (highlighting) {
|
||||||
if (!shiftKey) rep.selEnd[1] = previousCharacterOffset;
|
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 {
|
||||||
|
line = rep.lines.atIndex(rep.selEnd[0]);
|
||||||
|
} catch (e) {
|
||||||
|
// silently fail, no big deal..
|
||||||
|
line = rep.lines.atIndex(visibleLineRange[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineLength = line.width;
|
||||||
|
// Keep the X character offset on page down
|
||||||
|
if (previousCharacterOffset <= line.width) {
|
||||||
|
rep.selStart[1] = previousCharacterOffset;
|
||||||
|
if (!shiftKey) rep.selEnd[1] = previousCharacterOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO/JM: Handle page up in really long lines
|
// TODO/JM: Handle page up in really long lines
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
/*
|
|
||||||
describe('Page Up/Down', function () {
|
describe('Page Up/Down', function () {
|
||||||
beforeEach(function (cb) {
|
beforeEach(function (cb) {
|
||||||
helper.newPad({
|
helper.newPad({
|
||||||
|
@ -296,7 +295,6 @@ describe('Viewport based Page Up/Down', function () {
|
||||||
await helper.waitForPromise(() => currentLineNumber < 5);
|
await helper.waitForPromise(() => currentLineNumber < 5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
describe('Shift Page Up/Down', function () {
|
describe('Shift Page Up/Down', function () {
|
||||||
beforeEach(function (cb) {
|
beforeEach(function (cb) {
|
||||||
helper.newPad({
|
helper.newPad({
|
||||||
|
@ -373,4 +371,17 @@ describe('Shift Page Up/Down', function () {
|
||||||
});
|
});
|
||||||
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue