diff --git a/src/components/area/AreaEditor.vue b/src/components/area/AreaEditor.vue index 1413a14..ca69f9d 100644 --- a/src/components/area/AreaEditor.vue +++ b/src/components/area/AreaEditor.vue @@ -39,7 +39,8 @@ :grayed="!isActive" :focused="isFocused(section)" @pointerdown="selectionEl.cellDown($event)" - @overcell="onOverCell" + @overgridcell="onOverGridCell" + @leavegridcell="onLeaveGridCell" /> @@ -71,7 +72,7 @@ const props = defineProps({ grayed: { type: Boolean, default: false }, focused: { type: Boolean, default: false }, }) -defineEmit(['pointerdown', 'overcell']) +defineEmit(['pointerdown', 'overgridcell', 'overgridcell']) import { computed } from 'vue' diff --git a/src/components/props/AreaGridTemplateProps.vue b/src/components/props/AreaGridTemplateProps.vue index f03ed10..90f358b 100644 --- a/src/components/props/AreaGridTemplateProps.vue +++ b/src/components/props/AreaGridTemplateProps.vue @@ -4,7 +4,7 @@

grid-template-columns

- add+ + add+

grid-template-rows

- add+ + add+
0) + area.children.forEach((child) => { + const [startRow, startCol, endRow, endCol] = child.gridArea.split(' / ') + if (colIndex < Number(startCol)) + child.gridArea = `${startRow} / ${Number(startCol) + 1} / ${endRow} / ${Number(endCol) + 1}` + else if (colIndex < Number(endCol)) + child.gridArea = `${startRow} / ${startCol} / ${endRow} / ${Number(endCol) + 1}` + }) } -export function addRow(grid, rowStr) { - addToDimension(grid.row, rowStr) +export function addRow(area, rowStr) { + const rowIndex = area.grid.hover?.row || -1 + addToDimension(area.grid.row, rowIndex, rowStr) + if (rowIndex > 0) + area.children.forEach((child) => { + const [startRow, startCol, endRow, endCol] = child.gridArea.split(' / ') + if (rowIndex < Number(startRow)) + child.gridArea = `${Number(startRow) + 1} / ${startCol} / ${Number(endRow) + 1} / ${endCol}` + else if (rowIndex < Number(endRow)) + child.gridArea = `${startRow} / ${startCol} / ${Number(endRow) + 1} / ${endCol}` + }) } function reduceLimit(l) { diff --git a/src/utils/keyMonitor.js b/src/utils/keyMonitor.js index 6b70083..9df5e89 100644 --- a/src/utils/keyMonitor.js +++ b/src/utils/keyMonitor.js @@ -4,6 +4,7 @@ import { canRedo, canUndo, currentArea, + overArea, deselectCurrentArea, mainArea, redo, @@ -37,6 +38,7 @@ function ctrlMetaKeyHandler(event) { } function keyHandler(event) { + const targetArea = overArea?.value || currentArea.value switch (event.key.toLowerCase()) { case 'backspace': case 'delete': @@ -50,14 +52,10 @@ function keyHandler(event) { } break case 'r': - if (currentArea?.value?.grid) { - addRow(currentArea.value.grid, '1fr') - } + if (targetArea.display === 'grid') addRow(targetArea, '1fr') break case 'c': - if (currentArea?.value?.grid) { - addCol(currentArea.value.grid, '1fr') - } + if (targetArea.display === 'grid') addCol(targetArea, '1fr') break case 'escape': if (currentArea.value !== mainArea.value) {