-
Notifications
You must be signed in to change notification settings - Fork 22
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
Backup: copy-paste support with refactor of java side events handling #231
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d6dbeaa
fix: sync props (state) with attributes and propagate changes with bu…
tpoisseau 41fecf9
feat: vaadin events
tpoisseau 1f4f81b
feat: copy/paste
tpoisseau 7881615
fix: readonly state from attribute init
tpoisseau 0d9a56c
fix: `#handleChange` filter
tpoisseau 248fc1b
fix: paste fragment
tpoisseau fa5594c
wip: support copy/paste on reaction
tpoisseau 2575d9e
Merge branch 'main' into 229-improve-web-component
tpoisseau 5d1f3ff
feat: add clipboard listener
tpoisseau 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
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
function fireMouseEvent(what, ev, clickCount = 0) { | ||
if (ev.button > 0) { | ||
// TODO: remove this to implement popup menu. | ||
return; | ||
} | ||
drawArea.fireMouseEvent( | ||
|
@@ -70,23 +70,27 @@ | |
function addKeyboardListeners(canvasElement, editorArea, JavaEditorArea) { | ||
const isMac = | ||
typeof navigator !== 'undefined' && navigator.platform === 'MacIntel'; | ||
const isMenuKey = (ev) => (isMac && ev.metaKey) || (!isMac && ev.ctrlKey); | ||
|
||
function fireKeyEvent(what, ev) { | ||
const key = getKeyFromEvent(ev, JavaEditorArea); | ||
if (key === null) return; | ||
ev.stopPropagation(); | ||
ev.preventDefault(); | ||
|
||
editorArea.fireKeyEvent( | ||
what, | ||
key, | ||
ev.altKey, | ||
ev.ctrlKey, | ||
ev.shiftKey, | ||
(isMac && ev.metaKey) || (!isMac && ev.ctrlKey), | ||
isMenuKey(ev), | ||
); | ||
} | ||
|
||
canvasElement.addEventListener('keydown', (ev) => { | ||
// copy-paste is handled by the clipboard event | ||
if (isMenuKey(ev) && ev.key === 'c') return; | ||
if (isMenuKey(ev) && ev.key === 'v') return; | ||
Comment on lines
+90
to
+92
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. not triggering java events with |
||
|
||
fireKeyEvent(JavaEditorArea.KEY_EVENT_PRESSED, ev); | ||
}); | ||
canvasElement.addEventListener('keyup', (ev) => { | ||
|
@@ -129,7 +133,55 @@ | |
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {HTMLDivElement} rootElement | ||
* @param editorArea | ||
* @param {boolean} readOnly | ||
* @param JavaEditorArea | ||
*/ | ||
function addClipboardListeners( | ||
rootElement, | ||
editorArea, | ||
readOnly, | ||
JavaEditorArea, | ||
) { | ||
/** | ||
* @param {ClipboardEvent} event | ||
*/ | ||
function onCopy(event) { | ||
editorArea.fireClipboardEvent(JavaEditorArea.CLIPBOARD_EVENT_COPY, null); | ||
|
||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
|
||
/** | ||
* @param {ClipboardEvent} event | ||
*/ | ||
function onPaste(event) { | ||
const idcode = event.clipboardData.getData('text/plain'); | ||
if (!idcode) return; | ||
|
||
editorArea.fireClipboardEvent(JavaEditorArea.CLIPBOARD_EVENT_PASTE, idcode); | ||
|
||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
|
||
rootElement.addEventListener('copy', onCopy); | ||
if (!readOnly) { | ||
rootElement.addEventListener('paste', onPaste); | ||
} | ||
|
||
return () => { | ||
rootElement.removeEventListener('copy', onCopy); | ||
rootElement.removeEventListener('paste', onPaste); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
addPointerListeners, | ||
addKeyboardListeners, | ||
addClipboardListeners, | ||
}; |
Oops, something went wrong.
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.
Removed so browser can propagate copy-paste events.
To interact with clipboard, browser need proper user interaction