include opts in pageup/pagedown method to support shift key and include the test

This commit is contained in:
John McLear 2020-12-30 19:19:35 +00:00
parent dda5e03f7e
commit 5a425d7e69
2 changed files with 41 additions and 6 deletions

View file

@ -241,11 +241,16 @@ helper.clearPad = async () => {
* Scrolls up in the editor * Scrolls up in the editor
* TODO: is `getSelection` always defined? * TODO: is `getSelection` always defined?
*/ */
helper.pageUp = async () => { helper.pageUp = async (opts) => {
// the caret is in this node // the caret is in this node
const caretNode = helper.padInner$.document.getSelection().anchorNode; const caretNode = helper.padInner$.document.getSelection().anchorNode;
const event = new helper.padInner$.Event(helper.evtType); const event = new helper.padInner$.Event(helper.evtType);
event.which = 33; event.which = 33;
if (opts) {
if (opts.shift) {
event.shiftKey = true;
}
}
helper.padInner$('#innerdocbody').trigger(event); helper.padInner$('#innerdocbody').trigger(event);
// return as soon as the selection has changed // return as soon as the selection has changed
@ -256,11 +261,16 @@ helper.pageUp = async () => {
* Scrolls down in the editor * Scrolls down in the editor
* TODO: is `getSelection` always defined? * TODO: is `getSelection` always defined?
*/ */
helper.pageDown = async () => { helper.pageDown = async (opts) => {
// the caret is in this node // the caret is in this node
const caretNode = helper.padInner$.document.getSelection().anchorNode; const caretNode = helper.padInner$.document.getSelection().anchorNode;
const event = new helper.padInner$.Event(helper.evtType); const event = new helper.padInner$.Event(helper.evtType);
event.which = 34; event.which = 34;
if (opts) {
if (opts.shift) {
event.shiftKey = true;
}
}
helper.padInner$('#innerdocbody').trigger(event); helper.padInner$('#innerdocbody').trigger(event);
// return as soon as the selection has changed // return as soon as the selection has changed
@ -274,8 +284,9 @@ helper.pageDown = async () => {
*/ */
helper.caretLineNumber = () => { helper.caretLineNumber = () => {
if (helper.padInner$.document.getSelection()) { if (helper.padInner$.document.getSelection()) {
let caretNode = helper.padInner$.document.getSelection().anchorNode;; let caretNode = helper.padInner$.document.getSelection().anchorNode;
let bodyElement = helper.padInner$('body')[0]; console.log('caretNode', caretNode);
const bodyElement = helper.padInner$('body')[0];
// a text node does not have a classList method // a text node does not have a classList method
if (caretNode.nodeType === 3) { if (caretNode.nodeType === 3) {
@ -283,7 +294,7 @@ helper.caretLineNumber = () => {
} }
// find the ace-line that contains the caret // find the ace-line that contains the caret
while (!caretNode.classList.contains('ace-line') && caretNode !== bodyElement ) { while (!caretNode.classList.contains('ace-line') && caretNode !== bodyElement) {
caretNode = caretNode.parentNode; caretNode = caretNode.parentNode;
// a text node does not have a classList method // a text node does not have a classList method

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
/*
describe('Page Up/Down', function () { describe('Page Up/Down', function () {
beforeEach(function (cb) { beforeEach(function (cb) {
helper.newPad({ helper.newPad({
@ -268,7 +269,7 @@ describe('Really long text line goes to character within text line if text line
}); });
}); });
describe('Viewport baesd Page Up/Down', function () { describe('Viewport based Page Up/Down', function () {
beforeEach(function (cb) { beforeEach(function (cb) {
helper.newPad({ helper.newPad({
cb: async () => { cb: async () => {
@ -295,3 +296,26 @@ describe('Viewport baesd Page Up/Down', function () {
await helper.waitForPromise(() => currentLineNumber < 5); await helper.waitForPromise(() => currentLineNumber < 5);
}); });
}); });
*/
describe('Shift Page Up/Down', function () {
beforeEach(function (cb) {
helper.newPad({
cb: async () => {
await helper.clearPad();
// 200 lines
await helper.edit('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
cb();
},
});
});
it('highlights multiple lines on shift page down', async function () {
await helper.edit('xxx', 1); // caret is offset 6
helper.pageUp();
helper.pageDown({
shift: true,
});
await helper.waitForPromise(() => helper.padInner$.document.getSelection().type === 'Range');
});
});