diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index e5549546be9a..642b8c11e61e 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -265,8 +265,8 @@ export default class AnalyseCtrl { }; flip = () => { + 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/chapterNewForm.ts b/ui/analyse/src/study/chapterNewForm.ts index 3d0ad5d5a8d4..13867af9cba3 100644 --- a/ui/analyse/src/study/chapterNewForm.ts +++ b/ui/analyse/src/study/chapterNewForm.ts @@ -210,6 +210,7 @@ export function view(ctrl: StudyChapterNewForm): VNode { orientation: ctrl.orientation, onChange: ctrl.editorFen, coordinates: true, + bindHotkeys: false, }; ctrl.editor = await site.asset.loadEsm('editor', { init: data }); ctrl.editorFen(ctrl.editor.getFen()); 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); diff --git a/ui/editor/src/ctrl.ts b/ui/editor/src/ctrl.ts index afc3bb1e9b68..def6ee0a1f95 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; @@ -49,10 +50,14 @@ export default class EditorCtrl { if (cfg.endgamePositions) cfg.endgamePositions.forEach(p => (p.epd = p.fen.split(' ').splice(0, 4).join(' '))); - site.mousetrap.bind('f', () => { - if (this.chessground) this.chessground.toggleOrientation(); - this.onChange(); - }); + if (this.options.bindHotkeys !== false) + site.mousetrap.bind('f', () => { + if (this.chessground) { + this.chessground.toggleOrientation(); + if (this.options.orientation) this.setOrientation(opposite(this.options.orientation)); + } + this.onChange(); + }); this.castlingToggles = { K: false, Q: false, k: false, q: false }; const params = new URLSearchParams(location.search); diff --git a/ui/editor/src/interfaces.ts b/ui/editor/src/interfaces.ts index 8e554747425c..20cd04c99f96 100644 --- a/ui/editor/src/interfaces.ts +++ b/ui/editor/src/interfaces.ts @@ -40,6 +40,7 @@ export interface Options { onChange?: (fen: string) => void; inlineCastling?: boolean; coordinates?: boolean; + bindHotkeys?: boolean; // defaults to true } export interface OpeningPosition {