Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs + enter direction #453

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/component/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function selectorSet(multiple, ri, ci, indexesUpdated = true, moving = false) {
// direction: left | right | up | down | row-first | row-last | col-first | col-last
function selectorMove(multiple, direction) {
const {
selector, data,
selector, data, contTabsPressed
} = this;
const { rows, cols } = data;
let [ri, ci] = selector.indexes;
Expand All @@ -113,6 +113,9 @@ function selectorMove(multiple, direction) {
ri = 0;
} else if (direction === 'col-last') {
ri = rows.len - 1;
} else if (direction === 'tabs+enter'){
if (ri < rows.len - 1) ri += 1;
ci = Math.max(0, ci - contTabsPressed.n)
}
if (multiple) {
selector.moveIndexes = [ri, ci];
Expand Down Expand Up @@ -579,6 +582,7 @@ function sheetInitEvents() {
modalValidation,
sortFilter,
} = this;
let { contTabsPressed } = this;
// overlayer
overlayerEl
.on('mousemove', (evt) => {
Expand Down Expand Up @@ -691,6 +695,11 @@ function sheetInitEvents() {

bind(window, 'click', (evt) => {
this.focusing = overlayerEl.contains(evt.target);
const {ri, ci} = contTabsPressed.lastCurrentCell;
if(this.focusing && (ri != this.data.selector.ri || this.data.selector.ci - ci != 1)) {
contTabsPressed = {n: 0, lastCurrentCell: { ri: this.data.selector.ri, ci: this.data.selector.ci}}
this.contTabsPressed = contTabsPressed;
}
});

bind(window, 'paste', (evt) => {
Expand Down Expand Up @@ -812,14 +821,23 @@ function sheetInitEvents() {
editor.clear();
// shift + tab => move left
// tab => move right
if(!shiftKey){
const {ri, ci} = contTabsPressed.lastCurrentCell;
if(contTabsPressed.n == 0 || ri != this.data.selector.ri || this.data.selector.ci - ci != 1)
contTabsPressed = {n: 1, lastCurrentCell: { ri: this.data.selector.ri, ci: this.data.selector.ci}}
else
if(this.data.selector.ci < this.data.cols.len - 1)
contTabsPressed = {n: contTabsPressed.n + 1, lastCurrentCell: { ri: this.data.selector.ri, ci: this.data.selector.ci}}
this.contTabsPressed = contTabsPressed;
}
selectorMove.call(this, false, shiftKey ? 'left' : 'right');
evt.preventDefault();
break;
case 13: // enter
editor.clear();
// shift + enter => move up
// enter => move down
selectorMove.call(this, false, shiftKey ? 'up' : 'down');
selectorMove.call(this, false, shiftKey ? 'up' : (contTabsPressed.n > 0 ? 'tabs+enter' : 'down'));
evt.preventDefault();
break;
case 8: // backspace
Expand All @@ -830,6 +848,9 @@ function sheetInitEvents() {
break;
}

if([32,37,38,39,40,13].includes(keyCode))
contTabsPressed.n = 0;

if (key === 'Delete') {
insertDeleteRowColumn.call(this, 'delete-cell-text');
evt.preventDefault();
Expand Down Expand Up @@ -884,6 +905,13 @@ export default class Sheet {
);
this.overlayerEl = h('div', `${cssPrefix}-overlayer`)
.child(this.overlayerCEl);
this.contTabsPressed = {
n: 0,
lastCurrentCell : {
ri: null,
ci: null,
}
};
// sortFilter
this.sortFilter = new SortFilter();
// root element
Expand Down