User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens the editor where the comment stands: after any move, in a variation too (the flow is cut at the move), or at the start of the game; Enter — done, Esc — cancel, Shift+Enter — a paragraph; another move writes the draft; one edit — one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the position in the editor and in the menu. The right mouse button draws arrows and circles on the board ([%cal]/[%csl] of the current move; colours by modifiers). Existing comments are edited and deleted; their commands and untouched bytes are kept. chess_core: with_text, with_shapes, shapes, Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
9967d6b759
commit
dc7d9f88b3
15 changed files with 1592 additions and 71 deletions
|
|
@ -9,10 +9,11 @@ use shakmaty::{CastlingMode, Move, Position, san::SanPlus, uci::UciMove};
|
|||
use crate::game::{Game, GameMove, MoveKind, NodeId};
|
||||
use crate::nag::Nag;
|
||||
|
||||
/// NAGs and trailing comments of a node (what annotation edits change).
|
||||
/// NAGs and comments of a node (what annotation edits change).
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Annotations {
|
||||
nags: Vec<Nag>,
|
||||
comments_before: Vec<String>,
|
||||
comments_after: Vec<String>,
|
||||
}
|
||||
|
||||
|
|
@ -263,10 +264,12 @@ impl Game {
|
|||
let node = self.node(id).ok_or(EditError::UnknownNode)?;
|
||||
let old = Annotations {
|
||||
nags: node.nags.clone(),
|
||||
comments_before: node.comments_before.clone(),
|
||||
comments_after: node.comments_after.clone(),
|
||||
};
|
||||
let new = Annotations {
|
||||
nags,
|
||||
comments_before: old.comments_before.clone(),
|
||||
comments_after,
|
||||
};
|
||||
if old != new {
|
||||
|
|
@ -275,6 +278,31 @@ impl Game {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Replaces the comments before the move of `id` (an introduction to a line).
|
||||
/// Undoable; no-op if unchanged.
|
||||
pub fn set_comments_before(
|
||||
&mut self,
|
||||
id: NodeId,
|
||||
comments_before: Vec<String>,
|
||||
) -> Result<(), EditError> {
|
||||
self.check_attached(id)?;
|
||||
let node = self.node(id).ok_or(EditError::UnknownNode)?;
|
||||
let old = Annotations {
|
||||
nags: node.nags.clone(),
|
||||
comments_before: node.comments_before.clone(),
|
||||
comments_after: node.comments_after.clone(),
|
||||
};
|
||||
let new = Annotations {
|
||||
nags: old.nags.clone(),
|
||||
comments_before,
|
||||
comments_after: old.comments_after.clone(),
|
||||
};
|
||||
if old != new {
|
||||
self.record(Command::Annotate { node: id, old, new });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Runs `f` so that all its edits form a single undo step.
|
||||
pub fn edit_group<R>(&mut self, f: impl FnOnce(&mut Game) -> R) -> R {
|
||||
let outer = self.group.replace(Vec::new());
|
||||
|
|
@ -345,6 +373,7 @@ impl Game {
|
|||
Command::Annotate { node, new, .. } => {
|
||||
if let Some(n) = self.node_mut(*node) {
|
||||
n.nags.clone_from(&new.nags);
|
||||
n.comments_before.clone_from(&new.comments_before);
|
||||
n.comments_after.clone_from(&new.comments_after);
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue