From dab573919e0664d70d52ae1abb2d182e58ec877a Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Tue, 19 Jul 2022 12:25:54 +0500 Subject: [PATCH] little hot fixes --- src/components/table/SelectionManager.ts | 17 ++++++++++++----- src/components/table/Table.ts | 12 ++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/components/table/SelectionManager.ts b/src/components/table/SelectionManager.ts index 5e3a801..1547be4 100644 --- a/src/components/table/SelectionManager.ts +++ b/src/components/table/SelectionManager.ts @@ -190,7 +190,7 @@ export class SelectionManager { }); } - getNeighbourCellBySide(side: 'left' | 'right' | 'down' | 'up', $cell = this.$currentSelectedCell): Dom | undefined { + getSiblingCellBySide(side: 'left' | 'right' | 'down' | 'up', $cell = this.$currentSelectedCell): Dom | undefined { if (!$cell?.isExist) { console.error('Нет стартовой ячейки'); return; @@ -235,7 +235,7 @@ export class SelectionManager { const $current = this.$currentSelectedCell || this.rootTable.focusManager.$currentFocusedCell || this.$currentSelectedCell?.[0]; if (!$current?.isExist) return; - const $movingCell = this.getNeighbourCellBySide(side, $current); + const $movingCell = this.getSiblingCellBySide(side, $current); if (!$movingCell?.isExist || !$movingCell) { console.error('Ошибка, не найдена ячейка для перемещения'); return; @@ -295,9 +295,16 @@ export class SelectionManager { this.$currentSelectedCell && this.rootTable.focusManager.focusCell(this.$currentSelectedCell); } + if (event.key === 'Enter' || event.key === 'Tab') { + let side; + + if (event.key === 'Enter' && !event.shiftKey) side = 'down'; + if (event.key === 'Tab') side = event.shiftKey ? 'left' : 'right'; + + side && this.moveSelectionTo(side); + } return; } - event.preventDefault(); let $cell: Dom | undefined; @@ -344,7 +351,7 @@ export class SelectionManager { if (!side) return; - $cell = this.getNeighbourCellBySide(side, this.$currentSelectedCell || this.$firstSelectedCell); + $cell = this.getSiblingCellBySide(side, this.$currentSelectedCell || this.$firstSelectedCell); if (event.ctrlKey && $cell?.isExist) { this.addCellToSelection($cell); @@ -362,7 +369,7 @@ export class SelectionManager { return; } - $cell = this.getNeighbourCellBySide(side, this.$firstSelectedCell || this.$currentSelectedCell); + $cell = this.getSiblingCellBySide(side, this.$firstSelectedCell || this.$currentSelectedCell); if (!$cell || !$cell.isExist) return; this.selectCell($cell); diff --git a/src/components/table/Table.ts b/src/components/table/Table.ts index cb79112..e1ddd4b 100644 --- a/src/components/table/Table.ts +++ b/src/components/table/Table.ts @@ -50,8 +50,16 @@ export class Table extends ExcelComponent { this.initTable(); - this.$onEventFromObserver('formula:input', this.updateTextInCell); - // this.$onEventFromObserver('formula:enter-press', () => this.selection.$currentCell.focus()); + this.$onEventFromObserver('formula:input', (text) => { + if (!this.focusManager.$currentFocusedCell) this.updateTextInCell(text, this.selectionManager.$currentSelectedCell, true); + else this.updateTextInCell(text, this.focusManager.$currentFocusedCell, true); + }); + + this.$onEventFromObserver('formula:enter-press', () => { + this.focusManager.focusCell(this.selectionManager.$currentSelectedCell); + this.updateTextInCell(this.selectionManager.$currentSelectedCell?.text, this.focusManager.$currentFocusedCell, false); + }); + this.$onEventFromObserver('toolbar:applyStyle', this.updateCurrentStyles); this.$onEventFromObserver('toolbar:add-row', this.addNewRowHandler); this.$onEventFromObserver('toolbar:remove-row', this.removeRowHandler);