Skip to content

Commit

Permalink
scroll on selecting cells with keyboard
Browse files Browse the repository at this point in the history
When selecting multiple cells with shift + down arrow, if the selection
goes out of the view area it should scroll to keep the newly selected
cells into view.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: I30aac5e3595482c7e43adff189cc47fed4310b59
  • Loading branch information
Jaume Pujantell committed Nov 26, 2024
1 parent dc930ff commit 58c04b7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
8 changes: 4 additions & 4 deletions browser/src/layer/tile/CanvasTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2815,10 +2815,10 @@ L.CanvasTileLayer = L.Layer.extend({
scrollX = newSelection.pX2 - app.file.viewedRectangle.pX2 + spacingX;
else if (newSelection.pX1 < app.file.viewedRectangle.pX1 && newSelection.pX1 < oldSelection.pX1)
scrollX = newSelection.pX1 - app.file.viewedRectangle.pX1 - spacingX;
if (newSelection.pY1 > app.file.viewedRectangle.pY1 && newSelection.pY1 > oldSelection.pY1)
scrollY = newSelection.pY1 - app.file.viewedRectangle.pY1 + spacingY;
else if (newSelection.pY2 < app.file.viewedRectangle.pY2 && newSelection.pY2 < oldSelection.pY2)
scrollY = newSelection.pY2 - app.file.viewedRectangle.pY2 - spacingY;
if (newSelection.pY2 > app.file.viewedRectangle.pY2 && newSelection.pY2 > oldSelection.pY2)
scrollY = newSelection.pY2 - app.file.viewedRectangle.pY2 + spacingY;
else if (newSelection.pY1 < app.file.viewedRectangle.pY1 && newSelection.pY1 < oldSelection.pY1)
scrollY = newSelection.pY1 - app.file.viewedRectangle.pY1 - spacingY;
if (scrollX !== 0 || scrollY !== 0) {
var newCenter = new app.definitions.simplePoint(app.file.viewedRectangle.center[0], app.file.viewedRectangle.center[1]);
newCenter.pX += scrollX;
Expand Down
44 changes: 43 additions & 1 deletion cypress_test/integration_tests/desktop/calc/scrolling_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe it cy beforeEach require */
/* global describe it cy beforeEach expect require */

var helper = require('../../common/helper');
var desktopHelper = require('../../common/desktop_helper');
Expand Down Expand Up @@ -28,4 +28,46 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Scroll through document',
cy.wait(500);
desktopHelper.assertScrollbarPosition('horizontal', 250, 320);
});

it('Scroll while selecting vertically', function() {
desktopHelper.assertScrollbarPosition('vertical', 19, 21);

// Click on a cell near the edge of the view
cy.cGet('#map')
.then(function(items) {
expect(items).to.have.lengthOf(1);
var XPos = items[0].getBoundingClientRect().right - 280;
var YPos = items[0].getBoundingClientRect().bottom - 60;
cy.cGet('body').click(XPos, YPos);
});

// Select cells downwards with shift + arrow
for (let i = 0; i < 10; ++i) {
helper.typeIntoDocument('{shift}{downArrow}');
}

// Document should scroll
desktopHelper.assertScrollbarPosition('vertical', 50, 60);
});

it('Scroll while selecting horizontally', function() {
desktopHelper.assertScrollbarPosition('horizontal', 48, 60);

// Click on a cell near the edge of the view
cy.cGet('#map')
.then(function(items) {
expect(items).to.have.lengthOf(1);
var XPos = items[0].getBoundingClientRect().right - 280;
var YPos = items[0].getBoundingClientRect().bottom - 60;
cy.cGet('body').click(XPos, YPos);
});

// Select cells to the right with shift + arrow
for (let i = 0; i < 10; ++i) {
helper.typeIntoDocument('{shift}{rightArrow}');
}

// Document should scroll
desktopHelper.assertScrollbarPosition('horizontal', 160, 170);
});
});

0 comments on commit 58c04b7

Please sign in to comment.