@@ -96,6 +96,14 @@ export default {
9696 numberOfLines () {
9797 return this .code .split (/ \r\n | \r | \n / ).length ;
9898 },
99+ customCodeData () {
100+ return {
101+ text: this .language .name === ' Whitespace' ? this .code : this .code .trim ().split (' \n ' ).map ((line ) => line .trimEnd ()).join (' \n ' ),
102+ tabSize: this .selectedSize ,
103+ lines: this .numberOfLines ,
104+ showEditor: true ,
105+ };
106+ },
99107 },
100108 watch: {
101109 async language () {
@@ -118,25 +126,10 @@ export default {
118126 deep: true ,
119127 handler (current ) {
120128 if (current) {
121- this .$socket .client .emit (' customCodeData' , {
122- text: this .code ,
123- tabSize: this .selectedSize ,
124- lines: this .numberOfLines ,
125- showEditor: this .customCode .showEditor ,
126- });
129+ this .emitCustomCode ();
127130 }
128131 },
129132 },
130- selectedSize () {
131- if (this .room .admin ) {
132- this .$socket .client .emit (' customCodeData' , {
133- text: this .code ,
134- tabSize: this .selectedSize ,
135- lines: this .numberOfLines ,
136- showEditor: true ,
137- });
138- }
139- },
140133 },
141134 mounted () {
142135 if (this .code ) {
@@ -177,21 +170,23 @@ export default {
177170 if (this .timeout ) clearTimeout (this .timeout );
178171 this .timeout = setTimeout (() => {
179172 const data = {
180- text: this .code ,
181- tabSize: this .selectedSize ,
182- lines: this .numberOfLines ,
183- showEditor: true ,
173+ ... this .customCodeData ,
184174 short: this .customCode .text .length < 30 || this .customCode .lines < 4 ,
185175 };
186176 this .$store .commit (' SET_CUSTOM_CODE' , data);
187177 if (this .room .admin ) {
188- this .$socket . client . emit ( ' customCodeData ' , data );
178+ this .emitCustomCode ( );
189179 }
190180 }, 50 );
191181 },
192182 clear () {
193183 this .code = ' ' ;
194184 },
185+ emitCustomCode () {
186+ this .$socket .client .emit (' customCodeData' , {
187+ ... this .customCodeData ,
188+ });
189+ },
195190 },
196191};
197192 </script >
0 commit comments