-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Handle paste events for images and text properly #7679
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8241f55
enable eval source maps for debugging
davetsay 742336e
split image and text paste handling
davetsay 16d325f
change back source maps
davetsay b41f64d
image takes precedence over text
davetsay eb74816
break up notebook entry functions for re-use
davetsay 923e95a
create hotkeys utils
davetsay f7ac8da
add notebook paste test
davetsay ea98767
add test for pasting to selected but not editing entry
davetsay 372e6f9
link tests to issue
davetsay bce0bf0
jsdoc addition
davetsay 3eab149
jsdocs
davetsay fb122de
no need to import then export
davetsay ea52e82
fix changed path
davetsay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/***************************************************************************** | ||
* Open MCT, Copyright (c) 2014-2024, United States Government | ||
* as represented by the Administrator of the National Aeronautics and Space | ||
* Administration. All rights reserved. | ||
* | ||
* Open MCT is licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* Open MCT includes source code licensed under additional open source | ||
* licenses. See the Open Source Licenses file (LICENSES.md) included with | ||
* this source code distribution or the Licensing information page available | ||
* at runtime from the About dialog for additional information. | ||
*****************************************************************************/ | ||
|
||
const isMac = process.platform === 'darwin'; | ||
const modifier = isMac ? 'Meta' : 'Control'; | ||
|
||
/** | ||
* @param {import('@playwright/test').Page} page | ||
*/ | ||
async function selectAll(page) { | ||
await page.keyboard.press(`${modifier}+KeyA`); | ||
} | ||
|
||
/** | ||
* @param {import('@playwright/test').Page} page | ||
*/ | ||
async function copy(page) { | ||
await page.keyboard.press(`${modifier}+KeyC`); | ||
} | ||
|
||
/** | ||
* @param {import('@playwright/test').Page} page | ||
*/ | ||
async function paste(page) { | ||
await page.keyboard.press(`${modifier}+KeyV`); | ||
} | ||
|
||
export { copy, paste, selectAll }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/***************************************************************************** | ||
* Open MCT, Copyright (c) 2014-2024, United States Government | ||
* as represented by the Administrator of the National Aeronautics and Space | ||
* Administration. All rights reserved. | ||
* | ||
* Open MCT is licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* Open MCT includes source code licensed under additional open source | ||
* licenses. See the Open Source Licenses file (LICENSES.md) included with | ||
* this source code distribution or the Licensing information page available | ||
* at runtime from the About dialog for additional information. | ||
*****************************************************************************/ | ||
|
||
export * from './clipboard.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
@drop.capture="cancelEditMode" | ||
@drop.prevent="dropOnEntry" | ||
@click="selectAndEmitEntry($event, entry)" | ||
@paste="addImageFromPaste" | ||
@paste="handlePaste" | ||
> | ||
<div class="c-ne__time-and-content"> | ||
<div class="c-ne__time-and-creator-and-delete"> | ||
|
@@ -368,6 +368,28 @@ export default { | |
} | ||
}, | ||
methods: { | ||
handlePaste(event) { | ||
const clipboardItems = Array.from( | ||
(event.clipboardData || event.originalEvent.clipboardData).items | ||
); | ||
const hasClipboardText = clipboardItems.some( | ||
(clipboardItem) => clipboardItem.kind === 'string' | ||
); | ||
const clipboardImages = clipboardItems.filter( | ||
(clipboardItem) => clipboardItem.kind === 'file' && clipboardItem.type.includes('image') | ||
); | ||
const hasClipboardImages = clipboardImages?.length > 0; | ||
|
||
if (hasClipboardImages) { | ||
if (hasClipboardText) { | ||
console.warn('Image and text kinds found in paste. Only processing images.'); | ||
} | ||
|
||
this.addImageFromPaste(clipboardImages, event); | ||
} else if (hasClipboardText) { | ||
this.addTextFromPaste(event); | ||
} | ||
}, | ||
async addNewEmbed(objectPath) { | ||
const bounds = this.openmct.time.bounds(); | ||
const snapshotMeta = { | ||
|
@@ -384,32 +406,34 @@ export default { | |
|
||
this.manageEmbedLayout(); | ||
}, | ||
async addImageFromPaste(event) { | ||
const clipboardItems = Array.from( | ||
(event.clipboardData || event.originalEvent.clipboardData).items | ||
); | ||
const hasImage = clipboardItems.some( | ||
(clipboardItem) => clipboardItem.type.includes('image') && clipboardItem.kind === 'file' | ||
); | ||
// If the clipboard contained an image, prevent the paste event from reaching the textarea. | ||
if (hasImage) { | ||
addTextFromPaste(event) { | ||
if (!this.editMode) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is easily confused for the API's Edit mode. Can we rename this to make it clear that it refers to the notebook entry being editable? |
||
event.preventDefault(); | ||
} | ||
}, | ||
async addImageFromPaste(clipboardImages, event) { | ||
event?.preventDefault(); | ||
let updated = false; | ||
|
||
await Promise.all( | ||
Array.from(clipboardItems).map(async (clipboardItem) => { | ||
const isImage = clipboardItem.type.includes('image') && clipboardItem.kind === 'file'; | ||
if (isImage) { | ||
const imageFile = clipboardItem.getAsFile(); | ||
const imageEmbed = await createNewImageEmbed(imageFile, this.openmct, imageFile?.name); | ||
if (!this.entry.embeds) { | ||
this.entry.embeds = []; | ||
} | ||
this.entry.embeds.push(imageEmbed); | ||
Array.from(clipboardImages).map(async (clipboardImage) => { | ||
const imageFile = clipboardImage.getAsFile(); | ||
const imageEmbed = await createNewImageEmbed(imageFile, this.openmct, imageFile?.name); | ||
|
||
if (!this.entry.embeds) { | ||
this.entry.embeds = []; | ||
} | ||
|
||
this.entry.embeds.push(imageEmbed); | ||
|
||
updated = true; | ||
}) | ||
); | ||
this.manageEmbedLayout(); | ||
this.timestampAndUpdate(); | ||
|
||
if (updated) { | ||
this.manageEmbedLayout(); | ||
this.timestampAndUpdate(); | ||
} | ||
}, | ||
convertMarkDownToHtml(text = '') { | ||
let markDownHtml = this.marked.parse(text, { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.