-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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: Add separators on context menu #2659
feat: Add separators on context menu #2659
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/excalidraw/excalidraw/7f3rlwdec |
Visually it looks great ❤️ not sure what to do with the ids though.. needs some thinking :) |
If we don't want to have this weird numbering scheme, another option would be to simply list the actions manually, in the order we want, including separators. IMO it's not so bad — it'd simplify the code (remove the need for We should also move all the adhoc contextmenu items into proper actions (paste..). It would look something like this: import { actionPaste } from "src/actions/actionClipboard"; // this action doesn't exist yet
import { actionSelectAll } from "src/actions/actionSelectAll";
const separator = { type: "separator" };
ContextMenu.push({
options: [
actionPaste,
separator,
actionSelectAll,
// ...
]
}); |
Thank you @dwelle, your solution seems very nice to me. Removing numbering scheme will definitely improve code quality. |
How to convert following methods into actions which are using private pasteFromClipboard = withBatchedUpdates(
async (event: ClipboardEvent | null) => {
// #686
const target = document.activeElement;
const elementUnderCursor = document.elementFromPoint(cursorX, cursorY);
if (
// if no ClipboardEvent supplied, assume we're pasting via contextMenu
// thus these checks don't make sense
event &&
(!(elementUnderCursor instanceof HTMLCanvasElement) ||
isWritableElement(target))
) {
return;
}
const data = await parseClipboard(event);
if (data.errorMessage) {
this.setState({ errorMessage: data.errorMessage });
} else if (data.spreadsheet) {
this.addElementsFromPasteOrLibrary(
renderSpreadsheet(data.spreadsheet, cursorX, cursorY),
);
} else if (data.elements) {
this.addElementsFromPasteOrLibrary(data.elements);
} else if (data.text) {
this.addTextFromPaste(data.text);
}
this.selectShapeTool("selection");
event?.preventDefault();
},
); private copyToClipboardAsPng = async () => {
const elements = this.scene.getElements();
const selectedElements = getSelectedElements(elements, this.state);
try {
await exportCanvas(
"clipboard",
selectedElements.length ? selectedElements : elements,
this.state,
this.canvas!,
this.state,
);
} catch (error) {
console.error(error);
this.setState({ errorMessage: error.message });
}
}; |
Actions can (should) return That said, maybe it's not a good fit for |
167cbc4
to
991eb97
Compare
991eb97
to
ec37b10
Compare
ec37b10
to
9570da3
Compare
9570da3
to
23f8cea
Compare
23f8cea
to
0c07055
Compare
0c07055
to
443f97c
Compare
What's the latest with this one @Kartik1397? Are you stuck anywhere? need help? |
@lipis My exam is going on which will end tomorrow. So I will start working on this again from tomorrow. |
Priority on the exams! Good luck.. |
443f97c
to
3423422
Compare
@Kartik1397 are you done with this one? |
@lipis Yes, If you fine with not creating action for paste and toggleZenMode for now. |
Let's see what @dwelle thinks.. |
|
@Kartik1397 reviewed. I made a few changes:
If you're ok with the changes, we can merge 🚀 Also, what's your twitter handle? |
Let's 🐑 it :) |
There was a bug, when we open context menu while cursor type is move.
Yeah 👍
|
🎆 |
Fixes #2506 - Check the preview.
This is my first try toward implementing separators in context menu.
One thing which I can improve in this implementation is to use constant varible instead of hard coded numerical value for order and group.
If there is a more clever way to implement this, please suggest me.
Screenshots