@@ -212,15 +212,16 @@ function messageInputReducer(state, action) {
212212 */
213213export default function useMessageInput ( props ) {
214214 const {
215+ additionalTextareaProps,
216+ clearEditingState,
215217 doImageUploadRequest,
216218 doFileUploadRequest,
219+ errorHandler,
217220 focus,
218221 message,
219- clearEditingState ,
222+ noFiles ,
220223 overrideSubmitHandler,
221224 parent,
222- noFiles,
223- errorHandler,
224225 publishTypingEvent,
225226 } = props ;
226227
@@ -673,9 +674,7 @@ export default function useMessageInput(props) {
673674 ( async ( event ) => {
674675 // TODO: Move this handler to package with ImageDropzone
675676 const { items } = event . clipboardData ;
676- if ( ! dataTransferItemsHaveFiles ( items ) ) {
677- return ;
678- }
677+ if ( ! dataTransferItemsHaveFiles ( items ) ) return ;
679678
680679 event . preventDefault ( ) ;
681680 // Get a promise for the plain text in case no files are
@@ -686,6 +685,7 @@ export default function useMessageInput(props) {
686685 const plainTextItem = [ ...items ] . find (
687686 ( { kind, type } ) => kind === 'string' && type === 'text/plain' ,
688687 ) ;
688+
689689 if ( plainTextItem ) {
690690 plainTextPromise = new Promise ( ( resolve ) => {
691691 plainTextItem . getAsString ( ( s ) => {
@@ -699,14 +699,24 @@ export default function useMessageInput(props) {
699699 uploadNewFiles ( fileLikes ) ;
700700 return ;
701701 }
702+
702703 // fallback to regular text paste
703704 if ( plainTextPromise ) {
704- const s = await plainTextPromise ;
705- insertText ( s ) ;
705+ const { maxLength } = additionalTextareaProps ;
706+ const pastedText = await plainTextPromise ;
707+
708+ if ( pastedText . length > maxLength ) {
709+ dispatch ( {
710+ type : 'setText' ,
711+ getNewText : ( ) => pastedText . slice ( 0 , maxLength ) ,
712+ } ) ;
713+ } else {
714+ insertText ( pastedText ) ;
715+ }
706716 }
707717 } ) ( e ) ;
708718 } ,
709- [ uploadNewFiles , insertText ] ,
719+ [ additionalTextareaProps , insertText , uploadNewFiles ] ,
710720 ) ;
711721
712722 const isUploadEnabled = channel ?. getConfig ?. ( ) ?. uploads !== false ;
0 commit comments