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

Feature/editor key events #14

Merged
merged 5 commits into from
Nov 12, 2023

Conversation

khakimov
Copy link
Contributor

@khakimov khakimov commented Nov 5, 2023

This commit adds handle ctrl+Enter (cmd+Enter) in the editor component (handleSubmit function is called) to save new post or reply.

Additionally, when the editor is active and an image is pasted from a buffer (cmd+V), the image file is handled by attachToPost(attachToPost). Related to cmd + V for pasting images from clipboard (#8)

@victor-teles
Copy link

I was looking for this keyboard feature 🔥
I think ctrl+enter/shift+enter is commonly used for line breaking, maybe the key could be just enter?

image

@khakimov
Copy link
Contributor Author

khakimov commented Nov 5, 2023

I was looking for this keyboard feature 🔥 I think ctrl+enter/shift+enter is commonly used for line breaking, maybe the key could be just enter?

Aha, make sense, let me test tomorrow and push updated code. Not sure even if editor is handling new line at the moment, so maybe you right to keep Enter for posting new post/reply.

@UdaraJay
Copy link
Owner

UdaraJay commented Nov 5, 2023

The line-break functionality would be good to preserve– it would be ideal if keyboard events of this sort could be handled by a custom tiptap extension or shortcut for consistency, but this works just fine for now.

This looks great! thanks for contributing! :)

src/main/ipc.ts Outdated
const hours = String(currentDate.getHours()).padStart(2, '0');
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
const seconds = String(currentDate.getSeconds()).padStart(2, '0');
const extension = 'png'; // Replace with the desired file extension
Copy link
Owner

Choose a reason for hiding this comment

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

is the extension always png in the case of pasting from clipboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing out. Fixed that, checking filename and determine which extension is posted:

const file = item.getAsFile();
const fileName = file.name; // Retrieve the filename
const fileExtension = fileName.split('.').pop(); // Extract the file extension

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@UdaraJay I also updated the way to handle paste using editorProps and handlePaste instead of useEffect.

@@ -68,6 +68,7 @@ export default function Editor({
const [isDragging, setIsDragging] = useState(false);
const [isAIResponding, setIsAiResponding] = useState(false);
const [prevDragPos, setPrevDragPos] = useState(0);
const [isActive, setIsActive] = useState(false);
Copy link
Owner

Choose a reason for hiding this comment

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

You can use editor.isFocused instead of managing the active state yourself.

@khakimov
Copy link
Contributor Author

khakimov commented Nov 6, 2023

The line-break functionality would be good to preserve– it would be ideal if keyboard events of this sort could be handled by a custom tiptap extension or shortcut for consistency, but this works just fine for now.

This looks great! thanks for contributing! :)

thank you for leading the way, rewrote everything after reading tiptap documentation. handlePaste to handle pasting images and custom extension EnterSubmitExtension to trigger a 'submit' event on the editor with Enter. Removed isActive and used editor?.isFocused 🙌

@UdaraJay
Copy link
Owner

UdaraJay commented Nov 9, 2023

This looks good to go! I'll merge into the next release after some testing.

@UdaraJay UdaraJay merged commit 3c2b9c8 into UdaraJay:main Nov 12, 2023
2 of 5 checks passed
UdaraJay added a commit to khakimov/Pile that referenced this pull request Dec 31, 2023
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.

None yet

3 participants