140140 @select-user-tag =" selectUserTag($event)"
141141 />
142142
143+ <room-Templates-Text
144+ :filtered-templates-text =" filteredTemplatesText"
145+ :active-template =" activeTemplate"
146+ :active-up-or-down =" activeUpOrDown"
147+ @select-template-text =" selectTemplateText($event)"
148+ @active-item =" activeUpOrDown = 0"
149+ />
150+
143151 <room-message-reply
144152 :room =" room"
145153 :message-reply =" messageReply"
210218 }"
211219 @input =" onChangeInput"
212220 @keydown.esc =" escapeTextarea"
213- @keydown.enter.exact.prevent =" "
221+ @keydown.enter.exact.prevent =" beforeEnter "
214222 @paste =" onPasteImage"
223+ @keydown.tab.exact.prevent =" "
224+ @keydown.tab =" activeTemplate = true"
225+ @keydown.up.exact.prevent =" "
226+ @keydown.up =" upActiveTemplate"
227+ @keydown.down.exact.prevent =" "
228+ @keydown.down =" downActiveTemplate"
215229 />
216230
217231 <div class =" vac-icon-textarea" >
264278 type =" file"
265279 multiple
266280 :accept =" acceptedFiles"
267- style =" display :none "
281+ style =" display : none "
268282 @change =" onFileChange($event.target.files)"
269283 />
270284
@@ -298,9 +312,10 @@ import RoomFiles from './RoomFiles/RoomFiles'
298312import RoomMessageReply from ' ./RoomMessageReply/RoomMessageReply'
299313import RoomUsersTag from ' ./RoomUsersTag/RoomUsersTag'
300314import RoomEmojis from ' ./RoomEmojis/RoomEmojis'
315+ import RoomTemplatesText from ' ./RoomTemplatesText/RoomTemplatesText'
301316import Message from ' ../Message/Message'
302317
303- import filteredUsers from ' ../../utils/filter-items'
318+ import filteredItems from ' ../../utils/filter-items'
304319import Recorder from ' ../../utils/recorder'
305320
306321const { detectMobile , iOSDevice } = require (' ../../utils/mobile-detection' )
@@ -327,6 +342,7 @@ export default {
327342 RoomMessageReply,
328343 RoomUsersTag,
329344 RoomEmojis,
345+ RoomTemplatesText,
330346 Message
331347 },
332348
@@ -360,7 +376,8 @@ export default {
360376 linkOptions: { type: Object , required: true },
361377 loadingRooms: { type: Boolean , required: true },
362378 roomInfoEnabled: { type: Boolean , required: true },
363- textareaActionEnabled: { type: Boolean , required: true }
379+ textareaActionEnabled: { type: Boolean , required: true },
380+ templatesText: { type: Array , default: null }
364381 },
365382
366383 emits: [
@@ -398,6 +415,9 @@ export default {
398415 filteredEmojis: [],
399416 filteredUsersTag: [],
400417 selectedUsersTag: [],
418+ filteredTemplatesText: [],
419+ activeTemplate: null ,
420+ activeUpOrDown: null ,
401421 textareaCursorPosition: null ,
402422 cursorRangePosition: null ,
403423 emojisDB: new Database (),
@@ -442,6 +462,7 @@ export default {
442462 return (
443463 !! this .filteredEmojis .length ||
444464 !! this .filteredUsersTag .length ||
465+ !! this .filteredTemplatesText .length ||
445466 !! this .files .length ||
446467 !! this .messageReply
447468 )
@@ -515,14 +536,15 @@ export default {
515536 if (isMobile) {
516537 this .message = this .message + ' \n '
517538 setTimeout (() => this .onChangeInput ())
518- } else {
539+ } else if ( this . filteredTemplatesText . length === 0 ) {
519540 this .sendMessage ()
520541 }
521542 }
522543
523544 setTimeout (() => {
524545 this .updateFooterList (' @' )
525546 this .updateFooterList (' :' )
547+ this .updateFooterList (' /' )
526548 }, 60 )
527549 }),
528550 50
@@ -533,6 +555,7 @@ export default {
533555
534556 this .updateFooterList (' @' )
535557 this .updateFooterList (' :' )
558+ this .updateFooterList (' /' )
536559 })
537560
538561 this .$refs .roomTextarea .addEventListener (' blur' , () => {
@@ -644,6 +667,10 @@ export default {
644667 return
645668 }
646669
670+ if (tagChar === ' /' && ! this .templatesText ) {
671+ return
672+ }
673+
647674 if (
648675 this .textareaCursorPosition === this .$refs .roomTextarea .selectionStart
649676 ) {
@@ -677,6 +704,8 @@ export default {
677704 this .updateEmojis (query)
678705 } else if (tagChar === ' @' ) {
679706 this .updateShowUsersTag (query)
707+ } else if (tagChar === ' /' ) {
708+ this .updateShowTemplatesText (query)
680709 }
681710 } else {
682711 this .resetFooterList (tagChar)
@@ -718,7 +747,7 @@ export default {
718747 this .focusTextarea ()
719748 },
720749 updateShowUsersTag (query ) {
721- this .filteredUsersTag = filteredUsers (
750+ this .filteredUsersTag = filteredItems (
722751 this .room .users ,
723752 ' username' ,
724753 query,
@@ -747,22 +776,65 @@ export default {
747776
748777 this .focusTextarea ()
749778 },
779+ updateShowTemplatesText (query ) {
780+ this .filteredTemplatesText = filteredItems (
781+ this .templatesText ,
782+ ' tag' ,
783+ query,
784+ true
785+ )
786+ },
787+ selectTemplateText (template ) {
788+ this .activeTemplate = false
789+ if (! template) return
790+ const { position , endPosition } = this .getCharPosition (' /' )
791+
792+ const space = this .message .substr (endPosition, endPosition).length
793+ ? ' '
794+ : ' '
795+
796+ this .message =
797+ this .message .substr (0 , position - 1 ) +
798+ template .text +
799+ space +
800+ this .message .substr (endPosition, this .message .length - 1 )
801+
802+ this .cursorRangePosition =
803+ position + template .text .length + space .length + 1
804+ this .focusTextarea ()
805+ },
806+ beforeEnter () {
807+ if (this .filteredTemplatesText .length > 0 ) {
808+ this .activeTemplate = true
809+ }
810+ },
811+ upActiveTemplate () {
812+ this .activeUpOrDown = - 1
813+ },
814+ downActiveTemplate () {
815+ this .activeUpOrDown = 1
816+ },
750817 resetFooterList (tagChar = null ) {
751818 if (tagChar === ' :' ) {
752819 this .filteredEmojis = []
753820 } else if (tagChar === ' @' ) {
754821 this .filteredUsersTag = []
822+ } else if (tagChar === ' /' ) {
823+ this .filteredTemplatesText = []
755824 } else {
756825 this .filteredEmojis = []
757826 this .filteredUsersTag = []
827+ this .filteredTemplatesText = []
758828 }
759829
760830 this .textareaCursorPosition = null
761831 },
762832 escapeTextarea () {
763833 if (this .filteredEmojis .length ) this .filteredEmojis = []
764834 else if (this .filteredUsersTag .length ) this .filteredUsersTag = []
765- else this .resetMessage ()
835+ else if (this .filteredTemplatesText .length ) {
836+ this .filteredTemplatesText = []
837+ } else this .resetMessage ()
766838 },
767839 resetMessage (disableMobileFocus = false , initRoom = false ) {
768840 if (! initRoom) {
0 commit comments