From a482000c79752e95237d9d10d95ffa21365648b9 Mon Sep 17 00:00:00 2001
From: ngradwohl <guru@local-guru.net>
Date: Sun, 21 Jul 2019 12:15:36 +0200
Subject: [PATCH] fix endless running loops in anim mode

---
 desktop/sources/scripts/commander.js | 15 +++++++++++++--
 desktop/sources/scripts/ronin.js     |  2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js
index 852b2b9..0009196 100644
--- a/desktop/sources/scripts/commander.js
+++ b/desktop/sources/scripts/commander.js
@@ -31,10 +31,21 @@ function Commander (ronin) {
     this.hide()
   }
 
+
+  this._current_txt = ''
+
   this.run = (txt = this._input.value) => {
     if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
-    ronin.interpreter.run(txt)
-    ronin.always === true && requestAnimationFrame(() => this.run(txt))
+    this._current_txt = txt;
+    
+    if ( ronin.always !== true ) {
+        ronin.interpreter.run(this._current_txt)
+    }
+  }
+
+  this.loop = () => {
+    ronin.interpreter.run(this._current_txt)
+    ronin.always === true && requestAnimationFrame(() => this.loop())
   }
 
   this.load = function (txt) {
diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js
index 927d388..7fd5ca9 100644
--- a/desktop/sources/scripts/ronin.js
+++ b/desktop/sources/scripts/ronin.js
@@ -64,7 +64,7 @@ function Ronin () {
   this.animate = (b = true) => {
     if (this.always === b) { return }
     this.always = b
-    this.commander.run()
+    this.commander.loop()
   }
 
   // Zoom