From 55caafb09e86784bf248da76cc62db5d9ede3a32 Mon Sep 17 00:00:00 2001 From: tim Date: Thu, 23 Jul 2020 10:40:55 -0400 Subject: [PATCH] working on remote operations --- .gitignore | 1 + editor.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/.gitignore b/.gitignore index ed3d22f..2fd53c6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .mov .png .jpg +notes.txt diff --git a/editor.js b/editor.js index af0e757..f475af4 100644 --- a/editor.js +++ b/editor.js @@ -28,6 +28,7 @@ class DDLLstring{ this.textWin.insertChar(rc[0],rc[1],char,'remote') } console.log(JSON.stringify(['remote',this.string])) + this.textWin.redraw('insert',char,rc) // modify so that it only redraws if rc is in visible range } deleteFromPos(pos){ @@ -57,6 +58,7 @@ class DDLLstring{ this.textWin.removePrevChar(rc[0],rc[1]+1,'remote') } console.log(JSON.stringify(['remote',this.string])) + this.textWin.redraw('delete',char,rc) // modify so that it only redraws if rc is in visible range } getString(){ @@ -80,6 +82,19 @@ class DDLLstring{ } } +/* +TextWindow models the state of the document. +It receives calls from the Editor using row/col coordinates +for inserting and deleting characters. It translates these into +position based calls and in turn makes calls to the DDLLstring object +which updates the MSET representation of the document and sends MSET +transformations corresponding to the inserts or deletes to the network. + +Likewise, when the DDLLstring object receives an insert or delete operation +from the network, it makes calls to this TextWindow object to update the +state and to redraw the canvas. Note that the DDLLstring object and the +TextWindow object both have links to each other. +*/ class TextWindow{ /** This class will represent a text object and a window onto that text object @@ -97,6 +112,61 @@ class TextWindow{ this.cols = 80 } + setRedrawCanvas(redraw){ + this.redrawCanvas = redraw + } + + redraw(operation,char,rowCol){ + const r = rowCol[0] + const c = rowCol[1] + console.log(`redraw(${operation},${char},[${r},${c}])`) + console.log(`char='\n' ==> ${char=='\n'}`) + if (operation=='insert'){ + if (char=='\n'){ + if (r