simulate a db tap on mobile to insert text (#1155)
This commit is contained in:
parent
0e90996715
commit
56034eacb0
@ -119,6 +119,7 @@ function withBatchedUpdates<
|
|||||||
|
|
||||||
const { history } = createHistory();
|
const { history } = createHistory();
|
||||||
|
|
||||||
|
let didTapTwice: boolean = false;
|
||||||
let cursorX = 0;
|
let cursorX = 0;
|
||||||
let cursorY = 0;
|
let cursorY = 0;
|
||||||
let isHoldingSpace: boolean = false;
|
let isHoldingSpace: boolean = false;
|
||||||
@ -368,6 +369,7 @@ export class App extends React.Component<any, AppState> {
|
|||||||
document.addEventListener("copy", this.onCopy);
|
document.addEventListener("copy", this.onCopy);
|
||||||
document.addEventListener("paste", this.pasteFromClipboard);
|
document.addEventListener("paste", this.pasteFromClipboard);
|
||||||
document.addEventListener("cut", this.onCut);
|
document.addEventListener("cut", this.onCut);
|
||||||
|
window.addEventListener("touchstart", this.onTapStart);
|
||||||
|
|
||||||
document.addEventListener("keydown", this.onKeyDown, false);
|
document.addEventListener("keydown", this.onKeyDown, false);
|
||||||
document.addEventListener("keyup", this.onKeyUp, { passive: true });
|
document.addEventListener("keyup", this.onKeyUp, { passive: true });
|
||||||
@ -401,6 +403,7 @@ export class App extends React.Component<any, AppState> {
|
|||||||
|
|
||||||
document.removeEventListener("copy", this.onCopy);
|
document.removeEventListener("copy", this.onCopy);
|
||||||
document.removeEventListener("paste", this.pasteFromClipboard);
|
document.removeEventListener("paste", this.pasteFromClipboard);
|
||||||
|
window.removeEventListener("touchstart", this.onTapStart);
|
||||||
document.removeEventListener("cut", this.onCut);
|
document.removeEventListener("cut", this.onCut);
|
||||||
|
|
||||||
document.removeEventListener("keydown", this.onKeyDown, false);
|
document.removeEventListener("keydown", this.onKeyDown, false);
|
||||||
@ -553,6 +556,27 @@ export class App extends React.Component<any, AppState> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private onTapStart = (event: TouchEvent) => {
|
||||||
|
let timeoutId;
|
||||||
|
if (!didTapTwice) {
|
||||||
|
didTapTwice = true;
|
||||||
|
timeoutId = setTimeout(function () {
|
||||||
|
didTapTwice = false;
|
||||||
|
}, 300);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (didTapTwice) {
|
||||||
|
const [touch] = event.touches;
|
||||||
|
// @ts-ignore
|
||||||
|
this.handleCanvasDoubleClick({
|
||||||
|
clientX: touch.clientX,
|
||||||
|
clientY: touch.clientY,
|
||||||
|
});
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
private pasteFromClipboard = withBatchedUpdates(
|
private pasteFromClipboard = withBatchedUpdates(
|
||||||
async (event: ClipboardEvent | null) => {
|
async (event: ClipboardEvent | null) => {
|
||||||
// #686
|
// #686
|
||||||
|
Loading…
x
Reference in New Issue
Block a user