Skip to content

Commit

Permalink
feat: 在标准 event 中支持 paste
Browse files Browse the repository at this point in the history
  • Loading branch information
lllllllqw committed Sep 30, 2024
1 parent 1193729 commit 167dcb0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ export default class Editor {

editor.on('paste', (codemirror, evt) => {
this.options.onPaste.call(this, evt, codemirror);
this.$cherry.$event.emit('paste', { evt, cherry: this.$cherry });
});

if (this.options.autoScrollByCursor) {
Expand Down
6 changes: 6 additions & 0 deletions src/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class Event {
afterInit: 'afterInit', // 编辑器初始化完成
focus: 'focus', // 焦点
blur: 'blur', // 失焦
paste: 'paste', // 粘贴
selectionChange: 'selectionChange', // 选区内容改变时触发
afterChangeLocale: 'afterChangeLocale', // 语言改变
changeMainTheme: 'changeMainTheme', // 变更主题
Expand Down Expand Up @@ -94,6 +95,11 @@ export default class Event {
options.event.blur(event);
});
}
if (options.event.paste) {
this.on(this.Events.paste, (event) => {
options.event.paste(event);
});
}
if (options.event.selectionChange) {
this.on(this.Events.selectionChange, (event) => {
options.event.selectionChange(event);
Expand Down
1 change: 1 addition & 0 deletions types/cherry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface _CherryOptions<T extends CherryCustomOptions = CherryCustomOpti
event: {
focus?: ({ e: MouseEvent, cherry: Cherry }) => void;
blur?: ({ e: MouseEvent, cherry: Cherry }) => void;
paste?: ({ e: MouseEvent, cherry: Cherry }) => void;
/** 编辑器内容改变并完成渲染后触发 */
afterChange?: CherryLifecycle;
/** 编辑器完成初次渲染后触发 */
Expand Down

0 comments on commit 167dcb0

Please sign in to comment.