mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
include opts in pageup/pagedown method to support shift key and include the test
This commit is contained in:
parent
dda5e03f7e
commit
5a425d7e69
2 changed files with 41 additions and 6 deletions
|
@ -241,11 +241,16 @@ helper.clearPad = async () => {
|
|||
* Scrolls up in the editor
|
||||
* TODO: is `getSelection` always defined?
|
||||
*/
|
||||
helper.pageUp = async () => {
|
||||
helper.pageUp = async (opts) => {
|
||||
// the caret is in this node
|
||||
const caretNode = helper.padInner$.document.getSelection().anchorNode;
|
||||
const event = new helper.padInner$.Event(helper.evtType);
|
||||
event.which = 33;
|
||||
if (opts) {
|
||||
if (opts.shift) {
|
||||
event.shiftKey = true;
|
||||
}
|
||||
}
|
||||
helper.padInner$('#innerdocbody').trigger(event);
|
||||
|
||||
// return as soon as the selection has changed
|
||||
|
@ -256,11 +261,16 @@ helper.pageUp = async () => {
|
|||
* Scrolls down in the editor
|
||||
* TODO: is `getSelection` always defined?
|
||||
*/
|
||||
helper.pageDown = async () => {
|
||||
helper.pageDown = async (opts) => {
|
||||
// the caret is in this node
|
||||
const caretNode = helper.padInner$.document.getSelection().anchorNode;
|
||||
const event = new helper.padInner$.Event(helper.evtType);
|
||||
event.which = 34;
|
||||
if (opts) {
|
||||
if (opts.shift) {
|
||||
event.shiftKey = true;
|
||||
}
|
||||
}
|
||||
helper.padInner$('#innerdocbody').trigger(event);
|
||||
|
||||
// return as soon as the selection has changed
|
||||
|
@ -274,8 +284,9 @@ helper.pageDown = async () => {
|
|||
*/
|
||||
helper.caretLineNumber = () => {
|
||||
if (helper.padInner$.document.getSelection()) {
|
||||
let caretNode = helper.padInner$.document.getSelection().anchorNode;;
|
||||
let bodyElement = helper.padInner$('body')[0];
|
||||
let caretNode = helper.padInner$.document.getSelection().anchorNode;
|
||||
console.log('caretNode', caretNode);
|
||||
const bodyElement = helper.padInner$('body')[0];
|
||||
|
||||
// a text node does not have a classList method
|
||||
if (caretNode.nodeType === 3) {
|
||||
|
@ -283,7 +294,7 @@ helper.caretLineNumber = () => {
|
|||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// a text node does not have a classList method
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
'use strict';
|
||||
/*
|
||||
describe('Page Up/Down', function () {
|
||||
beforeEach(function (cb) {
|
||||
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) {
|
||||
helper.newPad({
|
||||
cb: async () => {
|
||||
|
@ -295,3 +296,26 @@ describe('Viewport baesd Page Up/Down', function () {
|
|||
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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue