From 13b0b38bbc4ffca0011c023cb45e535815239623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Tue, 11 Feb 2020 16:19:32 +0100 Subject: [PATCH] [Dome/text] added flushline --- Ivette/src/dome/src/renderer/text/buffers.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Ivette/src/dome/src/renderer/text/buffers.js b/Ivette/src/dome/src/renderer/text/buffers.js index be2324b3248..bfe293b4ed5 100644 --- a/Ivette/src/dome/src/renderer/text/buffers.js +++ b/Ivette/src/dome/src/renderer/text/buffers.js @@ -142,16 +142,27 @@ export class Buffer extends Emitter { } } + /** + @summary Starts a new line in the buffer. + @description + If the current buffer content does not finish at the beginning of a fresh line, + inserts a newline character. + */ + flushline() { + const doc = this._doc ; + const from = doc.posFromIndex(Infinity); + if (from.ch > 0) doc.replaceRange('\n',from,undefined,'flush'); + } + /** @summary Appends with newline and auto-scrolling. @param {any} [value] - content to append in the buffer @description - This is a short-cut to `append(...value)`, followed by - `append('\n')` and `scroll()`. + This is a short-cut to `flushline()` followed by `append(...value,'\n')` and `scroll()`. */ log(...value) { - this.append(...value); - this.append('\n'); + this.flushline(); + this.append(...value,'\n'); this.scroll(); } -- GitLab