statusExtension.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Extension, RawCommands } from "@tiptap/core";
  2. /**
  3. * 为什么需要这个扩展?
  4. * 此扩展用于管理和 SemiAIChatInput 有关的状态,避免 SemiAIChatInput 和其他扩展的行为冲突,举个例子:
  5. * 自定义的扩展需要通过 enter 实现快捷按键操作,会和 SemiAIChatInput 的发送热键有冲突,
  6. * 因此通过 editor 的 storage 存储 allowHotKeySend 的状态,扩展可以去设置这些状态,提示 SemiAIChatInput 是否需要响应热键
  7. * Why is this extension needed?
  8. * This extension is used to manage the state related to SemiAIChatInput and avoid behavioral conflicts between
  9. * SemiAIChatInput and other extensions. For example:
  10. * Custom extensions require shortcut key operations via Enter, which conflicts with SemiAIChatInput's send hotkey.
  11. * Therefore, by storing the allowHotKeySend state in the editor's storage,
  12. * the extension can set these states to indicate whether SemiAIChatInput needs to respond to hotkeys.
  13. */
  14. const SemiStatusExtension = Extension.create({
  15. name: 'SemiAIChatInput',
  16. addStorage() {
  17. return {
  18. allowHotKeySend: true,
  19. };
  20. },
  21. addCommands() {
  22. return {
  23. setAllowHotKeySendForSemiAIChatInput(allow: boolean) {
  24. return ({ storage }) => {
  25. storage.SemiAIChatInput.allowHotKeySend = allow;
  26. };
  27. }
  28. } as Partial<RawCommands>;
  29. }
  30. });
  31. export default SemiStatusExtension;