Skip to content

Commit

Permalink
Use modulo for doSelectPreviousNextSource
Browse files Browse the repository at this point in the history
  • Loading branch information
ollimeier committed Oct 23, 2024
1 parent e2748b6 commit 987952f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/fontra/views/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
isObjectEmpty,
loadURLFragment,
makeUPlusStringFromCodePoint,
modulo,
parseSelection,
range,
readFromClipboard,
Expand Down Expand Up @@ -2792,18 +2793,18 @@ export class EditorController {
}
const varGlyphController =
await this.sceneModel.getSelectedVariableGlyphController();
const sourceIndex = this.sceneSettings.selectedSourceIndex;
let newSourceIndex;
if (sourceIndex === undefined) {
newSourceIndex = varGlyphController.findNearestSourceFromSourceLocation({

const sourceIndex =
this.sceneSettings.selectedSourceIndex ||
varGlyphController.findNearestSourceFromSourceLocation({
...this.sceneSettings.fontLocationSourceMapped,
...this.sceneSettings.glyphLocation,
});
} else {
const numSources = varGlyphController.sources.length;
newSourceIndex =
(selectPrevious ? sourceIndex + numSources - 1 : sourceIndex + 1) % numSources;
}
const newSourceIndex = modulo(
sourceIndex + (selectPrevious ? -1 : 1),
varGlyphController.sources.length
);

this.sceneController.scrollAdjustBehavior = "pin-glyph-center";
this.sceneSettings.selectedSourceIndex = newSourceIndex;
}
Expand Down

0 comments on commit 987952f

Please sign in to comment.