Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 在标准 event 中支持 paste #933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading