Skip to content

Commit d62e28f

Browse files
author
Bot
committed
trim whitespace in custom code
1 parent 7b0d5c5 commit d62e28f

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/components/CodeEditor.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export default {
160160
if (this.correctCharsInLine === expectedText.length) {
161161
this.cm.execCommand('goCharRight');
162162
this.currentLine += 1;
163+
console.log(`next line ${this.currentLine}`);
163164
164165
this.currentChange = {
165166
...this.currentChange,

src/components/UploadCode.vue

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

src/views/Run.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ export default {
9898
9999
},
100100
created() {
101-
console.log(JSON.parse(JSON.stringify(this.codeInfo)));
102-
103101
if (this.codeInfo && !this.codeInfo.lines) {
104102
// if user opened /run directly
105103
this.$router.push('/');

0 commit comments

Comments
 (0)