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: hide context menu when onRenderContextMenu return false #411

Merged
merged 5 commits into from
Mar 8, 2024

Conversation

1pone
Copy link
Contributor

@1pone 1pone commented Mar 4, 2024

This is an optimized version of pr #399

@josdejong
Copy link
Owner

Thanks! I think this is exactly the logic we need.

I have a few feedbacks regarding the code:

  1. I think it would be nice to keep the logic to create the menu items in a separate file, since the files TreeMode.svelte and TableMode.svelte are already very large. We can create a function like const items = createTreeContextMenuItems({ json, documentState, parser, ..., onCut, onCopy, onPaste, ... }) and put that in a separate file. Also, the components TreeContextMenu and TableContextMenu are now about empty and don't add anything anymore, I think we can remove them. So basically: we can replace the component TreeContextMenu.svelte with a function in a file createTreeContextMenuItems.ts, mostly containing the same logic as the component had (and do the same with table mode). What do you think?

  2. Minor thingy: can you replace the inline return like if (items === false) return to have braces, like:

    if (items === false) {
      return
    }

    (a personal preference)

@1pone
Copy link
Contributor Author

1pone commented Mar 7, 2024

Thanks, I've made the changes you suggested.

Copy link
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

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

Niice job!! This looks really good, and keeps the behavior backward compatible.

I made two small inline comments, can you have a look at those?

src/lib/components/modes/tablemode/TableMode.svelte Outdated Show resolved Hide resolved
src/lib/components/modes/treemode/TreeMode.svelte Outdated Show resolved Hide resolved
@1pone
Copy link
Contributor Author

1pone commented Mar 8, 2024

Resolved

@josdejong
Copy link
Owner

Thanks!

I was thinking: this still has to be published as a breaking changes: when you had an onRenderContextMenu before and was returning something, you now have to handle the case when the editor is readOnly.

@josdejong josdejong merged commit db3fb57 into josdejong:main Mar 8, 2024
4 checks passed
@1pone
Copy link
Contributor Author

1pone commented Mar 8, 2024

That's right, just like the adjustments made in the development page, this should really be known by those who are or have used onRenderContextMenu.

josdejong added a commit that referenced this pull request Mar 8, 2024
@josdejong
Copy link
Owner

I had one more thought: now that the context menu can be visible when the editor is readOnly, all the buttons should reckon with it and be disabled when not applicable in read-only mode. I've worked that out in c66ee09. I also came a cross a few minor issues related to the context menu, fixing that too.

Also, I added a property readOnly to the context of the onRenderMenu and onRenderContextMenu callbacks, see 4df5548.

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.

3 participants