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

Copy/paste improvements #9734

Merged
merged 8 commits into from
Apr 19, 2024
Merged

Copy/paste improvements #9734

merged 8 commits into from
Apr 19, 2024

Conversation

kazcw
Copy link
Contributor

@kazcw kazcw commented Apr 17, 2024

Pull Request Description

Copying nodes:

  • Multiple nodes supported.
  • Node comments and user-specified colors included.
  • Google Sheets data can be pasted to produce a Table node, handled the same way as Excel data.

Important Notes

  • Fix E2E tests on OS X.
  • Add E2E and unit tests for clipboard.
  • Use the lexer to test text escaping; fix text escaping issues and inconsistencies.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@kazcw kazcw added the CI: No changelog needed Do not require a changelog entry for this PR. label Apr 17, 2024
@kazcw kazcw self-assigned this Apr 17, 2024
for (const copiedNode of clipboardData) {
const { expression, documentation, visualization, colorOverride } = copiedNode
graphStore.createNode(
(clipboardData.length === 1 ? graphNavigator.sceneMousePos : null) ?? Vec2.Zero,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Positioning of multiple nodes is currently rudimentary; this will be fixed with the new API that will be introduced for #9703.

// Copy and paste it.
await page.keyboard.press(`${CONTROL_KEY}+C`)
await page.keyboard.press(`${CONTROL_KEY}+V`)
await expect(nodeToCopy).toBeSelected()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think newly-created nodes should always be selected; I'll implement this as part of #9703.

@kazcw
Copy link
Contributor Author

kazcw commented Apr 17, 2024

Depends on #9731 for tests to pass.

import * as locate from './locate'

const MAIN_FILE_NODES = 11

const COLLAPSE_SHORTCUT = os.platform() === 'darwin' ? 'Meta+G' : 'Control+G'
const COLLAPSE_SHORTCUT = `${CONTROL_KEY}+G`
Copy link
Contributor

Choose a reason for hiding this comment

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

After some changes ago, now it's possible to read COLLAPSE shortcut from bindings.ts (used for example in https://github.com/enso-org/enso/blob/e1893b65af1774bacd4b862cff11d28886bb81c2/app/gui2/src/composables/__tests__/selection.test.ts) You may try to use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think E2E tests have access to the main app source tree

@@ -10,18 +11,18 @@ test('Adding new node', async ({ page }) => {
await locate.addNewNodeButton(page).click()
await expect(locate.componentBrowserInput(page)).toBeVisible()
await page.keyboard.insertText('foo')
await page.keyboard.press('Control+Enter')
await page.keyboard.press(`${CONTROL_KEY}+Enter`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Does it mean that E2E tests never worked on mac?

Copy link
Contributor Author

@kazcw kazcw Apr 18, 2024

Choose a reason for hiding this comment

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

This is one of the most recent tests, but yeah, it has never worked on mac

')',
'gu',
)
const escapeRegex = new RegExp(`${[...fixedEscapes, '\\p{Surrogate}'].join('|')}`, 'gu')
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Why is it inside ``? join should return string already.
  2. What is this {Surrogate} tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment:

Unpaired-surrogate codepoints are not technically valid in Unicode, but they are allowed in Javascript strings.
Enso source files must be strictly UTF-8 conformant.

Comment on lines 24 to 26
documentation?: string | undefined
visualization?: VisualizationMetadata | undefined
colorOverride?: string | undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if, by default, we would copy all the metadata. So we could keep metadata field as Omit<NodeMetadataFields, 'position'>

@kazcw kazcw requested a review from farmaazon April 18, 2024 15:54
Comment on lines +35 to +37
// Unpaired-surrogate codepoints are not technically valid in Unicode, but they are allowed in Javascript strings.
// Enso source files must be strictly UTF-8 conformant.
'\\p{Surrogate}',
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 57 to 59
function isNodeMetadataField(property: string) {
return ['position', 'visualization', 'colorOverride'].includes(property)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about https://www.npmjs.com/package/ts-transformer-keys? You could use keys<NodeMetadataFields>()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't use compiler plugins without switching from vite's default transpiler (esbuild) to tsc, which would have a build-time cost: evanw/esbuild#1963.

We have a utility function allKeys that adds type-level correctness checking; I'll use that here. It is not as convenient as the TS-transformer (it requires an "example object" as an input), but it doesn't impose any unusual requirements on our build process.

@@ -22,16 +22,14 @@ interface ClipboardData {
interface CopiedNode {
expression: string
documentation?: string | undefined
visualization?: VisualizationMetadata | undefined
colorOverride?: string | undefined
metadata?: NodeMetadataFields
Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't want to exclude position from copied metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

position is ignored in the metadata supplied for node creation because a separate parameter overrides it.

@kazcw kazcw added the CI: Ready to merge This PR is eligible for automatic merge label Apr 19, 2024
@mergify mergify bot merged commit 6426478 into develop Apr 19, 2024
37 checks passed
@mergify mergify bot deleted the wip/kw/copy-comments branch April 19, 2024 16:33
@kazcw kazcw linked an issue Apr 23, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy-pasting nodes does not copy comments.
2 participants