Skip to content

Commit 208fee6

Browse files
committed
Fix: Correct invert some shortcuts in manga reading
1 parent 02b67c6 commit 208fee6

3 files changed

Lines changed: 101 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111
- Allow disabling `Do not enlarge more than its original size` in Webtoon mode [`7519ac5`](https://github.com/ollm/OpenComic/commit/7519ac5cd0ac4407a4d0edec7e7a3e2a76832f84)
1212
- Improved rotation and support for rotating in PDF [`cb90771`](https://github.com/ollm/OpenComic/commit/cb907714ca7d713bcbf3471564e48a3e67c8ca40)
1313
- PDFs are rendered to a blob image instead of a canvas [`554c1ef`](https://github.com/ollm/OpenComic/commit/554c1ef88adf358acae14f9bf28f0e1f4f626d8f)
14-
- Optimized sidebar thumbnails
14+
- Optimized sidebar thumbnails [`02b67c6`](https://github.com/ollm/OpenComic/commit/02b67c620b6b13810c778beca1052a9b28829548)
1515

1616
##### 🐛 Bug Fixes
1717

@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2222
- Some mime types are not correct detected [`baa8397`](https://github.com/ollm/OpenComic/commit/baa8397da5f33b5129607bbcc368c4eb782bc4e9)
2323
- Update electron to fix white lines in Webtoon mode [`2b98eb3`](https://github.com/ollm/OpenComic/commit/2b98eb3af7c1651149063e6176a5ae7e6b3d1c81)
2424
- Navigation back not working with shortcuts and gamepad [`ba8641f`](https://github.com/ollm/OpenComic/commit/ba8641f96ed3c8bdef8e35ce98af55b7e6d10bc8)
25+
- Correct invert some shortcuts in manga reading
2526

2627
## [v1.5.0](https://github.com/ollm/OpenComic/releases/tag/v1.5.0) (19-06-2025)
2728

scripts/reading.js

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -855,21 +855,38 @@ function changeHeaderButtons(scrollInStart = null, scrollInEnd = null)
855855

856856
if((scrollInStart === null || scrollInStart) && currentIndex == 1 && !((readingViewIs('scroll') && (_config.readingViewAdjustToWidth || _config.readingWebtoon)) && currentPageVisibility > 0))
857857
{
858-
prevIsPrevComic = true;
859-
canGoPrev = dom.previousComic();
858+
if(readingManga())
859+
{
860+
prevIsPrevComic = true;
861+
canGoPrev = dom.nextComic();
862+
}
863+
else
864+
{
865+
prevIsPrevComic = true;
866+
canGoPrev = dom.previousComic();
867+
}
860868
}
861869

862870
if((scrollInEnd === null || scrollInEnd) && currentIndex == indexNum && !((readingViewIs('scroll') && (_config.readingViewAdjustToWidth || _config.readingWebtoon)) && currentPageVisibility < maxPageVisibility))
863871
{
864-
nextIsNextComic = true;
865-
canGoNext = dom.nextComic();
872+
if(readingManga())
873+
{
874+
nextIsNextComic = true;
875+
canGoNext = dom.previousComic();
876+
}
877+
else
878+
{
879+
nextIsNextComic = true;
880+
canGoNext = dom.nextComic();
881+
}
866882
}
867883

868884
let currentChangeHeaderButtons = {
869885
prevIsPrevComic: prevIsPrevComic,
870886
nextIsNextComic: nextIsNextComic,
871887
canGoPrev: canGoPrev,
872888
canGoNext: canGoNext,
889+
readingManga: readingManga(),
873890
};
874891

875892
if(!isEqual(prevChangeHeaderButtons, currentChangeHeaderButtons))
@@ -880,12 +897,14 @@ function changeHeaderButtons(scrollInStart = null, scrollInEnd = null)
880897
dom.this([next, lastPage]).class(!canGoNext, 'disable-pointer');
881898

882899
firstPage.innerHTML = prevIsPrevComic ? 'skip_previous' : 'first_page';
883-
firstPage.setAttribute('hover-text', prevIsPrevComic ? language.reading.prevChapter : language.reading.firstPage);
884-
885900
lastPage.innerHTML = nextIsNextComic ? 'skip_next' : 'last_page';
886-
lastPage.setAttribute('hover-text', nextIsNextComic ? language.reading.nextChapter : language.reading.lastPage);
887901

888-
if(config.readingTrackingAtTheEnd && !trackingCurrent && ((_config.readingManga && prevIsPrevComic) || (!_config.readingManga && nextIsNextComic)))
902+
prev.setAttribute('hover-text', readingManga() ? language.reading.next : language.reading.previous);
903+
next.setAttribute('hover-text', readingManga() ? language.reading.previous : language.reading.next);
904+
firstPage.setAttribute('hover-text', readingManga() ? (prevIsPrevComic ? language.reading.nextChapter : language.reading.lastPage) : (prevIsPrevComic ? language.reading.prevChapter : language.reading.firstPage));
905+
lastPage.setAttribute('hover-text', readingManga() ? (nextIsNextComic ? language.reading.prevChapter : language.reading.firstPage) : (nextIsNextComic ? language.reading.nextChapter : language.reading.lastPage));
906+
907+
if(config.readingTrackingAtTheEnd && !trackingCurrent && ((readingManga() && prevIsPrevComic) || (!readingManga() && nextIsNextComic)))
889908
{
890909
trackingCurrent = true;
891910
tracking.track();
@@ -1014,7 +1033,7 @@ function goToImage(imageIndex, disableSave = false)
10141033

10151034
let newIndex = imagesData[imageIndex].position + 1;
10161035

1017-
if(_config.readingManga && !readingViewIs('scroll'))
1036+
if(readingManga())
10181037
newIndex = (indexNum - newIndex) + 1;
10191038

10201039
calculateRealReadingDirection(newIndex);
@@ -1033,7 +1052,7 @@ function goToFolder(folderIndex)
10331052

10341053
let newIndex = foldersPosition[folderIndex] + 1;
10351054

1036-
if(_config.readingManga && !readingViewIs('scroll'))
1055+
if(readingManga())
10371056
newIndex = (indexNum - newIndex) + 1;
10381057

10391058
calculateRealReadingDirection(newIndex);
@@ -1340,7 +1359,7 @@ function goToIndex(index, animation = true, nextPrevious = false, end = false)
13401359

13411360
let newIndex = (eIndex - 1);
13421361

1343-
if(_config.readingManga && !readingViewIs('scroll'))
1362+
if(readingManga())
13441363
newIndex = (indexNum - newIndex) - 1;
13451364

13461365
if(updateCurrentIndex)
@@ -1416,7 +1435,7 @@ function goToChapterProgress(chapterIndex, chapterProgress, animation = true)
14161435
if(readingDoublePage())
14171436
index = Math.ceil(index / 2);
14181437

1419-
if(_config.readingManga && !readingViewIs('scroll'))
1438+
if(readingManga())
14201439
index = (indexNum - closest.page.index);
14211440

14221441
reading.goToIndex(index, animation);
@@ -1445,11 +1464,11 @@ function goNext()
14451464

14461465
music.soundEffect.page();
14471466
}
1448-
else if(currentIndex == indexNum && dom.nextComic() && (!_config.readingManga || readingViewIs('scroll')))
1467+
else if(currentIndex == indexNum && dom.nextComic() && !readingManga())
14491468
{
14501469
showNextComic(1, true);
14511470
}
1452-
else if(currentIndex == indexNum && dom.previousComic() && _config.readingManga && !readingViewIs('scroll'))
1471+
else if(currentIndex == indexNum && dom.previousComic() && readingManga())
14531472
{
14541473
showNextComic(1, true, true);
14551474
}
@@ -1477,11 +1496,11 @@ function goPrevious()
14771496

14781497
music.soundEffect.page();
14791498
}
1480-
else if(previousIndex == 0 && dom.previousComic() && (!_config.readingManga || readingViewIs('scroll')))
1499+
else if(previousIndex == 0 && dom.previousComic() && !readingManga())
14811500
{
14821501
showPreviousComic(1, true);
14831502
}
1484-
else if(previousIndex == 0 && dom.nextComic() && _config.readingManga && !readingViewIs('scroll'))
1503+
else if(previousIndex == 0 && dom.nextComic() && readingManga())
14851504
{
14861505
showPreviousComic(1, true, true);
14871506
}
@@ -1490,11 +1509,12 @@ function goPrevious()
14901509
//Go to the start of the comic
14911510
function goStart(force = false)
14921511
{
1493-
if(force || !_config.readingManga || readingViewIs('scroll'))
1512+
if(force || !readingManga() || 1)
14941513
{
1514+
const hasComic = readingManga() ? dom.nextComic() : dom.previousComic();
14951515
saveReadingProgressA = true;
14961516

1497-
if((currentIndex > indexNum || (currentIndex - 1 == 0 && dom.previousComic())) && (!maxPageVisibility || currentPageVisibility == 0))
1517+
if((currentIndex > indexNum || (currentIndex - 1 == 0 && hasComic)) && (!maxPageVisibility || currentPageVisibility == 0))
14981518
{
14991519
goPrevious();
15001520

@@ -1518,7 +1538,9 @@ function goStart(force = false)
15181538

15191539
function goPrevComic()
15201540
{
1521-
if(dom.previousComic())
1541+
const hasComic = readingManga() ? dom.nextComic() : dom.previousComic();
1542+
1543+
if(hasComic)
15221544
{
15231545
let speed = _config.readingViewSpeed;
15241546
_config.readingViewSpeed = 0;
@@ -1533,11 +1555,12 @@ function goPrevComic()
15331555
//Go to the end of the comic
15341556
function goEnd(force = false)
15351557
{
1536-
if(force || !_config.readingManga || readingViewIs('scroll'))
1558+
if(force || !readingManga() || 1)
15371559
{
1560+
const hasComic = readingManga() ? dom.previousComic() : dom.nextComic();
15381561
saveReadingProgressA = true;
15391562

1540-
if((currentIndex < 1 || (currentIndex == indexNum && dom.nextComic())) && (!maxPageVisibility || maxPageVisibility == currentPageVisibility))
1563+
if((currentIndex < 1 || (currentIndex == indexNum && hasComic)) && (!maxPageVisibility || maxPageVisibility == currentPageVisibility))
15411564
{
15421565
goNext();
15431566

@@ -1561,7 +1584,9 @@ function goEnd(force = false)
15611584

15621585
function goNextComic()
15631586
{
1564-
if(dom.nextComic())
1587+
const hasComic = readingManga() ? dom.previousComic() : dom.nextComic();
1588+
1589+
if(hasComic)
15651590
{
15661591
let speed = _config.readingViewSpeed;
15671592
_config.readingViewSpeed = 0;
@@ -3034,6 +3059,11 @@ function readingDoublePage()
30343059
return (_config.readingDoublePage && !_config.readingWebtoon);
30353060
}
30363061

3062+
function readingManga()
3063+
{
3064+
return (_config.readingManga && !readingViewIs('scroll'));
3065+
}
3066+
30373067
var activeOnScroll = true;
30383068

30393069
function disableOnScroll(disable = true)
@@ -3380,7 +3410,7 @@ function reloadIndex()
33803410
let imageIndex = false;
33813411
let newIndex = (currentIndex - 1);
33823412

3383-
if(_config.readingManga && !readingViewIs('scroll'))
3413+
if(readingManga())
33843414
newIndex = (indexNum - newIndex) - 1;
33853415

33863416
eachImagesDistribution(newIndex, ['image'], function(image) {
@@ -3496,7 +3526,7 @@ function createAndDeleteBookmark(index = false)
34963526

34973527
let newIndex = (currentIndex - 1);
34983528

3499-
if(_config.readingManga && !readingViewIs('scroll'))
3529+
if(readingManga())
35003530
newIndex = (indexNum - newIndex) - 1;
35013531

35023532
eachImagesDistribution(newIndex, ['image'], function(image){
@@ -3601,7 +3631,7 @@ function saveReadingProgress(path = false, mainPath = false)
36013631

36023632
let newIndex = (currentIndex - 1);
36033633

3604-
if(_config.readingManga && !readingViewIs('scroll'))
3634+
if(readingManga())
36053635
newIndex = (indexNum - newIndex) - 1;
36063636

36073637
eachImagesDistribution(newIndex, ['image'], function(image){
@@ -4588,7 +4618,7 @@ async function generateEbookPages(end = false, reset = false, fast = false, imag
45884618

45894619
let newIndex = currentIndex;
45904620

4591-
if(_config.readingManga && !readingViewIs('scroll'))
4621+
if(readingManga())
45924622
newIndex = (indexNum - newIndex) + 1;
45934623

45944624
if(nextOpenChapterProgress)
@@ -4611,7 +4641,7 @@ function currentImagePosition()
46114641
{
46124642
let index = currentIndex - 1;
46134643

4614-
if(_config.readingManga && !reading.readingViewIs('scroll'))
4644+
if(readingManga())
46154645
index = (indexNum - index) - 1;
46164646

46174647
return index;
@@ -5620,7 +5650,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
56205650

56215651
var newIndex = currentIndex;
56225652

5623-
if(_config.readingManga && !readingViewIs('scroll'))
5653+
if(readingManga())
56245654
newIndex = (indexNum - newIndex) + 1;
56255655

56265656
goToIndex(newIndex, false, end, end);
@@ -5675,7 +5705,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
56755705

56765706
var newIndex = currentIndex;
56775707

5678-
if(_config.readingManga && !readingViewIs('scroll'))
5708+
if(readingManga())
56795709
newIndex = (indexNum - newIndex) + 1;
56805710

56815711
goToIndex(newIndex, false, end, end);
@@ -5810,6 +5840,8 @@ module.exports = {
58105840
rotateImage: rotateImage,
58115841
setIsLoaded: function(value){isLoaded=value},
58125842
isLoaded: function(value){return isLoaded},
5843+
doublePage: readingDoublePage,
5844+
manga: readingManga,
58135845
isLoad: isLoad,
58145846
onLoad: onLoad,
58155847
ebook: readingEbook,

scripts/shortcuts.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function clickTapZone(event, button)
5151
pageY = pageY / rect.height;
5252
pageX = pageX / rect.width;
5353

54-
if(config.invertTapZonesInManga && _config.readingManga && !reading.readingViewIs('scroll'))
54+
if(config.invertTapZonesInManga && reading.manga())
5555
pageX = 1 - pageX;
5656

5757
const vertical = (pageY > 0.66666 ? 'bottom' : (pageY > 0.33333 ? 'center' : 'top'));
@@ -84,6 +84,13 @@ function shortcutSnackbar(string, status = null)
8484
});
8585
}
8686

87+
const mangaInvert = new Set([
88+
'ArrowRight',
89+
'ArrowLeft',
90+
'KeyD',
91+
'KeyA',
92+
]);
93+
8794
function loadShortcuts()
8895
{
8996
shortcuts = {
@@ -368,7 +375,7 @@ function loadShortcuts()
368375

369376
const code = event?.code || '';
370377

371-
if(_config.readingManga && !reading.readingViewIs('scroll') && !/Arrow|KeyD$|KeyA$/iu.test(code))
378+
if(reading.manga() && !mangaInvert.has(code))
372379
reading.goNext();
373380
else
374381
reading.goPrev();
@@ -383,7 +390,7 @@ function loadShortcuts()
383390

384391
const code = event?.code || '';
385392

386-
if(_config.readingManga && !reading.readingViewIs('scroll') && !/Arrow|KeyD$|KeyA$/iu.test(code))
393+
if(reading.manga() && !mangaInvert.has(code))
387394
reading.goPrev();
388395
else
389396
reading.goNext();
@@ -398,7 +405,13 @@ function loadShortcuts()
398405

399406
if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
400407
{
401-
reading.goStart();
408+
const code = event?.code || '';
409+
410+
if(reading.manga() && !mangaInvert.has(code))
411+
reading.goEnd();
412+
else
413+
reading.goStart();
414+
402415
return true;
403416
}
404417
else if(!reading.zoomingIn())
@@ -416,7 +429,13 @@ function loadShortcuts()
416429

417430
if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
418431
{
419-
reading.goEnd();
432+
const code = event?.code || '';
433+
434+
if(reading.manga() && !mangaInvert.has(code))
435+
reading.goStart();
436+
else
437+
reading.goEnd();
438+
420439
return true;
421440
}
422441
else if(!reading.zoomingIn())
@@ -434,7 +453,13 @@ function loadShortcuts()
434453

435454
if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
436455
{
437-
reading.goPrevComic();
456+
const code = event?.code || '';
457+
458+
if(reading.manga() && !mangaInvert.has(code))
459+
reading.goNextComic();
460+
else
461+
reading.goPrevComic();
462+
438463
return true;
439464
}
440465
else if(!reading.zoomingIn())
@@ -450,10 +475,15 @@ function loadShortcuts()
450475
name: language.reading.nextChapter,
451476
function: function(event){
452477

453-
454478
if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
455479
{
456-
reading.goNextComic();
480+
const code = event?.code || '';
481+
482+
if(reading.manga() && !mangaInvert.has(code))
483+
reading.goPrevComic();
484+
else
485+
reading.goNextComic();
486+
457487
return true;
458488
}
459489
else if(!reading.zoomingIn())

0 commit comments

Comments
 (0)