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

Identify paste from browser event #1963

Merged
merged 7 commits into from
Jul 24, 2023
Merged

Conversation

juliaroldi
Copy link
Contributor

@juliaroldi juliaroldi commented Jul 19, 2023

The pasteNativeEvent was created in the BeforePasteEvent object, so it is possible to differentiate a paste event triggered by RoosterJS api and paste event from browser (keyboard shortcut and native context menu).
A paste button was added to ContentModel ribbon and a log was added in EventViewer Pane.
Paste control:
Screenshot 2023-07-24 at 11 36 24

If the paste event was triggered by a native event:
Screenshot 2023-07-24 at 11 38 14

If the event was triggered by paste control:
Screenshot 2023-07-24 at 11 40 00

@juliaroldi juliaroldi closed this Jul 19, 2023
@juliaroldi juliaroldi reopened this Jul 24, 2023
@juliaroldi juliaroldi changed the title paste native Identify pate from browser event Jul 24, 2023
@juliaroldi juliaroldi marked this pull request as ready for review July 24, 2023 14:42
@@ -215,7 +215,8 @@ export default interface IEditor {
clipboardData: ClipboardData,
pasteAsText?: boolean,
applyCurrentFormat?: boolean,
pasteAsImage?: boolean
pasteAsImage?: boolean,
nativePaste?: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding new parameter here, how about put it into ClipboardData, so that we don't polute this function interface.

@@ -125,7 +125,8 @@ export type CreatePasteFragment = (
position: NodePosition | null,
pasteAsText: boolean,
applyCurrentStyle: boolean,
pasteAsImage: boolean
pasteAsImage: boolean,
nativePaste: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

/**
* If true, the event was triggered by a native paste event (keyboard or native context menu paste)
*/
readonly pasteNativeEvent: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to ClipboardData, then no need to change here

false /*pasteAsText*/,
false /*applyCurrentStyle*/,
false /*pasteAsImage*/,
true /*nativePaste */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to ClipboardData, then set this value when extractClipboardItems()

@juliaroldi juliaroldi changed the title Identify pate from browser event Identify paste from browser event Jul 24, 2023
@juliaroldi juliaroldi force-pushed the u/juliaroldi/rooster-paste branch from d893fc6 to 50b7dce Compare July 24, 2023 18:56
/**
* If true, the event was triggered by a native paste event (keyboard or native context menu paste)
*/
readonly pasteNativeEvent: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make any new property optional, to be compatible with older build

@@ -27,22 +27,23 @@ export default function extractClipboardEvent(
event: ClipboardEvent,
callback: (clipboardData: ClipboardData) => void,
options?: ExtractClipboardEventOption,
rangeBeforePaste?: Range
rangeBeforePaste?: Range,
pasteNativeEvent: boolean = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is ClipboardEvent, it must be from native paste, so no need to provide this parameter here, and always pass true

@@ -21,7 +21,8 @@ import {
export default function extractClipboardItemsForIE(
dataTransfer: DataTransfer,
callback: (data: ClipboardData) => void,
options?: ExtractClipboardItemsForIEOptions
options?: ExtractClipboardItemsForIEOptions,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE is deprecated. So no need to change this file any more

@juliaroldi juliaroldi merged commit 943912d into master Jul 24, 2023
@JiuqingSong JiuqingSong deleted the u/juliaroldi/rooster-paste branch September 8, 2023 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants