Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/component/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ function insertDeleteRowColumn(type) {
if (data.settings.mode === 'read') return;
if (type === 'insert-row') {
data.insert('row');
} else if (type === 'insert-row-below') {
data.insertRowBelow();
} else if (type === 'delete-row') {
data.delete('row');
} else if (type === 'insert-column') {
Expand Down Expand Up @@ -831,6 +833,11 @@ function sheetInitEvents() {
break;
case 13: // enter
editor.clear();
const { eri } = this.selector.range;
const rows = this.data.rows;
if (eri === rows.len - 1 && !shiftKey) {
insertDeleteRowColumn.call(this, 'insert-row-below');
}
// shift + enter => move up
// enter => move down
selectorMove.call(this, false, shiftKey ? 'up' : 'down');
Expand Down
14 changes: 14 additions & 0 deletions src/core/data_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,20 @@ export default class DataProxy {
});
}

insertRowBelow(n = 1) {
this.changeData(() => {
const { sri } = this.selector.range;
const { rows, merges } = this;
let si = sri;
rows.insertBelow(sri, n);
merges.shift('row', si, n, (ri, ci, rn, cn) => {
const cell = rows.getCell(ri, ci);
cell.merge[0] += rn;
cell.merge[1] += cn;
});
});
}

// type: row | column
delete(type) {
this.changeData(() => {
Expand Down
18 changes: 18 additions & 0 deletions src/core/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ class Rows {
this.len += n;
}

insertBelow(sri, n = 1) {
const ndata = {};
this.each((ri, row) => {
let nri = parseInt(ri, 10);
if (nri > sri) {
nri += n;
this.eachCells(ri, (ci, cell) => {
if (cell.text && cell.text[0] === '=') {
cell.text = cell.text.replace(/[a-zA-Z]{1,3}\d+/g, word => expr2expr(word, 0, n, (x, y) => y >= sri));
}
});
}
ndata[nri] = row;
});
this._ = ndata;
this.len += n;
}

delete(sri, eri) {
const n = eri - sri + 1;
const ndata = {};
Expand Down