Skip to content

Commit 6c2600c

Browse files
committed
Improve navigation backwards
1 parent 74ff7f8 commit 6c2600c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/viewer.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ class Viewer extends EventEmitter {
4040
}
4141
}
4242

43+
// Find the lowest index of all current images
44+
// and return one less than that
4345
get previousIndex() {
44-
if (this.preloader) {
45-
return this.preloader.index - 1
46-
} else {
47-
if (this.ready) {
48-
return this.ready.index - 1
49-
} else {
50-
return -1
51-
}
46+
const p = this.preloader?.index
47+
const r = this.ready?.index
48+
const s = this.showing?.index
49+
const indexes = []
50+
p !== undefined && indexes.push(p)
51+
r !== undefined && indexes.push(r)
52+
s !== undefined && indexes.push(s)
53+
if (indexes.length === 0) {
54+
return -1
5255
}
56+
const min = Math.min(...indexes)
57+
return min - 1
5358
}
5459

5560
get showIndex() {

0 commit comments

Comments
 (0)