Kaynağa Gözat

:sparkles: fix https://github.com/Vanessa219/vditor/issues/1397

Vanessa 2 yıl önce
ebeveyn
işleme
4b121a956d
5 değiştirilmiş dosya ile 10 ekleme ve 0 silme
  1. 2 0
      CHANGELOG.md
  2. 1 0
      README.md
  3. 1 0
      README_en_US.md
  4. 3 0
      src/ts/util/editorCommonEvent.ts
  5. 3 0
      types/index.d.ts

+ 2 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 ### 升级
 * 3.9
+  * 添加 option.keydown
   * 添加 option.link 和 options.image
   * 添加 hljs.defaultLang
 * 3.8
@@ -108,6 +109,7 @@
 
 ### v3.9.3 / 2023-05
 
+* [添加`keydown`回调](https://github.com/Vanessa219/vditor/issues/1397) `引入特性`
 * [输入内容后立即点击工具栏下拉无反应](https://github.com/Vanessa219/vditor/issues/1391) `改进功能`
 * [XSS 代码注入漏洞](https://github.com/Vanessa219/vditor/issues/1395) `修复缺陷`
 * [支持葡萄牙语](https://github.com/Vanessa219/vditor/pull/1394) `引入特性`

+ 1 - 0
README.md

@@ -205,6 +205,7 @@ Markdown 输出的 HTML 所展现的外观。内置 ant-design, light,dark,w
 | input(value: string) | 输入后触发  | - |
 | focus(value: string) | 聚焦后触发 | - |
 | blur(value: string) | 失焦后触发 | - |
+| keydown(event: KeyboardEvent) | 按下后触发 | - |
 | esc(value: string) | <kbd>esc</kbd> 按下后触发 | - |
 | ctrlEnter(value: string) | <kbd>⌘/ctrl+enter</kbd> 按下后触发 | - |
 | select(value: string) | 编辑器中选中文字后触发 | - |

+ 1 - 0
README_en_US.md

@@ -181,6 +181,7 @@ Can be filled with element `id` or element itself` HTMLElement`
 | input | Trigger after input (value: string) | - |
 | focus | Trigger after focusing (value: string) | - |
 | blur | Trigger after out of focus (value: string) | - |
+| keydown(event: KeyboardEvent) | Trigger after keydown | - |
 | esc | Trigger after pressing <kbd>esc</kbd> (value: string) | - |
 | ctrlEnter | Trigger after pressing <kbd>⌘/ctrl+enter</kbd> (value: string) | - |
 | select | Triggered after selecting text in the editor (value: string) | - |

+ 3 - 0
src/ts/util/editorCommonEvent.ts

@@ -114,6 +114,9 @@ export const scrollCenter = (vditor: IVditor) => {
 
 export const hotkeyEvent = (vditor: IVditor, editorElement: HTMLElement) => {
     editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
+        if (!event.isComposing && vditor.options.keydown) {
+            vditor.options.keydown(event);
+        }
         // hint: 上下选择
         if ((vditor.options.hint.extend.length > 1 || vditor.toolbar.elements.emoji) &&
             vditor.hint.select(event, vditor)) {

+ 3 - 0
types/index.d.ts

@@ -727,6 +727,9 @@ interface IOptions {
     /** 失焦后触发 */
     blur?(value: string): void;
 
+    /** 按下键盘触发 */
+    keydown?(event: KeyboardEvent): void;
+
     /** `esc` 按下后触发 */
     esc?(value: string): void;