140
140
@select-user-tag =" selectUserTag($event)"
141
141
/>
142
142
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
+
143
151
<room-message-reply
144
152
:room =" room"
145
153
:message-reply =" messageReply"
210
218
}"
211
219
@input =" onChangeInput"
212
220
@keydown.esc =" escapeTextarea"
213
- @keydown.enter.exact.prevent =" "
221
+ @keydown.enter.exact.prevent =" beforeEnter "
214
222
@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"
215
229
/>
216
230
217
231
<div class =" vac-icon-textarea" >
264
278
type =" file"
265
279
multiple
266
280
:accept =" acceptedFiles"
267
- style =" display :none "
281
+ style =" display : none "
268
282
@change =" onFileChange($event.target.files)"
269
283
/>
270
284
@@ -298,9 +312,10 @@ import RoomFiles from './RoomFiles/RoomFiles'
298
312
import RoomMessageReply from ' ./RoomMessageReply/RoomMessageReply'
299
313
import RoomUsersTag from ' ./RoomUsersTag/RoomUsersTag'
300
314
import RoomEmojis from ' ./RoomEmojis/RoomEmojis'
315
+ import RoomTemplatesText from ' ./RoomTemplatesText/RoomTemplatesText'
301
316
import Message from ' ../Message/Message'
302
317
303
- import filteredUsers from ' ../../utils/filter-items'
318
+ import filteredItems from ' ../../utils/filter-items'
304
319
import Recorder from ' ../../utils/recorder'
305
320
306
321
const { detectMobile , iOSDevice } = require (' ../../utils/mobile-detection' )
@@ -327,6 +342,7 @@ export default {
327
342
RoomMessageReply,
328
343
RoomUsersTag,
329
344
RoomEmojis,
345
+ RoomTemplatesText,
330
346
Message
331
347
},
332
348
@@ -360,7 +376,8 @@ export default {
360
376
linkOptions: { type: Object , required: true },
361
377
loadingRooms: { type: Boolean , required: true },
362
378
roomInfoEnabled: { type: Boolean , required: true },
363
- textareaActionEnabled: { type: Boolean , required: true }
379
+ textareaActionEnabled: { type: Boolean , required: true },
380
+ templatesText: { type: Array , default: null }
364
381
},
365
382
366
383
emits: [
@@ -398,6 +415,9 @@ export default {
398
415
filteredEmojis: [],
399
416
filteredUsersTag: [],
400
417
selectedUsersTag: [],
418
+ filteredTemplatesText: [],
419
+ activeTemplate: null ,
420
+ activeUpOrDown: null ,
401
421
textareaCursorPosition: null ,
402
422
cursorRangePosition: null ,
403
423
emojisDB: new Database (),
@@ -442,6 +462,7 @@ export default {
442
462
return (
443
463
!! this .filteredEmojis .length ||
444
464
!! this .filteredUsersTag .length ||
465
+ !! this .filteredTemplatesText .length ||
445
466
!! this .files .length ||
446
467
!! this .messageReply
447
468
)
@@ -515,14 +536,15 @@ export default {
515
536
if (isMobile) {
516
537
this .message = this .message + ' \n '
517
538
setTimeout (() => this .onChangeInput ())
518
- } else {
539
+ } else if ( this . filteredTemplatesText . length === 0 ) {
519
540
this .sendMessage ()
520
541
}
521
542
}
522
543
523
544
setTimeout (() => {
524
545
this .updateFooterList (' @' )
525
546
this .updateFooterList (' :' )
547
+ this .updateFooterList (' /' )
526
548
}, 60 )
527
549
}),
528
550
50
@@ -533,6 +555,7 @@ export default {
533
555
534
556
this .updateFooterList (' @' )
535
557
this .updateFooterList (' :' )
558
+ this .updateFooterList (' /' )
536
559
})
537
560
538
561
this .$refs .roomTextarea .addEventListener (' blur' , () => {
@@ -644,6 +667,10 @@ export default {
644
667
return
645
668
}
646
669
670
+ if (tagChar === ' /' && ! this .templatesText ) {
671
+ return
672
+ }
673
+
647
674
if (
648
675
this .textareaCursorPosition === this .$refs .roomTextarea .selectionStart
649
676
) {
@@ -677,6 +704,8 @@ export default {
677
704
this .updateEmojis (query)
678
705
} else if (tagChar === ' @' ) {
679
706
this .updateShowUsersTag (query)
707
+ } else if (tagChar === ' /' ) {
708
+ this .updateShowTemplatesText (query)
680
709
}
681
710
} else {
682
711
this .resetFooterList (tagChar)
@@ -718,7 +747,7 @@ export default {
718
747
this .focusTextarea ()
719
748
},
720
749
updateShowUsersTag (query ) {
721
- this .filteredUsersTag = filteredUsers (
750
+ this .filteredUsersTag = filteredItems (
722
751
this .room .users ,
723
752
' username' ,
724
753
query,
@@ -747,22 +776,65 @@ export default {
747
776
748
777
this .focusTextarea ()
749
778
},
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
+ },
750
817
resetFooterList (tagChar = null ) {
751
818
if (tagChar === ' :' ) {
752
819
this .filteredEmojis = []
753
820
} else if (tagChar === ' @' ) {
754
821
this .filteredUsersTag = []
822
+ } else if (tagChar === ' /' ) {
823
+ this .filteredTemplatesText = []
755
824
} else {
756
825
this .filteredEmojis = []
757
826
this .filteredUsersTag = []
827
+ this .filteredTemplatesText = []
758
828
}
759
829
760
830
this .textareaCursorPosition = null
761
831
},
762
832
escapeTextarea () {
763
833
if (this .filteredEmojis .length ) this .filteredEmojis = []
764
834
else if (this .filteredUsersTag .length ) this .filteredUsersTag = []
765
- else this .resetMessage ()
835
+ else if (this .filteredTemplatesText .length ) {
836
+ this .filteredTemplatesText = []
837
+ } else this .resetMessage ()
766
838
},
767
839
resetMessage (disableMobileFocus = false , initRoom = false ) {
768
840
if (! initRoom) {
0 commit comments