问题
I implemented a copy&paste handling in SAPUI5 in an own control that worked till SAPUI5 version 1.54.x since 1.56.x it seems no longer working - especially in combination with drag&drop handling.
My code looked like this (in an own control):
sap.ui.define([
"sap/m/VBox",
"sap/m/VBoxRenderer"
], function (VBox, VBoxRenderer) {
"use strict";
var MyBox = VBox.extend("my.domain.controls.VBox",
{
metadata : {
properties : {
},
aggregations : {
},
events: {
copy : { parameters : {} },
paste : { parameters : {} }
}
},
init : function () {
this._bExcludeFromTabChain = false;
VBox.prototype.init.apply(this, arguments);
},
renderer : function (oRM, oControl) {
oRM.write("<div");
oRM.writeControlData(oControl);
oRM.addClass("MyBox");
oRM.writeAttribute("tabindex", "0"); // allows selection
oRM.writeClasses();
oRM.write(">");
VBoxRenderer.render.apply(this, [oRM, oControl]);
oRM.write("</div>");
}
});
MyBox.prototype.onAfterRendering = function() {
this.$().on("copy", jQuery.proxy(this.handleCopy, this));
this.$().on("paste", jQuery.proxy(this.handlePaste, this));
};
MyBox.prototype.onBeforeRendering = function() {
this.$().off("copy", this.handleCopy);
this.$().off("paste", this.handlePaste);
};
MyBox.prototype.exit = function() {
this.$().off("copy", this.handleCopy);
this.$().off("paste", this.handlePaste);
};
MyBox.prototype.handleCopy = function() {
this.fireEvent("copy", {});
};
MyBox.prototype.handlePaste = function() {
this.fireEvent("paste", {});
};
MyBox.prototype.getAccessibilityInfo = function() {
return {
children: this.getItems(),
focusable: true
};
};
return MyBox;
});
Is there a different way to handle Ctrl+C and Ctrl+V? I am not intersted in using the operating system clipboard I just intersted in geting the event.
As mentioned if I switch on drag&drop handling (in a control where this one is used as well) it looks like the jQuery copy/paste event does not reach my control.
来源:https://stackoverflow.com/questions/55809131/how-to-copypaste-sapui5-controls-by-pressing-ctrlc-and-ctrl-v