Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
'system' : isSystemMessage,
'combined-system': isCombinedSystemMessage}"
class="message-body">
<MessageBody :rich-parameters="richParameters"
<MessageBody ref="messageBodyInstance"
:rich-parameters="richParameters"
:is-deleting="isDeleting"
:has-call="conversation.hasCall"
:message="message"
Expand Down Expand Up @@ -381,6 +382,21 @@ export default {
token: this.message.token,
id: this.message.id,
})

// Reply to selection
const selection = this.$refs.messageBodyInstance.getSelection()
if (selection) {
console.log('selection', { selection })
const quotedSelection = selection
.trim()
.split('\n')
.map(line => '> ' + line).join('\n')
console.log('quotedSelection', { quotedSelection })
if (quotedSelection) {
EventBus.emit('append-chat-input', quotedSelection)
}
}

EventBus.emit('focus-chat-input')
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
<Quote v-if="message.parent" :message="message.parent" />

<!-- Message content / text -->
<NcRichText :text="renderedMessage"
<NcRichText ref="richTextInstance"
:text="renderedMessage"
:arguments="richParameters"
:class="{'single-emoji': isSingleEmoji}"
autolink
Expand Down Expand Up @@ -442,6 +443,29 @@ export default {
}
EventBus.emit('message-height-changed', { heightDiff: height - oldHeight })
},

/**
* @public
*/
getSelection() {
const selection = window.getSelection()

// Nothing selected
if (selection.rangeCount === 0) {
return ''
}

const range = selection.getRangeAt(0)
const target = range.commonAncestorContainer
const richTextElement = this.$refs.richTextInstance.$el

// Selection is outside of this message
if (richTextElement !== target && !richTextElement.contains(target)) {
return ''
}

return selection.toString()
}
},
}
</script>
Expand Down
14 changes: 14 additions & 0 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ export default {

mounted() {
EventBus.on('focus-chat-input', this.focusInput)
EventBus.on('append-chat-input', this.handleAppendChatInput)
EventBus.on('upload-start', this.handleUploadSideEffects)
EventBus.on('upload-discard', this.handleUploadSideEffects)
EventBus.on('retry-message', this.handleRetryMessage)
Expand All @@ -551,6 +552,7 @@ export default {

beforeDestroy() {
EventBus.off('focus-chat-input', this.focusInput)
EventBus.off('append-chat-input', this.handleAppendChatInput)
EventBus.off('upload-start', this.handleUploadSideEffects)
EventBus.off('upload-discard', this.handleUploadSideEffects)
EventBus.off('retry-message', this.handleRetryMessage)
Expand Down Expand Up @@ -770,6 +772,18 @@ export default {
this.$refs.richContenteditable.showTribute('/')
},

handleAppendChatInput(newTextLine) {
let textToAppend = ''
if (this.text) {
textToAppend += '\n\n'
}
textToAppend += newTextLine
textToAppend += '\n\n'

console.log('textToAppend', { textToAppend })
this.text += textToAppend
},

/**
* Clicks the hidden file input when clicking the correspondent NcActionButton,
* thus opening the file-picker
Expand Down