Copy and paste

This commit is contained in:
Will Scullin 2020-10-06 20:22:44 -07:00
parent 69707cb184
commit ea6bb2c115
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
2 changed files with 37 additions and 1 deletions

View File

@ -153,7 +153,7 @@ export function toggleSpeed()
}
export function setKeyBuffer(text) {
io.setKeyBuffer(text);
io.paste(text);
}
export function setTurboTape(val) {
@ -395,6 +395,17 @@ document.addEventListener('DOMContentLoaded', function() {
window.addEventListener('keydown', _keydown);
window.addEventListener('keyup', _keyup);
window.addEventListener('paste', (event) => {
var paste = (event.clipboardData || window.clipboardData).getData('text');
setKeyBuffer(paste);
event.preventDefault();
});
window.addEventListener('copy', (event) => {
event.clipboardData.setData('text/plain', text.getText());
event.preventDefault();
});
document.querySelector('.overscan').addEventListener('paste', function(event) {
io.paste(event.originalEvent.clipboardData().getData('text/plain'));
event.preventDefault();

View File

@ -181,6 +181,31 @@ export function TextPage()
_page.data[idx] = 0xff;
}
},
getText: function() {
function mapCharCode(charCode) {
charCode &= 0x7F;
if (charCode < 0x20) {
charCode += 0x40;
}
if (charCode >= 0x60) {
charCode -= 0x40;
}
return charCode;
}
var buffer = '', line, charCode;
var row, col;
for (row = 0; row < 24; row++) {
line = '';
for (col = 0; col < 40; col++) {
charCode = mapCharCode(_buffer[row][col]);
line += String.fromCharCode(charCode);
}
line = line.trimRight();
buffer += line + '\n';
}
return buffer;
},
clear: function canvas_clearScreen() {
for (var row = 0; row < 24; row++) {
for (var col = 0; col < 40; col++) {