Skip to content

Commit

Permalink
autoscroll cell selection bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
stevewirts committed Jan 6, 2015
1 parent b399977 commit d057aab
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 36 deletions.
2 changes: 1 addition & 1 deletion behaviors/fin-hypergrid-behavior-default.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
this.fixedColIndexes = this.fixedColIndexes || [],
this.values = {}; //for overriding with edit values;
this.setNextFeature(document.createElement('fin-hypergrid-feature-column-resizing'));
this.setNextFeature(document.createElement('fin-hypergrid-feature-column-moving'));
this.setNextFeature(document.createElement('fin-hypergrid-feature-cell-selection'));
this.setNextFeature(document.createElement('fin-hypergrid-feature-column-moving'));
this.setNextFeature(document.createElement('fin-hypergrid-feature-thumbwheel-scrolling'));
this.setNextFeature(document.createElement('fin-hypergrid-feature-cell-editing'));
this.setNextFeature(document.createElement('fin-hypergrid-feature-column-sorting'));
Expand Down
45 changes: 23 additions & 22 deletions features/fin-hypergrid-feature-cell-selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@

Polymer({ /* jshint ignore:line */

/**
* scrollingNow is true if we are scrolling now or false otherwise
*
* @property scrollingNow
* @type boolean
*/
scrollingNow: false,

/**
* currentDrag is the pixel location of the mouse pointer during a drag operation
*
Expand All @@ -43,14 +35,6 @@
*/
lastDragCell: null,

/**
* answers if we are dragging right now
*
* @property dragging
* @type Boolean
*/
dragging: null,

/**
* sbLastAuto is a millisecond value representing the previous time an autoscroll started
*
Expand All @@ -72,28 +56,45 @@
createdInit: function() {

this.rectangles = document.createElement('fin-rectangle');
this.dragging = false;

},

handleMouseUp: function(grid, event) {
this.dragging = false;
if (this.next) {
this.next.handleMouseUp(grid, event);
}
},

handleMouseDown: function(grid, event) {
var gridCell = event.gridCell;
if (gridCell.y < grid.getFixedRowCount()) {
grid.clearSelections();
this.dragging = false;
if (this.next) {
this.next.handleMouseDown(grid, event);
}
return;
} else if (gridCell.x < grid.getFixedColCount()) {
grid.clearSelections();
this.dragging = false;
return;
}
else {
var primEvent = event.primitiveEvent;
var keys = primEvent.detail.keys;
this.dragging = true;
this.extendSelection(grid, gridCell, keys);
}
},

handleMouseDrag: function(grid, event) {
var mouseDown = grid.getMouseDown();
if (!this.dragging) {
if (this.next) {
this.next.handleMouseDrag(grid, event);
}
}
if (mouseDown.x < 0 || mouseDown.y < 0) {
//we are in the fixed area don't initiate a drag
return;
Expand Down Expand Up @@ -166,11 +167,11 @@
var b = grid.getDataBounds();
var inside = b.contains(mouse);
if (inside) {
if (this.scrollingNow) {
this.scrollingNow = false;
if (grid.scrollingNow) {
grid.scrollingNow = false;
}
} else if (!this.scrollingNow) {
this.scrollingNow = true;
} else if (!grid.scrollingNow) {
grid.scrollingNow = true;
this.scrollDrag(grid);
}
},
Expand All @@ -184,7 +185,7 @@
* @method scrollDrag()
*/
scrollDrag: function(grid) {
if (!this.scrollingNow) {
if (!grid.scrollingNow) {
return;
}
var b = grid.getDataBounds();
Expand Down
8 changes: 5 additions & 3 deletions features/fin-hypergrid-feature-column-moving.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
handleMouseDrag: function(grid, event) {

var gridCell = event.gridCell;
//var scrollLeft = grid.getHScrollValue();

var x, y;

if (this.isFixedCol(grid, event)) {
return; //no rearranging fixed columns
}

if (this.isFixedRow(grid,event) && this.dragArmed && !this.dragging) {
this.dragging = true;
this.dragCol = gridCell.x - grid.getFixedColCount();
Expand All @@ -44,7 +46,7 @@
if (this.dragging) {
x = event.primitiveEvent.detail.mouse.x - this.dragOffset;
y = event.primitiveEvent.detail.mouse.y;
grid.dragColumn(x, this.dragCol);
grid.dragColumn(x);
}
},

Expand Down
2 changes: 1 addition & 1 deletion features/fin-hypergrid-feature-column-sorting.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
},
handleMouseMove: function(grid, event) {
if (this.isFixedRow(grid, event)) {
if (this.isFixedRow(grid, event) && !this.isFixedCol(grid, event)) {
this.cursor = 'pointer';
} else {
this.cursor = null;
Expand Down
22 changes: 18 additions & 4 deletions fin-hypergrid.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#dragger {
position: absolute;
display: none;
opacity: 0.75;
}
#floatColumn {
position: absolute;
Expand Down Expand Up @@ -396,6 +397,7 @@
*/
clearMouseDown: function() {
this.mouseDown = [this.rectangles.point.create(-1, -1)];
this.dragExtent = null;
},

/**
Expand Down Expand Up @@ -1631,6 +1633,14 @@
return this.getBehavior().getFixedColWidth(colIndex);
},

getFixedColsWidth: function() {
return this.getBehavior().getFixedColsWidth();
},

getFixedRowsHeight: function() {
return this.getBehavior().getFixedRowsHeight();
},

setFixedColumnWidth: function(colIndex, colWidth) {
this.getBehavior().setFixedColumnWidth(colIndex, colWidth);
},
Expand Down Expand Up @@ -1798,21 +1808,25 @@

},
dragColumn: function(x) {

var minX = this.getFixedColsWidth();
x = Math.max(minX, x);
var dragColumnIndex = this.columnRenderOverridesCache.dragger.colIndex;
var atMin = x === minX && dragColumnIndex !== 0;
var d = this.dragger;
// var numFixedCols = this.getFixedColCount();
d.style.webkitTransition = '';
d.style.transition = '';
d.style.webkitTransform = 'translate(' + x + 'px, ' + 0 + 'px)';
d.style.display = 'inline';
var overCol = this.renderer.getColumnFromPixelX(x + (d.width / 2));

//console.log(x + ' Im ' + dragColumnIndex + ' over ' + overCol);

if (atMin) {
overCol = 0;
}
var colDif = overCol - dragColumnIndex;
var columnDragDirection = colDif > 1;
var threshold = columnDragDirection ? 1 : 0;
if (colDif > 1 || colDif < 0) {
if (colDif > 1 || colDif < 0 || atMin) {
this.createFloatColumn(overCol - threshold);
this.floatColumnTo(columnDragDirection);
}
Expand Down
21 changes: 17 additions & 4 deletions fin-hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
*/
clearMouseDown: function() {
this.mouseDown = [this.rectangles.point.create(-1, -1)];
this.dragExtent = null;
},

/**
Expand Down Expand Up @@ -1514,6 +1515,14 @@
return this.getBehavior().getFixedColWidth(colIndex);
},

getFixedColsWidth: function() {
return this.getBehavior().getFixedColsWidth();
},

getFixedRowsHeight: function() {
return this.getBehavior().getFixedRowsHeight();
},

setFixedColumnWidth: function(colIndex, colWidth) {
this.getBehavior().setFixedColumnWidth(colIndex, colWidth);
},
Expand Down Expand Up @@ -1681,21 +1690,25 @@

},
dragColumn: function(x) {

var minX = this.getFixedColsWidth();
x = Math.max(minX, x);
var dragColumnIndex = this.columnRenderOverridesCache.dragger.colIndex;
var atMin = x === minX && dragColumnIndex !== 0;
var d = this.dragger;
// var numFixedCols = this.getFixedColCount();
d.style.webkitTransition = '';
d.style.transition = '';
d.style.webkitTransform = 'translate(' + x + 'px, ' + 0 + 'px)';
d.style.display = 'inline';
var overCol = this.renderer.getColumnFromPixelX(x + (d.width / 2));

//console.log(x + ' Im ' + dragColumnIndex + ' over ' + overCol);

if (atMin) {
overCol = 0;
}
var colDif = overCol - dragColumnIndex;
var columnDragDirection = colDif > 1;
var threshold = columnDragDirection ? 1 : 0;
if (colDif > 1 || colDif < 0) {
if (colDif > 1 || colDif < 0 || atMin) {
this.createFloatColumn(overCol - threshold);
this.floatColumnTo(columnDragDirection);
}
Expand Down
2 changes: 1 addition & 1 deletion fin-hypergrid.min.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions fin-hypergrid.pre.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#dragger {
position: absolute;
display: none;
opacity: 0.75;
}
#floatColumn {
position: absolute;
Expand Down

0 comments on commit d057aab

Please sign in to comment.