From 8db20bc0da10b6e48faf2d9037e5b5d1485dea2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Tue, 19 May 2020 17:11:10 +0200
Subject: [PATCH] [dome] add getValue & setValue to RicheTextBuffer

---
 ivette/src/dome/src/renderer/text/buffers.js | 33 +++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/ivette/src/dome/src/renderer/text/buffers.js b/ivette/src/dome/src/renderer/text/buffers.js
index bf6a2f190b7..30c272d3f99 100644
--- a/ivette/src/dome/src/renderer/text/buffers.js
+++ b/ivette/src/dome/src/renderer/text/buffers.js
@@ -95,9 +95,12 @@ export class RichTextBuffer extends Emitter {
     this.setFocused = this.setFocused.bind(this);
     this.clear = this.clear.bind(this);
     this.append = this.append.bind(this);
+    this.setValue = this.setValue.bind(this);
+    this.getValue = this.getValue.bind(this);
     this.log = this.log.bind(this);
     this._doc.on('change', ( _target , { origin } ) => {
       if (origin !== 'buffer') this.setEdited(true);
+      this.emit('change');
     });
   }
 
@@ -119,14 +122,7 @@ export class RichTextBuffer extends Emitter {
   // --------------------------------------------------------------------------
 
   /** Clear buffer contents and resets _edited_ state. */
-  clear() {
-    this._doc.setValue('');
-    this._edited = false;
-    this._stacked = [] ;
-    this._focused = false ;
-    this._markid = 0 ;
-    this._markers = {} ;
-  }
+  clear() { this.setValue(''); }
 
   /**
      @summary Writes in the buffer.
@@ -171,6 +167,27 @@ export class RichTextBuffer extends Emitter {
     this.scroll();
   }
 
+  /**
+     @summary Replace textual content with the given value.
+     @param {string} [txt] - new text content
+     @description
+     Also remove all markers.
+   */
+  setValue(txt='') {
+    this._doc.setValue(txt);
+    this._edited = false;
+    this._stacked = [] ;
+    this._focused = false ;
+    this._markid = 0 ;
+    this._markers = {} ;
+  }
+
+  /**
+     @summary Return textual content.
+     @return {string}
+  */
+  getValue() { return this._doc.getValue(); }
+
   /**
      @summary Opens a text marker.
      @param {object} options - CodeMirror
-- 
GitLab