mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
69c2f09eba
## Description Fixes keyboard shortcuts for text formatting (Ctrl+B, Ctrl+I, Ctrl+U, etc.) not working inside table cells. ## Changes - **Modified `table-cell.ts`**: Updated the `_handleKeyDown` method to only prevent default behavior for Tab key and allow other keyboard events to propagate, enabling text formatting shortcuts to work properly - **Created `table-keymap.ts`**: New module that registers the `textKeymap` for table blocks, ensuring text formatting shortcuts are available in table cells - **Updated `view.ts`**: Registered the `TableKeymapExtension` in the table view extension setup - **Cleaned up `format.ts`**: Removed unnecessary `TextSelection` check that was preventing shortcuts from working in table contexts ## Closes Closes #13916 #12127 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved Tab key handling within table cells for more consistent keyboard navigation. * Simplified read-only detection for keyboard shortcuts to avoid unexpected behavior. * **Refactor** * Reworked table keyboard mapping and registration to streamline shortcut handling and event flow. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
30 lines
823 B
TypeScript
30 lines
823 B
TypeScript
import { type BlockStdScope, type UIEventHandler } from '@blocksuite/std';
|
|
|
|
import { textFormatConfigs } from '../command/index.js';
|
|
|
|
export const textFormatKeymap = (std: BlockStdScope) =>
|
|
textFormatConfigs
|
|
.filter(config => config.hotkey)
|
|
.reduce(
|
|
(acc, config) => {
|
|
return {
|
|
...acc,
|
|
[config.hotkey as string]: ctx => {
|
|
const { store: doc } = std;
|
|
if (doc.readonly) return;
|
|
|
|
const allowed = config.textChecker?.(std.host) ?? true;
|
|
if (!allowed) return;
|
|
|
|
const event = ctx.get('keyboardState').raw;
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
|
|
config.action(std.host);
|
|
return true;
|
|
},
|
|
};
|
|
},
|
|
{} as Record<string, UIEventHandler>
|
|
);
|