Skip to content

Commit

Permalink
Do not allow dragging readonly element
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Aug 4, 2023
1 parent bc2225f commit f61a076
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
11 changes: 10 additions & 1 deletion packages/roosterjs-editor-core/lib/corePlugins/DOMEventPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export default class DOMEventPlugin implements PluginWithState<DOMEventPluginSta
});
},

// 4. Drop event
// 4. Drag and Drop event
dragstart: this.onDragStart,
drop: this.onDrop,

// 5. Focus management
Expand Down Expand Up @@ -146,6 +147,14 @@ export default class DOMEventPlugin implements PluginWithState<DOMEventPluginSta
return this.state;
}

private onDragStart = (e: Event) => {
const dragEvent = e as DragEvent;
const element = this.editor?.getElementAtCursor('*', dragEvent.target as Node);

if (element && !element.isContentEditable) {
dragEvent.preventDefault();
}
};
private onDrop = () => {
this.editor?.runAsync(editor => {
editor.addUndoSnapshot(() => {}, ChangeSource.Drop);
Expand Down
16 changes: 0 additions & 16 deletions packages/roosterjs-editor-core/lib/corePlugins/EntityPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const REMOVE_ENTITY_OPERATIONS: (EntityOperation | CompatibleEntityOperation)[]
export default class EntityPlugin implements PluginWithState<EntityPluginState> {
private editor: IEditor | null = null;
private state: EntityPluginState;
private disposer: (() => void) | null = null;

/**
* Construct a new instance of EntityPlugin
Expand All @@ -88,15 +87,12 @@ export default class EntityPlugin implements PluginWithState<EntityPluginState>
*/
initialize(editor: IEditor) {
this.editor = editor;
this.disposer = this.editor.addDomEventHandler('dragstart', this.onDragStart);
}

/**
* Dispose this plugin
*/
dispose() {
this.disposer?.();
this.disposer = null;
this.editor = null;
this.state.entityMap = {};
}
Expand Down Expand Up @@ -277,18 +273,6 @@ export default class EntityPlugin implements PluginWithState<EntityPluginState>
});
}

private onDragStart = (e: Event) => {
const dragEvent = e as DragEvent;
const entityWrapper = this.editor?.getElementAtCursor(
getEntitySelector(),
dragEvent.target as Node
);

if (entityWrapper && getEntityFromElement(entityWrapper)?.isReadonly) {
dragEvent.preventDefault();
}
};

private checkRemoveEntityForRange(event: Event) {
const editableEntityElements: HTMLElement[] = [];
const selector = getEntitySelector();
Expand Down

0 comments on commit f61a076

Please sign in to comment.