Archived
1
0

Enable native clipboard for editor and inputs

StackOverflow will be useful again.
This commit is contained in:
Asher
2019-01-30 16:57:22 -06:00
committed by Kyle Carberry
parent ebe5e1b1a9
commit bef46391fa
4 changed files with 160 additions and 11 deletions

View File

@ -36,6 +36,30 @@ export class Clipboard {
}
}
/**
* Paste currently copied text.
*/
public async paste(): Promise<boolean> {
if (this.isEnabled) {
try {
const element = document.activeElement as HTMLInputElement | HTMLTextAreaElement;
const start = element.selectionStart || 0;
const end = element.selectionEnd;
const allText = element.value;
const newText = allText.substring(0, start)
+ (await this.readText())
+ allText.substring(end || start);
element.value = newText;
return true;
} catch (ex) {
// Will try execCommand below.
}
}
return document.execCommand("paste");
}
/**
* Return true if the native clipboard is supported.
*/