diff options
author | 2023-04-16 01:46:27 +0800 | |
---|---|---|
committer | 2023-04-16 01:46:27 +0800 | |
commit | b484f069517c9c5e44c4a8a09aabc8050f2ea2fa (patch) | |
tree | ccbb147056a1c9e3515b1ccf578f526ae4f366dc /source/features/table-input.tsx | |
parent | dd2038e8f7b8afe8240aa372f1db86ff55c8a8c3 (diff) | |
download | refined-github-b484f069517c9c5e44c4a8a09aabc8050f2ea2fa.tar.gz refined-github-b484f069517c9c5e44c4a8a09aabc8050f2ea2fa.tar.zst refined-github-b484f069517c9c5e44c4a8a09aabc8050f2ea2fa.zip |
More ergonomic `table-input` HTML (#6516)23.4.15
Diffstat (limited to '')
-rw-r--r-- | source/features/table-input.tsx | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/source/features/table-input.tsx b/source/features/table-input.tsx index 65bfb2f8..d39a1402 100644 --- a/source/features/table-input.tsx +++ b/source/features/table-input.tsx @@ -15,13 +15,17 @@ function addTable({delegateTarget: square}: DelegateEvent<MouseEvent, HTMLButton const field = square.form!.querySelector('textarea.js-comment-field')!; const cursorPosition = field.selectionStart; + const columns = Number(square.dataset.x); + const rows = Number(square.dataset.y); + const row = columns === 1 + // One HTML line per row + ? '<tr><td>\n' + + // <tr> on its own line + // "1 space" indents without causing unwanted Markdown code blocks that 4 spaces would cause + : '<tr>\n' + ' <td>\n'.repeat(columns); field.focus(); - const table - = '<table>\n' - + ('<tr>\n' - + '\t<td>\n'.repeat(Number(square.dataset.x)) - ).repeat(Number(square.dataset.y)) - + '</table>'; + const table = '<table>\n' + row.repeat(rows) + '</table>'; textFieldEdit.insert(field, smartBlockWrap(table, field)); // Move caret to first cell |