Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 714fa0a

Browse files
committed
textCell keydown
1 parent d8222e5 commit 714fa0a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/components/cellTypes/TextCell.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import EditorCell from "components/cellTypes/EditorCell";
55
import { TableColumn } from "cdm/FolderModel";
66
import { c, getAlignmentClassname } from "helpers/StylesHelper";
77
import { ParseService } from "services/ParseService";
8-
import { InputType } from "helpers/Constants";
8+
import { InputType, SUGGESTER_REGEX } from "helpers/Constants";
99
import { MarkdownService } from "services/MarkdownRenderService";
1010

1111
const TextCell = (props: CellComponentProps) => {
@@ -39,7 +39,7 @@ const TextCell = (props: CellComponentProps) => {
3939
* Render markdown content of Obsidian on load
4040
*/
4141
useEffect(() => {
42-
if (dirtyCell && !containerCellRef.current && !textCell) {
42+
if (dirtyCell || (!containerCellRef.current && !textCell)) {
4343
// End useEffect
4444
return;
4545
}
@@ -52,7 +52,7 @@ const TextCell = (props: CellComponentProps) => {
5252
);
5353
}, [dirtyCell, textCell]);
5454

55-
const handleEditableOnclick: MouseEventHandler<HTMLSpanElement> = () => {
55+
const handleEditableOnclick = () => {
5656
setDirtyCell(true);
5757
};
5858

@@ -85,11 +85,21 @@ const TextCell = (props: CellComponentProps) => {
8585
) : (
8686
<span
8787
ref={containerCellRef}
88-
onClick={handleEditableOnclick}
88+
onDoubleClick={handleEditableOnclick}
89+
// On enter key press
90+
onKeyDown={(e) => {
91+
if (SUGGESTER_REGEX.CELL_VALID_KEYDOWN.test(e.key)) {
92+
handleEditableOnclick();
93+
} else if (e.key === "Enter") {
94+
e.preventDefault();
95+
handleEditableOnclick();
96+
}
97+
}}
8998
style={{ width: column.getSize() }}
9099
className={c(
91100
getAlignmentClassname(tableColumn.config, configInfo.getLocalSettings())
92101
)}
102+
tabIndex={0}
93103
/>
94104
);
95105
};

src/helpers/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ export const SUGGESTER_REGEX = Object.freeze({
476476

477477
TEXT_ARRAY: /(^\[{1})([^\[]{1}.*)(\]{1})$/g,
478478
TEXT_OBJECT: /(^\{{1})(.*)(\}{1})$/g,
479+
480+
CELL_VALID_KEYDOWN: /([a-zA-Z0-9_\- ]{1})$/g,
479481
});
480482

481483
/******************************************************************************

styles.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
div.database-plugin__td.data-input:hover {
9393
box-shadow: 0 0 1px 2px var(--text-accent-hover);
9494
}
95+
div.database-plugin__td.data-input div:focus,
96+
div.database-plugin__td.data-input span:focus {
97+
box-shadow: 0 0 1px 2px var(--text-accent);
98+
}
9599

96100
/******************************************************
97101
* Table Structure
@@ -685,8 +689,8 @@ div.database-plugin__td.data-input:hover {
685689
}
686690

687691
.database-plugin__scroll-horizontal {
688-
overflow-y: auto;
689-
overflow-x: auto;
692+
overflow-y: overlay;
693+
overflow-x: overlay;
690694
}
691695

692696
.database-plugin__scroll-container {

0 commit comments

Comments
 (0)