Skip to content

Commit b49cd12

Browse files
committed
chore: allow subselection of text in cell, change shift enter behaviour
1 parent fcb9775 commit b49cd12

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/frontend/src/pages/Tile/components/TableRow/TableCell.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useContextMenuContext } from '../../contexts/ContextMenuContext'
2323
import { useRowContext } from '../../contexts/RowContext'
2424
import { useTableContext } from '../../contexts/TableContext'
2525
import { moveCell } from '../../helpers/cell-navigation'
26+
import { addLineBreak } from '../../helpers/line-break'
2627
import { shallowCompare } from '../../helpers/shallow-compare'
2728
import { CellType, GenericRowData } from '../../types'
2829

@@ -88,11 +89,13 @@ function TableCell({
8889
*/
8990
switch (e.key) {
9091
case 'Enter': {
91-
if (e.shiftKey) {
92-
return
93-
}
9492
e.preventDefault()
9593
if (!isViewMode) {
94+
// Allow Alt+Enter to add new line
95+
if (e.altKey) {
96+
addLineBreak(e.currentTarget as HTMLTextAreaElement)
97+
return
98+
}
9699
if (row.id === NEW_ROW_ID || rowIndex === -1) {
97100
if (
98101
!shallowCompare(tableMeta?.tempRowData.current, {
@@ -110,7 +113,7 @@ function TableCell({
110113
row,
111114
rowIndex,
112115
columnIndex,
113-
direction: 'down',
116+
direction: e.shiftKey ? 'up' : 'down',
114117
allowCrossBoundaries: true,
115118
})
116119
break
@@ -260,7 +263,6 @@ function TableCell({
260263
}}
261264
ref={cellContainerRef}
262265
className={styles.cell}
263-
onClick={startEditing}
264266
onContextMenu={!isViewMode ? onContextMenu : undefined}
265267
>
266268
{/* if editing new row, show text area for all cells in the row */}
@@ -297,6 +299,7 @@ function TableCell({
297299
/>
298300
) : (
299301
<div
302+
onClick={startEditing}
300303
style={{
301304
display: 'flex',
302305
height: '100%',
@@ -307,6 +310,7 @@ function TableCell({
307310
wordBreak: 'break-word',
308311
fontSize: '0.875rem',
309312
cursor: 'cell',
313+
310314
backgroundColor: isHighlightingCell
311315
? 'var(--chakra-colors-orange-200)'
312316
: hasMatchingSearch
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function addLineBreak(element: HTMLTextAreaElement) {
2+
const start = element.selectionStart
3+
const end = element.selectionEnd
4+
const value = element.value
5+
6+
element.value = value.substring(0, start) + '\n' + value.substring(end)
7+
element.selectionStart = element.selectionEnd = start + 1
8+
}

0 commit comments

Comments
 (0)