Skip to content

Commit 7f83512

Browse files
committed
Remove kwywords through context menu.
1 parent 889a6c8 commit 7f83512

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

src/article/manuscript/ManuscriptPackage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ export default {
265265
nodeType: 'footnote',
266266
commandGroup: 'footnote'
267267
})
268-
config.addCommand('remove-keyword', RemoveKeywordCommand)
268+
config.addCommand('remove-metadata-keyword', RemoveKeywordCommand, {
269+
commandGroup: 'custom-metadata-fields'
270+
})
269271
config.addCommand('replace-figure-panel-image', ReplaceFigurePanelImageCommand, {
270272
commandGroup: 'figure-panel'
271273
})

src/article/metadata/MetadataPackage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
TableSelectAllCommand, ToggleCellHeadingCommand, ToggleCellMergeCommand
4242
} from '../manuscript/TableCommands'
4343
import OpenFigurePanelImageTool from '../shared/OpenFigurePanelImageTool'
44+
import RemoveKeywordCommand from '../shared/RemoveKeywordCommand'
4445
import ReplaceFigurePanelTool from '../shared/ReplaceFigurePanelTool'
4546
import TableFigureComponent from '../shared/TableFigureComponent'
4647
import TranslatableEntryEditor from './TranslatableEntryEditor'
@@ -260,6 +261,9 @@ export default {
260261
config.addCommand('remove-figure-panel', RemoveFigurePanelCommand, {
261262
commandGroup: 'figure-panel'
262263
})
264+
config.addCommand('remove-metadata-keyword', RemoveKeywordCommand, {
265+
commandGroup: 'custom-metadata-fields'
266+
})
263267
config.addCommand('remove-reference', RemoveReferenceCommand, {
264268
commandGroup: 'reference'
265269
})

src/article/shared/ArticleToolbarPackage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export default {
373373
config.addLabel('move-down-metadata-field', 'Move Down Metadata Field')
374374
config.addLabel('move-up-metadata-field', 'Move Up Metadata Field')
375375
config.addLabel('remove-metadata-field', 'Remove Metadata Field')
376+
config.addLabel('remove-metadata-keyword', 'Remove Keyword')
376377
// Author tools
377378
config.addLabel('edit-author', 'Edit Author')
378379
// Reference tools

src/article/shared/RemoveKeywordCommand.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,29 @@ import { Command, documentHelpers } from 'substance'
22

33
export default class RemoveKeywordCommand extends Command {
44
getCommandState (params, context) {
5-
return { disabled: false }
5+
const xpath = params.selectionState.xpath
6+
if (xpath.length > 0) {
7+
const selectedType = xpath[xpath.length - 1].type
8+
if (selectedType === 'custom-metadata-value') {
9+
return { disabled: false }
10+
}
11+
}
12+
return { disabled: true }
613
}
714

815
execute (params, context) {
9-
const { path, nodeId, surfaceId } = params
16+
const selectionState = params.selectionState
17+
const node = selectionState.node
18+
const nodeId = node.id
19+
const parentNode = node.getParent()
20+
const path = [parentNode.id, 'values']
1021
const editorSession = context.editorSession
22+
1123
editorSession.transaction(tx => {
1224
const index = tx.get(path).indexOf(nodeId)
13-
const size = tx.get(path).length
14-
if (index === -1) return false
15-
1625
documentHelpers.removeAt(tx, path, index)
1726
documentHelpers.deepDeleteNode(nodeId)
18-
// NOTE: After removing keyword selection should be moved to
19-
// the next reasonable place: next keyword value or new keyword input
20-
if (index < size - 1) {
21-
const nextNodeId = tx.get(path)[index]
22-
tx.setSelection({
23-
type: 'property',
24-
path: [nextNodeId, 'content'],
25-
surfaceId,
26-
startOffset: 0
27-
})
28-
} else {
29-
tx.setSelection({
30-
type: 'custom',
31-
customType: 'keywordInput',
32-
nodeId,
33-
data: { isExpanded: true },
34-
surfaceId
35-
})
36-
}
27+
tx.setSelection(null)
3728
})
3829
}
3930
}

0 commit comments

Comments
 (0)