Commit b7746336 authored by Christos's avatar Christos

Merge branch 'next-comment' into 'master'

Next comment

See merge request !268
parents bdf04395 df4a8fe6
......@@ -327,6 +327,9 @@ $toolbar-active-bg: rgba(204, 204, 204, 0.75);
width: 26px;
}
}
.fa-comment-o {
outline: none;
}
} // End sc-toolbar
.view-mode {
font-family: 'Fira Sans';
......
import { Tool } from 'substance'
import { FontAwesomeIcon as Icon } from 'substance'
class CommentNextControlTool extends Tool {
getClassNames() {
return 'commnent-next'
}
renderButton($$) {
const el = super.renderButton($$)
return el
}
}
CommentNextControlTool.type = 'comment-next'
export default CommentNextControlTool
......@@ -5,6 +5,8 @@ import CommentBubble from './CommentBubble'
import CommentCommand from './CommentCommand'
import CommentComponent from './CommentComponent'
import CommentHTMLConverter from './CommentHTMLConverter'
import CommentPreviousNextCommand from './CommentPreviousNextCommand'
import CommentNextControlTool from './CommentNextControlTool'
import ResolvedCommentPackage from './ResolvedCommentPackage'
import CommentsProvider from './CommentsProvider'
......@@ -38,6 +40,17 @@ export default {
en: 'Comment',
})
config.addCommand('comment-next', CommentPreviousNextCommand, {
nodeTypes: [Comment.type],
commandGroup: 'comment-control-tools',
actionType: 'next',
})
config.addTool('comment-next', CommentNextControlTool)
config.addIcon('comment-next', { fontawesome: 'fa-comment-o' })
config.addLabel('comment-next', {
en: 'Go to next commment',
})
let controllerKey = 'ctrl'
if (platform.isMac) controllerKey = 'cmd'
......
import { Command } from 'substance'
class CommentPreviousNextCommand extends Command {
getCommandState(params) {
let newState = {
active: false,
disabled: true,
}
if (!params.surface) {
return newState
}
const editorProps = params.surface.context.editor.props
const provider = this.getProvider(params)
const entries = provider.computeEntries()
if (entries.length === 0) return newState
newState = {
active: true,
disabled: false,
}
return newState
}
getCurrentSelection(params) {
const editorSession = params.editorSession
const selection = editorSession.getSelection()
return selection
}
execute(params) {
const provider = this.getProvider(params)
const itemToFocus = this.getNextOrPrevious(params)
provider.focus(itemToFocus)
}
getNextOrPrevious(params) {
const provider = this.getProvider(params)
const actionType = this.getActionType()
if (actionType === 'previous') {
return provider.getPreviousNode()
}
if (actionType === 'next') {
return provider.getNextNode()
}
return false
}
getProvider(params) {
console.log(params)
return params.surface.context.commentsProvider
}
getAnnotationType() {
return this.config.nodeType
}
getActionType() {
return this.config.actionType
}
}
export default CommentPreviousNextCommand
......@@ -42,12 +42,12 @@ class CommentsProvider extends AbstractProvider {
}
handleDocumentChange(change) {
const commentCreated = _
.values(change.created)
.filter(value => value.type === 'comment')
const commentDeleted = _
.values(change.deleted)
.filter(value => value.type === 'comment')
const commentCreated = _.values(change.created).filter(
value => value.type === 'comment',
)
const commentDeleted = _.values(change.deleted).filter(
value => value.type === 'comment',
)
if (!_.isEmpty(commentCreated) || !_.isEmpty(commentDeleted)) {
this.entries = this.computeEntries()
}
......@@ -199,6 +199,25 @@ class CommentsProvider extends AbstractProvider {
editorSession.setSelection(selection)
}
focus(comment) {
const { editorSession } = this.config
const { containerId, node } = comment
let surfaceId = containerId
if (containerId.includes('caption')) {
surfaceId = `main/${containerId.substring(8)}/${containerId}`
}
editorSession.transaction((tx, args) => {
tx.setSelection({
type: 'property',
containerId,
surfaceId,
path: node.path,
startOffset: node.start.offset,
endOffset: node.start.offset,
})
})
}
//
// remove comments from pane if the user wrote nothing in them
......
......@@ -114,6 +114,13 @@ export default {
style: 'minimal',
commandGroups: ['insert-script'],
},
{
name: 'comment-control-tools',
type: 'tool-group',
showDisabled: true,
style: 'minimal',
commandGroups: ['comment-control-tools'],
},
{
name: 'full-screen-control',
type: 'tool-group',
......
......@@ -79,6 +79,13 @@ export default {
style: 'minimal',
commandGroups: ['spell-check-toggle'],
},
{
name: 'comment-control-tools',
type: 'tool-group',
showDisabled: true,
style: 'minimal',
commandGroups: ['comment-control-tools'],
},
{
name: 'full-screen-control',
type: 'tool-group',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment