From 1237dec3d54ffbf1ed414962c05aefecc4f5b17a Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Thu, 30 Jan 2025 18:02:50 -0800 Subject: [PATCH 1/5] When in the editor form for a new chapter, make pressing 'f' only flip the editor board and not the open chapter in the background. --- ui/analyse/src/ctrl.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index 6c79e9af7997..fb40c59e8887 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -265,6 +265,7 @@ export default class AnalyseCtrl { }; flip = () => { + if (this.study?.chapters.newForm.isOpen()) return; this.flipped = !this.flipped; this.study?.onFlip(); this.chessground?.set({ From 1d20ca4c15d5504d4f32c12366e653f0605d8750 Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Fri, 31 Jan 2025 19:19:04 -0800 Subject: [PATCH 2/5] In the editor for a new chapter, make pressing `f` be essentially equivalent to manually toggling the orientation dropdown value. --- ui/analyse/src/study/chapterNewForm.ts | 6 ++++++ ui/editor/src/ctrl.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ui/analyse/src/study/chapterNewForm.ts b/ui/analyse/src/study/chapterNewForm.ts index 3d0ad5d5a8d4..de88ca22cb04 100644 --- a/ui/analyse/src/study/chapterNewForm.ts +++ b/ui/analyse/src/study/chapterNewForm.ts @@ -15,6 +15,7 @@ import type { StudyChapters } from './studyChapters'; import type { LichessEditor } from 'editor'; import { pubsub } from 'common/pubsub'; import { lichessRules } from 'chessops/compat'; +import { opposite } from 'chessground/util'; export const modeChoices = [ ['normal', i18n.study.normalAnalysis], @@ -51,6 +52,11 @@ export class StudyChapterNewForm { ) { pubsub.on('analysis.closeAll', () => this.isOpen(false)); this.orientation = root.bottomColor(); + site.mousetrap.bind('f', () => { + if (this.isOpen() && this.editor) + this.orientation = (document.getElementById('chapter-orientation') as HTMLInputElement).value = + opposite(this.orientation as Color); + }); } open = () => { diff --git a/ui/editor/src/ctrl.ts b/ui/editor/src/ctrl.ts index afc3bb1e9b68..415ca93de927 100644 --- a/ui/editor/src/ctrl.ts +++ b/ui/editor/src/ctrl.ts @@ -18,6 +18,7 @@ import { makeFen, parseFen, parseCastlingFen, INITIAL_FEN, EMPTY_FEN } from 'che import { lichessVariant, lichessRules } from 'chessops/compat'; import { defined, prop, type Prop } from 'common'; import { prompt } from 'common/dialog'; +import { opposite } from 'chessground/util'; export default class EditorCtrl { options: Options; @@ -51,6 +52,7 @@ export default class EditorCtrl { site.mousetrap.bind('f', () => { if (this.chessground) this.chessground.toggleOrientation(); + if (this.options.orientation) this.setOrientation(opposite(this.options.orientation)); this.onChange(); }); From 336447837fb513186b7b3865ce205de0c2a83a85 Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Fri, 31 Jan 2025 19:52:34 -0800 Subject: [PATCH 3/5] Move `setOrientation` call within if stmt. --- ui/editor/src/ctrl.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/editor/src/ctrl.ts b/ui/editor/src/ctrl.ts index 415ca93de927..2db44d2cffb9 100644 --- a/ui/editor/src/ctrl.ts +++ b/ui/editor/src/ctrl.ts @@ -51,8 +51,10 @@ export default class EditorCtrl { cfg.endgamePositions.forEach(p => (p.epd = p.fen.split(' ').splice(0, 4).join(' '))); site.mousetrap.bind('f', () => { - if (this.chessground) this.chessground.toggleOrientation(); - if (this.options.orientation) this.setOrientation(opposite(this.options.orientation)); + if (this.chessground) { + this.chessground.toggleOrientation(); + if (this.options.orientation) this.setOrientation(opposite(this.options.orientation)); + } this.onChange(); }); From f8f32ad54d507658700e969a741c1ebb793fa580 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 2 Feb 2025 12:11:41 +0100 Subject: [PATCH 4/5] remove knowledge of `study?.chapters.newForm` from analyse/ctrl --- ui/analyse/src/ctrl.ts | 3 +-- ui/analyse/src/study/studyCtrl.ts | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index 1afb60105859..642b8c11e61e 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -265,9 +265,8 @@ export default class AnalyseCtrl { }; flip = () => { - if (this.study?.chapters.newForm.isOpen()) return; + if (this.study?.onFlip() === false) return; this.flipped = !this.flipped; - this.study?.onFlip(); this.chessground?.set({ orientation: this.bottomColor(), }); diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index d1e9af6a6789..782e1d5fee48 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -534,7 +534,11 @@ export default class StudyCtrl { else this.chapters.localPaths[this.vm.chapterId] = this.ctrl.path; // don't remember position on gamebook this.practice?.onJump(); }; - onFlip = () => this.chapterFlipMapProp(this.data.chapter.id, this.ctrl.flipped); + onFlip = () => { + if (this.chapters.newForm.isOpen()) return false; + this.chapterFlipMapProp(this.data.chapter.id, this.ctrl.flipped); + return true; + }; isClockTicking = (path: Tree.Path) => path !== '' && this.data.chapter.relayPath === path && !isFinished(this.data.chapter); From bce7ff12e49f38f2a274749898fa1c88081e858f Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 2 Feb 2025 12:25:18 +0100 Subject: [PATCH 5/5] don't bind the f hotkey in the study chapter board editor that doesn't seem useful, there's a