]> git.za3k.com Git - flowy.git/commitdiff
Debounce text editing so you're not undoing/redoing one character at a time master
authorZachary Vance <vanceza@gmail.com>
Thu, 4 Jun 2015 22:09:06 +0000 (15:09 -0700)
committerZachary Vance <vanceza@gmail.com>
Thu, 4 Jun 2015 22:09:06 +0000 (15:09 -0700)
dist/flowy.js
dist/flowy.unwrapped.js
src/models/todo.js
src/views/todo.js

index aa43858a8158f9002c1ac5dcfde1381e9aa2e0a1..0d993dc033192fef1d2fc90371056f3eff9f3fc4 100644 (file)
@@ -448,6 +448,7 @@ var TodoView = Backbone.View.extend({
     return this;
   },
   stopEditingText: function() {
     return this;
   },
   stopEditingText: function() {
+    this.model.flushText();
     this.$el.find("> .text").blur();
     return this;
   },
     this.$el.find("> .text").blur();
     return this;
   },
@@ -627,6 +628,7 @@ var TodoView = Backbone.View.extend({
         console.log("unexpected number of lines in textChange");
     } else if (lines.length === 1) {
         // Normal edit
         console.log("unexpected number of lines in textChange");
     } else if (lines.length === 1) {
         // Normal edit
+        // Debounce it.
         this.model.setText(this.decodeText(lines[0]));
 
     // If there's a line break in the text, they pressed "Enter", and it's more complicated.
         this.model.setText(this.decodeText(lines[0]));
 
     // If there's a line break in the text, they pressed "Enter", and it's more complicated.
@@ -721,10 +723,26 @@ var TodoModel = Backbone.Model.extend({
         this.save({collapsed: !this.get("collapsed")});
     },
     _setText: function(text) {
         this.save({collapsed: !this.get("collapsed")});
     },
     _setText: function(text) {
+        this._text = text;
         return this.save({text: text});
     },
         return this.save({text: text});
     },
-    setText: function(text) {
-        return Actions.App.act(new Actions.ChangeText(this, text));
+    setText: function(text, flush) {
+        this._text = text;
+        if (flush) {
+            this.flushText();
+        } else {
+            this._flushTextDebounced();
+        }
+        return this;
+    },
+    _flushTextDebounced: _.debounce(function() {
+        this.flushText();
+    }, 500),
+    flushText: function(text) {
+        if (!this._text || this.get("text") === this._text) {
+            return;
+        }
+        return Actions.App.act(new Actions.ChangeText(this, this._text));
     },
     hasChildren: function() {
         return this.get("bullets").length > 0;
     },
     hasChildren: function() {
         return this.get("bullets").length > 0;
index 4765349888dc80196c38807acfe5fb8dcbfd6482..8a94f3bec2344aaaa4699aae7783ac2d73707ad2 100644 (file)
@@ -447,6 +447,7 @@ var TodoView = Backbone.View.extend({
     return this;
   },
   stopEditingText: function() {
     return this;
   },
   stopEditingText: function() {
+    this.model.flushText();
     this.$el.find("> .text").blur();
     return this;
   },
     this.$el.find("> .text").blur();
     return this;
   },
@@ -626,6 +627,7 @@ var TodoView = Backbone.View.extend({
         console.log("unexpected number of lines in textChange");
     } else if (lines.length === 1) {
         // Normal edit
         console.log("unexpected number of lines in textChange");
     } else if (lines.length === 1) {
         // Normal edit
+        // Debounce it.
         this.model.setText(this.decodeText(lines[0]));
 
     // If there's a line break in the text, they pressed "Enter", and it's more complicated.
         this.model.setText(this.decodeText(lines[0]));
 
     // If there's a line break in the text, they pressed "Enter", and it's more complicated.
@@ -720,10 +722,26 @@ var TodoModel = Backbone.Model.extend({
         this.save({collapsed: !this.get("collapsed")});
     },
     _setText: function(text) {
         this.save({collapsed: !this.get("collapsed")});
     },
     _setText: function(text) {
+        this._text = text;
         return this.save({text: text});
     },
         return this.save({text: text});
     },
-    setText: function(text) {
-        return Actions.App.act(new Actions.ChangeText(this, text));
+    setText: function(text, flush) {
+        this._text = text;
+        if (flush) {
+            this.flushText();
+        } else {
+            this._flushTextDebounced();
+        }
+        return this;
+    },
+    _flushTextDebounced: _.debounce(function() {
+        this.flushText();
+    }, 500),
+    flushText: function(text) {
+        if (!this._text || this.get("text") === this._text) {
+            return;
+        }
+        return Actions.App.act(new Actions.ChangeText(this, this._text));
     },
     hasChildren: function() {
         return this.get("bullets").length > 0;
     },
     hasChildren: function() {
         return this.get("bullets").length > 0;
index 79e9c743e8410ad4eadbf12cc1499487b9e431a0..a60ff721c0ac22bdff0008b1defbfba55fcace9c 100644 (file)
@@ -15,10 +15,26 @@ var TodoModel = Backbone.Model.extend({
         this.save({collapsed: !this.get("collapsed")});
     },
     _setText: function(text) {
         this.save({collapsed: !this.get("collapsed")});
     },
     _setText: function(text) {
+        this._text = text;
         return this.save({text: text});
     },
         return this.save({text: text});
     },
-    setText: function(text) {
-        return Actions.App.act(new Actions.ChangeText(this, text));
+    setText: function(text, flush) {
+        this._text = text;
+        if (flush) {
+            this.flushText();
+        } else {
+            this._flushTextDebounced();
+        }
+        return this;
+    },
+    _flushTextDebounced: _.debounce(function() {
+        this.flushText();
+    }, 500),
+    flushText: function(text) {
+        if (!this._text || this.get("text") === this._text) {
+            return;
+        }
+        return Actions.App.act(new Actions.ChangeText(this, this._text));
     },
     hasChildren: function() {
         return this.get("bullets").length > 0;
     },
     hasChildren: function() {
         return this.get("bullets").length > 0;
index 25619e19d8bb064af2336ce98a8094f1b36696a1..4d2e0d8c9212ffed39bab2212d434990f3d1456d 100644 (file)
@@ -50,6 +50,7 @@ var TodoView = Backbone.View.extend({
     return this;
   },
   stopEditingText: function() {
     return this;
   },
   stopEditingText: function() {
+    this.model.flushText();
     this.$el.find("> .text").blur();
     return this;
   },
     this.$el.find("> .text").blur();
     return this;
   },
@@ -229,6 +230,7 @@ var TodoView = Backbone.View.extend({
         console.log("unexpected number of lines in textChange");
     } else if (lines.length === 1) {
         // Normal edit
         console.log("unexpected number of lines in textChange");
     } else if (lines.length === 1) {
         // Normal edit
+        // Debounce it.
         this.model.setText(this.decodeText(lines[0]));
 
     // If there's a line break in the text, they pressed "Enter", and it's more complicated.
         this.model.setText(this.decodeText(lines[0]));
 
     // If there's a line break in the text, they pressed "Enter", and it's more complicated.