Skip to content

Commit

Permalink
Improve mobile experience (swipe)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowuake committed Apr 30, 2024
1 parent ffd18ff commit 87f598f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions schemius-web/schemius.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,21 @@ class Schemius {
const xDelta = touch.clientX - Schemius.xStart;
const yDelta = touch.clientY - Schemius.yStart;

const key =
Math.abs(xDelta) > Math.abs(yDelta)
const [key, timeout] =
Math.abs(xDelta) > 0.5 * Math.abs(yDelta)
? xDelta > 0
? "ArrowRight"
: "ArrowLeft"
? ["ArrowRight", 50]
: ["ArrowLeft", 50]
: yDelta > 0
? "ArrowDown"
: "ArrowUp";
? ["ArrowDown", 100]
: ["ArrowUp", 100];

// Schemius.xStart = null;
// Schemius.yStart = null;

Schemius.dispatchKeyEvent(key);
setTimeout(() => {
Schemius.dispatchKeyEvent(key);
}, timeout);
return false;
}

Expand All @@ -223,6 +225,10 @@ class Schemius {
}
}

static toEventSink() {
return false;
}

static handleKeyDown(e) {
if (e.ctrlKey) {
if (e.key !== "V") {
Expand Down Expand Up @@ -328,7 +334,8 @@ class Schemius {

$(document)
.on("touchstart", Schemius.terminal, Schemius.handleTouchStart)
.on("touchmove", Schemius.terminal, Schemius.handleTouchMove);
.on("touchmove", Schemius.terminal, Schemius.handleTouchMove)
.on("touchend", Schemius.terminal, Schemius.toEventSink);

// $(window).on("orientationchange", Schemius.setSize);
}
Expand Down

0 comments on commit 87f598f

Please sign in to comment.