Add native C&P support to morphic text inputs!

All the hard work goes to the folks working on Edgy for this one!
@cyderize wrote Edgy's implementation, and I copied that almost exactly.

08f6c473ae/edgy/clipboard.js

* In the current edgy implementation, there's a `hiddenDiv` which
contains the `hiddenText` textarea. I found that div to not be
necessary, so it was removed.
* I tweaked a couple `==` to be `===`.

Fix #353 really fix #88
dev
Michael Ball 2015-12-15 22:42:04 -08:00
rodzic e672fe5056
commit cad8f21e74
1 zmienionych plików z 57 dodań i 1 usunięć

Wyświetl plik

@ -4478,7 +4478,7 @@ function CursorMorph(aStringOrTextMorph) {
}
CursorMorph.prototype.init = function (aStringOrTextMorph) {
var ls;
var ls, myself = this;
// additional properties:
this.keyDownEventUsed = false;
@ -4496,6 +4496,59 @@ CursorMorph.prototype.init = function (aStringOrTextMorph) {
this.target.setAlignmentToLeft();
}
this.gotoSlot(this.slot);
// Add hidden text box for copying and pasting
this.hiddenText = document.createElement('textarea');
this.target.hiddenText = this.hiddenText;
this.hiddenText.style.position = 'absolute';
this.hiddenText.style.right = '101%'; // placed just out of view
document.body.appendChild(this.hiddenText);
this.hiddenText.value = this.target.selection();
this.hiddenText.focus();
this.hiddenText.select();
this.hiddenText.addEventListener(
'keypress',
function (event) {
console.log('press');
console.log(event);
myself.processKeyPress(event);
this.value = myself.target.selection();
this.select();
},
false
);
this.hiddenText.addEventListener(
'keydown',
function (event) {
console.log('down');
console.log(event);
myself.processKeyDown(event);
this.value = myself.target.selection();
this.select();
// Make sure tab prevents default
if (event.keyIdentifier === 'U+0009' || event.keyIdentifier === 'Tab') {
myself.processKeyPress(event);
event.preventDefault();
}
},
false
);
this.hiddenText.addEventListener(
'input',
function (event) {
if (this.value === '') {
myself.gotoSlot(myself.target.selectionStartSlot());
myself.target.deleteSelection();
}
},
false
);
};
// CursorMorph event processing:
@ -4849,6 +4902,9 @@ CursorMorph.prototype.destroy = function () {
this.target.drawNew();
this.target.changed();
}
if (this.hiddenText) {
document.body.removeChild(this.hiddenText);
}
CursorMorph.uber.destroy.call(this);
};