Skip to content

Commit

Permalink
work in progress - fix position of editor in fixed rows/columns when …
Browse files Browse the repository at this point in the history
…scrolled far from top-left corner (issue #1942 is reproducible here and fix from branch `feature/issue-1942` does not solve it because scrollToRenderedCell scrolls the master table)
  • Loading branch information
warpech committed Jan 9, 2015
1 parent 8e493e4 commit ecc3cc4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/3rdparty/walkontable/src/scroll.js
Expand Up @@ -22,9 +22,9 @@ WalkontableScroll.prototype.scrollViewport = function (coords) {
throw new Error('column ' + coords.col + ' does not exist');
}

var TD = this.instance.wtTable.getCell(coords);
var TD = this.instance.getCell(coords, true);
if (typeof TD === 'object') {
if (coords.col >= this.instance.getSetting('fixedColumnsLeft')) {
if (coords.col >= this.instance.getSetting('fixedColumnsLeft') && coords.row >= this.instance.getSetting('fixedRowsTop')) {
this.scrollToRenderedCell(TD);
}
} else {
Expand Down Expand Up @@ -82,10 +82,12 @@ WalkontableScroll.prototype.scrollToRenderedCell = function (TD) {
if (cellWidth < workspaceWidth) {
if (cellOffset.left < viewportScrollPosition.left + leftCloneWidth) {
this.instance.wtScrollbars.horizontal.setScrollPosition(cellOffset.left - leftCloneWidth);
this.instance.wtScrollbars.horizontal.onScroll();
}
else if (cellOffset.left + cellWidth > workspaceOffset.left + viewportScrollPosition.left + workspaceWidth) {
var delta = (cellOffset.left + cellWidth) - (workspaceOffset.left + viewportScrollPosition.left + workspaceWidth);
this.instance.wtScrollbars.horizontal.setScrollPosition(viewportScrollPosition.left + delta);
this.instance.wtScrollbars.horizontal.onScroll();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/3rdparty/walkontable/src/scrollbarNativeHorizontal.js
Expand Up @@ -103,7 +103,8 @@ WalkontableHorizontalScrollbarNative.prototype.scrollTo = function (sourceCol, b
newX -= this.instance.wtViewport.getViewportWidth()
}
else {
newX += this.sumCellSizes(0, sourceCol);
var fixedColumnsLeft = this.instance.getSetting('fixedColumnsLeft');
newX += this.sumCellSizes(fixedColumnsLeft, sourceCol);
}

this.setScrollPosition(newX);
Expand Down
3 changes: 2 additions & 1 deletion src/3rdparty/walkontable/src/scrollbarNativeVertical.js
Expand Up @@ -105,7 +105,8 @@ WalkontableVerticalScrollbarNative.prototype.scrollTo = function (sourceRow, bot
newY -= this.instance.wtViewport.getViewportHeight();
}
else {
newY += this.sumCellSizes(0, sourceRow);
var fixedRowsTop = this.instance.getSetting('fixedRowsTop');
newY += this.sumCellSizes(fixedRowsTop, sourceRow);
}

this.setScrollPosition(newY);
Expand Down
87 changes: 70 additions & 17 deletions test/jasmine/spec/editors/textEditorSpec.js
Expand Up @@ -531,7 +531,7 @@ describe('TextEditor', function () {
// corner
selectCell(1, 1);
keyDown(Handsontable.helper.keyCode.ENTER);
$inputHolder = $('.handsontableInputHolder');
var $inputHolder = $('.handsontableInputHolder');
expect($(getCell(1,1)).offset().left).toEqual($inputHolder.offset().left + 1);
expect($(getCell(1,1)).offset().top).toEqual($inputHolder.offset().top + 1);

Expand All @@ -556,13 +556,12 @@ describe('TextEditor', function () {
this.$container.scrollTop(1000);
});

it("should open editor at the same coordinates as the edited cell after the table had been scrolled", function() {
it("should open editor at the same coordinates as the edited cell after the table had been scrolled (corner)", function() {
var hot = handsontable({
data: Handsontable.helper.createSpreadsheetData(16, 8),
fixedColumnsLeft: 2,
fixedRowsTop: 2
})
, currentCell = null;
});

this.$container.scrollTop(100);
this.$container.scrollLeft(100);
Expand All @@ -571,32 +570,86 @@ describe('TextEditor', function () {

// corner
selectCell(1, 1);
var currentCell = hot.getCell(1, 1, true);
var left = $(currentCell).offset().left;
var top = $(currentCell).offset().top;

var $inputHolder = $('.handsontableInputHolder');
keyDown(Handsontable.helper.keyCode.ENTER);
currentCell = hot.view.wt.wtScrollbars.corner.clone.wtTable.getCell({row: 1, col: 1});
$inputHolder = $('.handsontableInputHolder');
expect($(currentCell).offset().left).toEqual($inputHolder.offset().left + 1);
expect($(currentCell).offset().top).toEqual($inputHolder.offset().top + 1);
expect(left).toEqual($inputHolder.offset().left + 1);
expect(top).toEqual($inputHolder.offset().top + 1);
});

it("should open editor at the same coordinates as the edited cell after the table had been scrolled (top)", function() {
var hot = handsontable({
data: Handsontable.helper.createSpreadsheetData(50, 50),
fixedColumnsLeft: 2,
fixedRowsTop: 2
});

this.$container.scrollTop(500);
this.$container.scrollLeft(500);

hot.render();

// top
selectCell(1, 6);
var currentCell = hot.getCell(1, 6, true);
var left = $(currentCell).offset().left;
var top = $(currentCell).offset().top;

var $inputHolder = $('.handsontableInputHolder');
keyDown(Handsontable.helper.keyCode.ENTER);
currentCell = hot.view.wt.wtScrollbars.vertical.clone.wtTable.getCell({row: 1, col: 6});
expect($(currentCell).offset().left).toEqual($inputHolder.offset().left + 1);
expect($(currentCell).offset().top).toEqual($inputHolder.offset().top + 1);
expect(left).toEqual($inputHolder.offset().left + 1);
expect(top).toEqual($inputHolder.offset().top + 1);
});

it("should open editor at the same coordinates as the edited cell after the table had been scrolled (left)", function() {
var hot = handsontable({
data: Handsontable.helper.createSpreadsheetData(50, 50),
fixedColumnsLeft: 2,
fixedRowsTop: 2
});

this.$container.scrollTop(500);
this.$container.scrollLeft(500);

hot.render();

// left
selectCell(6, 1);
var currentCell = hot.getCell(6, 1, true);
var left = $(currentCell).offset().left;
var top = $(currentCell).offset().top;

var $inputHolder = $('.handsontableInputHolder');
keyDown(Handsontable.helper.keyCode.ENTER);
currentCell = hot.view.wt.wtScrollbars.horizontal.clone.wtTable.getCell({row: 6, col: 1});
expect($(currentCell).offset().left).toEqual($inputHolder.offset().left + 1);
expect($(currentCell).offset().top).toEqual($inputHolder.offset().top + 1);
expect(left).toEqual($inputHolder.offset().left + 1);
expect(top).toEqual($inputHolder.offset().top + 1);
});

it("should open editor at the same coordinates as the edited cell after the table had been scrolled (non-fixed)", function() {
var hot = handsontable({
data: Handsontable.helper.createSpreadsheetData(50, 50),
fixedColumnsLeft: 2,
fixedRowsTop: 2
});

this.$container.scrollTop(500);
this.$container.scrollLeft(500);

hot.render();

// non-fixed
selectCell(7, 7);
var currentCell = hot.getCell(7, 7, true);
var left = $(currentCell).offset().left;
var top = $(currentCell).offset().top;

var $inputHolder = $('.handsontableInputHolder');
keyDown(Handsontable.helper.keyCode.ENTER);
currentCell = hot.view.wt.wtTable.getCell({row: 7, col: 7});
expect($(currentCell).offset().left).toEqual($inputHolder.offset().left + 1);
expect($(currentCell).offset().top).toEqual($inputHolder.offset().top + 1);
expect(left).toEqual($inputHolder.offset().left + 1);
expect(top).toEqual($inputHolder.offset().top + 1);
});

it("should display editor with the proper size, when the edited column is beyond the tables container", function() {
Expand Down

0 comments on commit ecc3cc4

Please sign in to comment.