Skip to content

Commit 4949b9e

Browse files
Add node-specific "Add/View Comment" to game-tree node menu (#940)
Reworks PR #942 against the current architecture (post Electron 14->37 migration, PR #976). The original commits used setting.toggle(), which does not exist on the renderer-side setting shims, so they were reverted and the feature reimplemented here. Per the PR discussion, the original global "Show Comments" toggle in the node context menu (an out-of-place global action in a node-specific menu) is replaced by a node-specific "Add/View Comment" item in the node menu's Annotate submenu. Selecting it reveals the comment box (enabling Show Comments mode, which aids feature discovery), navigates to the clicked node, and enters edit mode with the comment field focused. Also extracts getCommentMenuTemplate() (shared by the node menu's Annotate submenu and the comment-box menu) and a focusCommentBox() helper (shared with setMode), and toggles view.show_comments via setting.set/get directly. Co-authored-by: Robert Christ <robert.christ@gmail.com>
1 parent 2b1501e commit 4949b9e

1 file changed

Lines changed: 50 additions & 7 deletions

File tree

src/modules/sabaki.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,41 @@ class Sabaki extends EventEmitter {
364364
this.setState({deadStones: result})
365365
})
366366
} else if (mode === 'edit') {
367-
this.waitForRender().then(() => {
368-
let textarea = document.querySelector('#properties .edit textarea')
369-
370-
textarea.selectionStart = textarea.selectionEnd = 0
371-
textarea.focus()
372-
})
367+
this.focusCommentBox()
373368
}
374369

375370
this.setState(stateChange)
376371
this.events.emit('modeChange')
377372
}
378373

374+
focusCommentBox() {
375+
this.waitForRender().then(() => {
376+
let textarea = document.querySelector('#properties .edit textarea')
377+
if (textarea == null) return
378+
379+
textarea.selectionStart = textarea.selectionEnd = 0
380+
textarea.focus()
381+
})
382+
}
383+
384+
openCommentEditor(treePosition) {
385+
// Reveal the comment box so the node's comment is visible — this is how
386+
// users discover that nodes can carry comments. Persist the preference
387+
// when it changes so the box stays open afterwards.
388+
if (!setting.get('view.show_comments')) {
389+
setting.set('view.show_comments', true)
390+
}
391+
this.setState({showCommentBox: true})
392+
393+
// Focus the clicked node and enter edit mode so its comment can be read or
394+
// written immediately. setMode('edit') focuses the comment box only when
395+
// switching into edit mode, so focus again to cover the already-in-edit
396+
// case.
397+
this.setCurrentTreePosition(this.inferredState.gameTree, treePosition)
398+
this.setMode('edit')
399+
this.focusCommentBox()
400+
}
401+
379402
openDrawer(drawer) {
380403
this.setState({openDrawer: drawer})
381404
}
@@ -2745,6 +2768,8 @@ class Sabaki extends EventEmitter {
27452768
// Menus
27462769

27472770
openNodeMenu(treePosition, {x, y} = {}) {
2771+
let commentMenu = this.getCommentMenuTemplate(treePosition)
2772+
27482773
let t = i18n.context('menu.edit')
27492774
let template = [
27502775
{
@@ -2785,12 +2810,30 @@ class Sabaki extends EventEmitter {
27852810
label: t('Remove &Other Variations'),
27862811
click: () => this.removeOtherVariations(treePosition),
27872812
},
2813+
{type: 'separator'},
2814+
{
2815+
label: t('&Annotate'),
2816+
submenu: [
2817+
{
2818+
label: t('Add/&View Comment'),
2819+
click: () => this.openCommentEditor(treePosition),
2820+
},
2821+
{type: 'separator'},
2822+
...commentMenu,
2823+
],
2824+
},
27882825
]
27892826

27902827
helper.popupMenu(template, x, y)
27912828
}
27922829

27932830
openCommentMenu(treePosition, {x, y} = {}) {
2831+
let template = this.getCommentMenuTemplate(treePosition)
2832+
2833+
helper.popupMenu(template, x, y)
2834+
}
2835+
2836+
getCommentMenuTemplate(treePosition) {
27942837
let t = i18n.context('menu.comment')
27952838
let node = this.inferredState.gameTree.get(treePosition)
27962839

@@ -2874,7 +2917,7 @@ class Sabaki extends EventEmitter {
28742917
item.click = () => this.setComment(treePosition, item.data)
28752918
}
28762919

2877-
helper.popupMenu(template, x, y)
2920+
return template
28782921
}
28792922

28802923
openVariationMenu(

0 commit comments

Comments
 (0)