Skip to content

Commit

Permalink
fix: Make popup positioning wrap around
Browse files Browse the repository at this point in the history
  • Loading branch information
birtles committed Apr 19, 2021
1 parent 07cf8f2 commit d46a1b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.1 (2021-04-19)

- Make <kbd>j</kbd> / <kbd>k</kbd> keys wrap-around when they reach the limit.

## 0.5.0 (2021-04-17)

- Adds ability to move the popup window using the <kbd>j</kbd> / <kbd>k</kbd>
Expand Down
17 changes: 9 additions & 8 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
isTextInputNode,
} from './dom-utils';
import { SelectionMeta } from './meta';
import { mod } from './mod';
import { kanjiToNumber } from './numbers';
import {
CopyState,
Expand Down Expand Up @@ -423,15 +424,15 @@ export class RikaiContent {
this.config.readingOnly = !this.config.readingOnly;
this.showPopup();
} else if (movePopupDown.includes(upperKey)) {
if (this.popupPositionMode < PopupPositionMode.End) {
this.popupPositionMode++;
this.showPopup();
}
this.popupPositionMode =
(this.popupPositionMode + 1) % (PopupPositionMode.End + 1);
this.showPopup();
} else if (movePopupUp.includes(upperKey)) {
if (this.popupPositionMode > PopupPositionMode.Start) {
this.popupPositionMode--;
this.showPopup();
}
this.popupPositionMode = mod(
this.popupPositionMode - 1,
PopupPositionMode.End + 1
);
this.showPopup();
} else if (
navigator.clipboard &&
// It's important we _don't_ enter copy mode when the Ctrl key is being
Expand Down
4 changes: 4 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// JS % operator is a _remainder_ operator
export function mod(a: number, n: number): number {
return ((a % n) + n) % n;
}

0 comments on commit d46a1b7

Please sign in to comment.