Skip to content

Commit

Permalink
Merge pull request #35 from SmilyOrg/navigation-off-by-one-fix
Browse files Browse the repository at this point in the history
Restore region IDs to be 1-based
  • Loading branch information
SmilyOrg authored Sep 6, 2022
2 parents 8fe1742 + 6b1f685 commit 53a6fe5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions internal/layout/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (regionSource PhotoRegionSource) GetRegionsFromBounds(rect render.Rect, sce
photos := scene.GetVisiblePhotos(rect, regionConfig.Limit)
for photo := range photos {
regions = append(regions, regionSource.getRegionFromPhoto(
photo.Index,
1+photo.Index,
photo.Photo,
scene, regionConfig,
))
Expand All @@ -133,10 +133,10 @@ func (regionSource PhotoRegionSource) GetRegionsFromBounds(rect render.Rect, sce
}

func (regionSource PhotoRegionSource) GetRegionById(id int, scene *render.Scene, regionConfig render.RegionConfig) render.Region {
if id < 0 || id >= len(scene.Photos)-1 {
return render.Region{Id: -1}
if id <= 0 || id > len(scene.Photos) {
return render.Region{}
}
photo := scene.Photos[id]
photo := scene.Photos[id-1]
return regionSource.getRegionFromPhoto(id, &photo, scene, regionConfig)
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (*Api) GetScenesSceneIdRegionsId(w http.ResponseWriter, r *http.Request, sc
}

region := scene.GetRegion(int(id))
if region.Id == -1 {
if region.Id <= 0 {
http.Error(w, "Region not found", http.StatusNotFound)
return
}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/NaturalViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export default {
region(region) {
// console.log("region", this.regionFocusPending, this.region)
if (this.region && this.regionFocusPending) {
this.viewRegion(this.region);
this.focusRegion(this.region);
this.regionFocusPending = null;
this.scrollbarUpdateRegion = this.region;
}
Expand Down Expand Up @@ -926,7 +926,7 @@ export default {
prevId = parseInt(this.regionId, 10);
}
const nextId = prevId + offset;
if (nextId < 0 || nextId >= this.scene.file_count-1) {
if (nextId <= 0 || nextId > this.scene.file_count) {
return;
}
this.regionFocusPending = true;
Expand Down

0 comments on commit 53a6fe5

Please sign in to comment.