calc: avoid jumping on large cell selection

If we had very long or tall cell - maybe bigger than a screen
on every selection we tried to show it on the screen what
caused view to jump. If cell is bigger and partially visible
left view at the same position to avoid "jumping".

Steps to reproduce:
1. merge many cells - longer than one screen width
2. scroll in the middle of merged cell
3. select the cell
Result: jump to the begining
Expected: no jump if it is paritally visible

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I04da5cd346f175728222888a039a796b271e00d1
This commit is contained in:
Szymon Kłos 2023-12-21 15:19:02 +01:00 committed by Tomaž Vajngerl
parent 74d78d287a
commit a4add51e93
6 changed files with 56 additions and 2 deletions

View file

@ -97,6 +97,14 @@ L.LatLngBounds.prototype = {
return this._northEast.lat;
},
getWidth: function () {
return this.getEast() - this.getWest();
},
getHeight: function () {
return this.getNorth() - this.getSouth();
},
contains: function (obj) { // (LatLngBounds) or (LatLng) -> Boolean
if (typeof obj[0] === 'number' || obj instanceof L.LatLng) {
obj = L.latLng(obj);

View file

@ -1098,6 +1098,22 @@ L.CalcTileLayer = L.CanvasTileLayer.extend({
return scroll; // no scroll needed.
}
var noSplit = !this._splitPanesContext
|| this._splitPanesContext.getSplitPos().equals(new L.Point(0, 0));
if (noSplit && this._cellCursor.intersects(paneRectsInLatLng[0])) {
// Check if target cell is bigger than screen but partially visible
// TODO: handle with split panes
var cellWidth = this._cellCursor.getWidth();
var paneWidth = paneRectsInLatLng[0].getWidth();
var cellHeight = this._cellCursor.getHeight();
var paneHeight = paneRectsInLatLng[0].getHeight();
if (cellWidth > paneWidth || cellHeight > paneHeight)
return scroll; // no scroll needed.
}
var freePaneBounds = paneRectsInLatLng[paneRectsInLatLng.length - 1];
var splitPoint = map.unproject(this._splitPanesContext ? this._splitPanesContext.getSplitPos() : new L.Point(0, 0));

View file

@ -4587,6 +4587,8 @@ L.CanvasTileLayer = L.Layer.extend({
this._updateCursorAndOverlay();
},
// TODO: unused variables: horizontalDirection, verticalDirection
// TODO: used only in calc: move to CalcTileLayer
_onUpdateCellCursor: function (horizontalDirection, verticalDirection, onPgUpDn, scrollToCursor) {
this._onUpdateCellResizeMarkers();
if (this._cellCursor && !this._isEmptyRectangle(this._cellCursor)) {

Binary file not shown.

View file

@ -30,7 +30,7 @@ function clickFormulaBar() {
// one makes the document to step in cell editing.
// dblClick - to do a double click or not. The result of double click is that the cell
// editing it triggered both on desktop and mobile.
function clickOnFirstCell(firstClick = true, dblClick = false) {
function clickOnFirstCell(firstClick = true, dblClick = false, isA1 = true) {
cy.log('Clicking on first cell - start.');
cy.log('Param - firstClick: ' + firstClick);
cy.log('Param - dblClick: ' + dblClick);
@ -62,7 +62,8 @@ function clickOnFirstCell(firstClick = true, dblClick = false) {
});
}
cy.cGet('input#addressInput').should('have.prop', 'value', 'A1');
if (isA1)
cy.cGet('input#addressInput').should('have.prop', 'value', 'A1');
cy.log('Clicking on first cell - end.');
}

View file

@ -0,0 +1,27 @@
/* global describe it cy beforeEach require afterEach */
var helper = require('../../common/helper');
var calcHelper = require('../../common/calc_helper');
var desktopHelper = require('../../common/desktop_helper');
describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Scroll through document', function() {
var testFileName = 'cell_cursor.ods';
beforeEach(function() {
helper.beforeAll(testFileName, 'calc');
desktopHelper.switchUIToCompact();
cy.cGet('#toolbar-up .w2ui-scroll-right').click();
cy.cGet('#tb_editbar_item_sidebar').click();
});
afterEach(function() {
helper.afterAll(testFileName, this.currentTest.state);
});
it('No jump on long merged cell', function() {
desktopHelper.assertScrollbarPosition('horizontal', 310, 315);
calcHelper.clickOnFirstCell(true, false, false);
cy.cGet('input#addressInput').should('have.prop', 'value', 'A1:Z1');
desktopHelper.assertScrollbarPosition('horizontal', 310, 315);
});
});