diff --git a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx index 42f454f3..c5b81873 100644 --- a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx +++ b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx @@ -288,17 +288,20 @@ export class SerialMonitorOutput extends React.Component { - chunk += data; - const eolIndex = chunk.indexOf('\n'); - if (eolIndex !== -1) { - const line = chunk.substring(0, eolIndex + 1); - chunk = chunk.slice(eolIndex + 1); - const content = `${this.state.content}${this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''}${line}`; - this.setState({ content }); + const rawLines = data.split('\n'); + const lines: string[] = [] + const timestamp = () => this.state.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''; + for (let i = 0; i < rawLines.length; i++) { + if (i === 0 && this.state.content.length !== 0) { + lines.push(rawLines[i]); + } else { + lines.push(timestamp() + rawLines[i]); + } } + const content = this.state.content + lines.join('\n'); + this.setState({ content }); }), this.props.clearConsoleEvent(() => this.setState({ content: '' })), this.props.monitorModel.onChange(({ property }) => {