Skip to content

Commit 134a6e2

Browse files
committed
feat: add listen tab
1 parent b55c54b commit 134a6e2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/components/TableEditor.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const TableEditor = ({ content = DEFAULT_TABLE, className = '' }, ref) => {
8585
ref,
8686
() => ({
8787
getEditorValue: () => value,
88+
onKeyup: (code) => console.log(code)
8889
}),
8990
)
9091

src/pages/App.jsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useState, useEffect } from 'react'
1+
import { useRef, useState, useEffect, useCallback } from 'react'
22
import { Button } from 'antd'
33
import { PlusOutlined } from '@ant-design/icons'
44

@@ -63,12 +63,26 @@ const App = ({ content, tables, blockId }) => {
6363
return _arr.concat({ type: 'table', str: DEFAULT_TABLE })
6464
})
6565
}
66+
const onKeyup = useCallback(e => {
67+
console.log('[faiz:] === keyup', e)
68+
if (e.code === 'Tab') {
69+
Object.keys(tableEditorMapRef.current).forEach(key => {
70+
tableEditorMapRef.current?.[key]?.onKeyup('Tab')
71+
})
72+
}
73+
}, [])
6674

6775
useEffect(() => {
6876
const arr = splitStrByTable(content, tables)
6977
setArrAfterSplitByTable(arr)
7078
console.log('[faiz:] === arrAfterSplitByTable', arr)
7179
}, [content, tables])
80+
useEffect(() => {
81+
document.addEventListener('keyup', onKeyup)
82+
return () => {
83+
document.removeEventListener('keyup', onKeyup)
84+
}
85+
}, [onKeyup])
7286

7387
return (
7488
<div className="w-screen h-screen flex flex-col justify-center items-center">

0 commit comments

Comments
 (0)