fix: fix paste not working bug
This commit is contained in:
parent
f0027bfe50
commit
ed6ac63747
|
|
@ -19,27 +19,35 @@ export default class Clipboard {
|
||||||
navigator.clipboard.writeText(e.clipboardData.getData('text/plain')).catch(() => {/* Do nothing */});
|
navigator.clipboard.writeText(e.clipboardData.getData('text/plain')).catch(() => {/* Do nothing */});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param {ClipboardEvent} e
|
||||||
|
*/
|
||||||
_handlePaste(e) {
|
_handlePaste(e) {
|
||||||
if (navigator.clipboard.readText) {
|
if(!this._isVncEvent()){
|
||||||
navigator.clipboard.readText().then(this.onpaste).catch(() => {/* Do nothing */});
|
return;
|
||||||
} else if (e.clipboardData) {
|
}
|
||||||
|
if(e.clipboardData){
|
||||||
this.onpaste(e.clipboardData.getData('text/plain'));
|
this.onpaste(e.clipboardData.getData('text/plain'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_isVncEvent(){
|
||||||
|
const isTargetFocused = document.activeElement === this._target;
|
||||||
|
return isTargetFocused;
|
||||||
|
}
|
||||||
|
|
||||||
// ===== PUBLIC METHODS =====
|
// ===== PUBLIC METHODS =====
|
||||||
|
|
||||||
grab() {
|
grab() {
|
||||||
if (!Clipboard.isSupported) return;
|
if (!Clipboard.isSupported) return;
|
||||||
this._target.addEventListener('copy', this._eventHandlers.copy);
|
this._target.addEventListener('copy', this._eventHandlers.copy);
|
||||||
this._target.addEventListener('paste', this._eventHandlers.paste);
|
// _target can not listen the paste event.
|
||||||
|
document.body.addEventListener('paste', this._eventHandlers.paste);
|
||||||
}
|
}
|
||||||
|
|
||||||
ungrab() {
|
ungrab() {
|
||||||
if (!Clipboard.isSupported) return;
|
if (!Clipboard.isSupported) return;
|
||||||
this._target.removeEventListener('copy', this._eventHandlers.copy);
|
this._target.removeEventListener('copy', this._eventHandlers.copy);
|
||||||
this._target.removeEventListener('paste', this._eventHandlers.paste);
|
document.body.removeEventListener('paste', this._eventHandlers.paste);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,10 @@ export default class Keyboard {
|
||||||
|
|
||||||
_handleKeyDown(e) {
|
_handleKeyDown(e) {
|
||||||
const code = this._getKeyCode(e);
|
const code = this._getKeyCode(e);
|
||||||
|
const isCtrlVEvent = code === "KeyV" && e.ctrlKey;
|
||||||
|
if(isCtrlVEvent){
|
||||||
|
return;
|
||||||
|
}
|
||||||
let keysym = KeyboardUtil.getKeysym(e);
|
let keysym = KeyboardUtil.getKeysym(e);
|
||||||
let numlock = e.getModifierState('NumLock');
|
let numlock = e.getModifierState('NumLock');
|
||||||
let capslock = e.getModifierState('CapsLock');
|
let capslock = e.getModifierState('CapsLock');
|
||||||
|
|
|
||||||
10
core/rfb.js
10
core/rfb.js
|
|
@ -261,7 +261,7 @@ export default class RFB extends EventTargetMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._clipboard = new Clipboard(this._canvas);
|
this._clipboard = new Clipboard(this._canvas);
|
||||||
this._clipboard.onpaste = this.clipboardPasteFrom.bind(this);
|
this._clipboard.onpaste = this._handlePasteEvent.bind(this);
|
||||||
|
|
||||||
this._keyboard = new Keyboard(this._canvas);
|
this._keyboard = new Keyboard(this._canvas);
|
||||||
this._keyboard.onkeyevent = this._handleKeyEvent.bind(this);
|
this._keyboard.onkeyevent = this._handleKeyEvent.bind(this);
|
||||||
|
|
@ -500,6 +500,14 @@ export default class RFB extends EventTargetMixin {
|
||||||
this._canvas.blur();
|
this._canvas.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_handlePasteEvent(text){
|
||||||
|
this.clipboardPasteFrom(text);
|
||||||
|
this.sendKey(KeyTable.XK_Control_L, "ControlLeft", true)
|
||||||
|
this.sendKey(KeyTable.XK_V, "KeyV", true)
|
||||||
|
this.sendKey(KeyTable.XK_V, "KeyV", false)
|
||||||
|
this.sendKey(KeyTable.XK_Control_L, "ControlLeft", false)
|
||||||
|
}
|
||||||
|
|
||||||
clipboardPasteFrom(text) {
|
clipboardPasteFrom(text) {
|
||||||
if (this._rfbConnectionState !== 'connected' || this._viewOnly) { return; }
|
if (this._rfbConnectionState !== 'connected' || this._viewOnly) { return; }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue