()
| 46 | } |
| 47 | |
| 48 | export function focusedBlockId(): string { |
| 49 | const focused = document.activeElement; |
| 50 | if (focused instanceof HTMLElement) { |
| 51 | const blockId = findBlockId(focused); |
| 52 | if (blockId) { |
| 53 | return blockId; |
| 54 | } |
| 55 | } |
| 56 | const sel = document.getSelection(); |
| 57 | if (sel && sel.anchorNode && sel.rangeCount > 0 && !sel.isCollapsed) { |
| 58 | let anchor = sel.anchorNode; |
| 59 | if (anchor instanceof Text) { |
| 60 | anchor = anchor.parentElement; |
| 61 | } |
| 62 | if (anchor instanceof HTMLElement) { |
| 63 | const blockId = findBlockId(anchor); |
| 64 | if (blockId) { |
| 65 | return blockId; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | return null; |
| 70 | } |
no test coverage detected