Merge pull request #152 from cschreier/master

#150 Enable horizontal scrolling with touchpad
This commit is contained in:
Jan Prochazka 2021-08-14 09:37:12 +02:00 committed by GitHub
commit 86eca6bc7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -171,7 +171,6 @@
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
return value;
}
</script>
<script lang="ts">
@ -666,43 +665,52 @@
function handleGridWheel(event) {
if (event.shiftKey) {
let newFirstVisibleColumnScrollIndex = firstVisibleColumnScrollIndex;
if (event.deltaY > 0) {
newFirstVisibleColumnScrollIndex++;
}
if (event.deltaY < 0) {
newFirstVisibleColumnScrollIndex--;
}
if (newFirstVisibleColumnScrollIndex > maxScrollColumn) {
newFirstVisibleColumnScrollIndex = maxScrollColumn;
}
if (newFirstVisibleColumnScrollIndex < 0) {
newFirstVisibleColumnScrollIndex = 0;
}
firstVisibleColumnScrollIndex = newFirstVisibleColumnScrollIndex;
domHorizontalScroll.scroll(newFirstVisibleColumnScrollIndex);
scrollHorizontal(event.deltaY, event.deltaX);
} else {
let newFirstVisibleRowScrollIndex = firstVisibleRowScrollIndex;
if (event.deltaY > 0) {
newFirstVisibleRowScrollIndex += wheelRowCount;
}
if (event.deltaY < 0) {
newFirstVisibleRowScrollIndex -= wheelRowCount;
}
let rowCount = grider.rowCount;
if (newFirstVisibleRowScrollIndex + visibleRowCountLowerBound > rowCount) {
newFirstVisibleRowScrollIndex = rowCount - visibleRowCountLowerBound + 1;
}
if (newFirstVisibleRowScrollIndex < 0) {
newFirstVisibleRowScrollIndex = 0;
}
firstVisibleRowScrollIndex = newFirstVisibleRowScrollIndex;
domVerticalScroll.scroll(newFirstVisibleRowScrollIndex);
scrollHorizontal(event.deltaX, event.deltaY);
scrollVertical(event.deltaX, event.deltaY);
}
}
function scrollVertical(deltaX, deltaY) {
let newFirstVisibleRowScrollIndex = firstVisibleRowScrollIndex;
if (deltaY > 0 && deltaX === -0) {
newFirstVisibleRowScrollIndex += wheelRowCount;
} else if (deltaY < 0 && deltaX === -0) {
newFirstVisibleRowScrollIndex -= wheelRowCount;
}
let rowCount = grider.rowCount;
if (newFirstVisibleRowScrollIndex + visibleRowCountLowerBound > rowCount) {
newFirstVisibleRowScrollIndex = rowCount - visibleRowCountLowerBound + 1;
}
if (newFirstVisibleRowScrollIndex < 0) {
newFirstVisibleRowScrollIndex = 0;
}
firstVisibleRowScrollIndex = newFirstVisibleRowScrollIndex;
domVerticalScroll.scroll(newFirstVisibleRowScrollIndex);
}
function scrollHorizontal(deltaX, deltaY) {
let newFirstVisibleColumnScrollIndex = firstVisibleColumnScrollIndex;
if (deltaX > 0 && deltaY === -0) {
newFirstVisibleColumnScrollIndex++;
} else if (deltaX < 0 && deltaY === -0) {
newFirstVisibleColumnScrollIndex--;
}
if (newFirstVisibleColumnScrollIndex > maxScrollColumn) {
newFirstVisibleColumnScrollIndex = maxScrollColumn;
}
if (newFirstVisibleColumnScrollIndex < 0) {
newFirstVisibleColumnScrollIndex = 0;
}
firstVisibleColumnScrollIndex = newFirstVisibleColumnScrollIndex;
domHorizontalScroll.scroll(newFirstVisibleColumnScrollIndex);
}
function getSelectedRowIndexes() {
if (selectedCells.find(x => x[0] == 'header')) return _.range(0, grider.rowCount);
return _.uniq((selectedCells || []).map(x => x[0])).filter(x => _.isNumber(x));
@ -980,7 +988,6 @@
);
const menu = getContextMenu();
</script>
{#if !display || (!isDynamicStructure && (!columns || columns.length == 0))}
@ -1001,7 +1008,13 @@
{/each}
</div>
{:else}
<div class="container" bind:clientWidth={containerWidth} bind:clientHeight={containerHeight} use:contextMenu={menu}>
<div
class="container"
bind:clientWidth={containerWidth}
bind:clientHeight={containerHeight}
use:contextMenu={menu}
on:wheel={handleGridWheel}
>
<input
type="text"
class="focus-field"
@ -1019,7 +1032,6 @@
on:mousedown={handleGridMouseDown}
on:mousemove={handleGridMouseMove}
on:mouseup={handleGridMouseUp}
on:wheel={handleGridWheel}
>
<thead>
<tr>
@ -1187,5 +1199,4 @@
right: 40px;
bottom: 20px;
}
</style>