Skip to content

Commit

Permalink
Minor changes from feedback on PR birchill#1656
Browse files Browse the repository at this point in the history
  • Loading branch information
StarScape committed Mar 21, 2024
1 parent 784473d commit 8902dae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2088,9 +2088,10 @@ export class ContentHandler {
} else if (dictToShow === 'prev') {
dict = this.currentDict;

let prev =
(cycleOrder.length + (cycleOrder.indexOf(this.currentDict) - 1)) %
cycleOrder.length;
let prev = mod(
cycleOrder.indexOf(this.currentDict) - 1,
cycleOrder.length
);
while (cycleOrder[prev] !== this.currentDict) {
const prevDict = cycleOrder[prev];
if (
Expand All @@ -2100,7 +2101,7 @@ export class ContentHandler {
dict = prevDict;
break;
}
prev = --prev % cycleOrder.length;
prev = mod(--prev, cycleOrder.length);
}
} else {
dict = dictToShow;
Expand Down
4 changes: 3 additions & 1 deletion src/content/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import { renderKanjiEntries } from './kanji';
import { renderMetadata } from './metadata';
import { renderNamesEntries } from './names';
import { renderCopyDetails, renderUpdatingStatus } from './status';
import { onHorizontalSwipe } from './swipe';
import { renderTabBar } from './tabs';
import { renderWordEntries } from './words';

import popupStyles from '../../../css/popup.css';
import { onHorizontalSwipe } from './swipe';

export type StartCopyCallback = (
index: number,
Expand Down Expand Up @@ -126,7 +126,9 @@ export function renderPopup(

windowElem.dataset.tabSide = options.tabDisplay || 'top';

console.log('Hello1');
onHorizontalSwipe(contentContainer, (direction) => {
console.log('Hello?');
if (options.onSwitchDictionary) {
options.onSwitchDictionary(direction === 'left' ? 'prev' : 'next');
}
Expand Down
7 changes: 3 additions & 4 deletions src/content/popup/swipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function onHorizontalSwipe(
function (e) {
startX = e.changedTouches[0].pageX;
startY = e.changedTouches[0].pageY;
startTime = Date.now();
startTime = performance.now();
},
false
);
Expand All @@ -41,7 +41,7 @@ export function onHorizontalSwipe(
const touch = e.changedTouches[0];
const deltaX = touch.pageX - startX;
const deltaY = touch.pageY - startY;
const elapsedTime = Date.now() - startTime;
const elapsedTime = performance.now() - startTime;

// Check that elapsed time is within specified, horizontal dist
// traveled >= threshold, and vertical dist traveled <= 100
Expand All @@ -50,8 +50,7 @@ export function onHorizontalSwipe(
Math.abs(deltaX) >= xMinThreshold &&
Math.abs(deltaY) <= yMaxThreshold;
if (isSwipe) {
const dir: HorizontalSwipeDirection = deltaX < 0 ? 'right' : 'left';
handler(dir);
handler(deltaX < 0 ? 'right' : 'left');
}
},
false
Expand Down

0 comments on commit 8902dae

Please sign in to comment.