Prevent next paste on middle clic with linux (#1402)
This commit is contained in:
parent
0ffbde77ac
commit
e158dbc45a
@ -1603,6 +1603,10 @@ class App extends React.Component<any, AppState> {
|
||||
(event.button === POINTER_BUTTON.MAIN && isHoldingSpace))
|
||||
) {
|
||||
isPanning = true;
|
||||
|
||||
let nextPastePrevented = false;
|
||||
const isLinux = /Linux/.test(window.navigator.platform);
|
||||
|
||||
document.documentElement.style.cursor = CURSOR_TYPE.GRABBING;
|
||||
let { clientX: lastX, clientY: lastY } = event;
|
||||
const onPointerMove = withBatchedUpdates((event: PointerEvent) => {
|
||||
@ -1611,6 +1615,40 @@ class App extends React.Component<any, AppState> {
|
||||
lastX = event.clientX;
|
||||
lastY = event.clientY;
|
||||
|
||||
/*
|
||||
* Prevent paste event if we move while middle clicking on Linux.
|
||||
* See issue #1383.
|
||||
*/
|
||||
if (
|
||||
isLinux &&
|
||||
!nextPastePrevented &&
|
||||
(Math.abs(deltaX) > 1 || Math.abs(deltaY) > 1)
|
||||
) {
|
||||
nextPastePrevented = true;
|
||||
|
||||
/* Prevent the next paste event */
|
||||
const preventNextPaste = (event: ClipboardEvent) => {
|
||||
document.body.removeEventListener(EVENT.PASTE, preventNextPaste);
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
/*
|
||||
* Reenable next paste in case of disabled middle click paste for
|
||||
* any reason:
|
||||
* - rigth click paste
|
||||
* - empty clipboard
|
||||
*/
|
||||
const enableNextPaste = () => {
|
||||
setTimeout(() => {
|
||||
document.body.removeEventListener(EVENT.PASTE, preventNextPaste);
|
||||
window.removeEventListener(EVENT.POINTER_UP, enableNextPaste);
|
||||
}, 100);
|
||||
};
|
||||
|
||||
document.body.addEventListener(EVENT.PASTE, preventNextPaste);
|
||||
window.addEventListener(EVENT.POINTER_UP, enableNextPaste);
|
||||
}
|
||||
|
||||
this.setState({
|
||||
scrollX: normalizeScroll(
|
||||
this.state.scrollX - deltaX / this.state.zoom,
|
||||
|
Loading…
x
Reference in New Issue
Block a user