Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make 'f' correctly toggle the orientation in a new chapter form #16904

Merged
2 changes: 1 addition & 1 deletion ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/src/study/chapterNewForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LichessEditor>('editor', { init: data });
ctrl.editorFen(ctrl.editor.getFen());
Expand Down
6 changes: 5 additions & 1 deletion ui/analyse/src/study/studyCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions ui/editor/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions ui/editor/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface Options {
onChange?: (fen: string) => void;
inlineCastling?: boolean;
coordinates?: boolean;
bindHotkeys?: boolean; // defaults to true
}

export interface OpeningPosition {
Expand Down