]> git.za3k.com Git - flowy.git/commitdiff
Support pressing delete at the end, minus detecting being at the end correctly
authorZachary Vance <vanceza@gmail.com>
Wed, 20 May 2015 22:55:51 +0000 (15:55 -0700)
committerZachary Vance <vanceza@gmail.com>
Wed, 20 May 2015 22:55:51 +0000 (15:55 -0700)
dist/flowy.js
dist/flowy.unwrapped.js
src/views/todo.js

index 0c259cfe47fbaff904af00cb71ddecd5a15244fc..8ab18e5da8887caca908d7dca9d82659340af018 100644 (file)
@@ -353,6 +353,9 @@ var TodoView = Backbone.View.extend({
   isFocusAtBeginning: function() {
     return getCaretPosition(this.$el.find("> .text")[0]) === 0;
   },
+  isFocusAtEnd: function() {
+    return false; // TODO
+  },
   decodeText: function(encodedText) {
     return $("<div/>").html(encodedText).text();
   },
@@ -385,7 +388,6 @@ var TodoView = Backbone.View.extend({
     } else if (this.isFocusAtBeginning()) {
         var text = this.model.get("text");
         this.model.remove(this.model.collection);
-        var focusReminderElement = $('<span class="focus"></span>');
         previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
         previousNode.getView().startEditingText({"atMarker": ".focus"});
         return false;
@@ -403,7 +405,14 @@ var TodoView = Backbone.View.extend({
         this.model.remove(this.model.collection);
         nextNode.getView().startEditingText();
         return false;
-    }
+    } else if (this.isFocusAtEnd()) {
+        var text = nextNode.get("text");
+        nextNode.remove(this.model.collection);
+        this.stopEditingText();
+        this.model.setText(this.model.get("text") + '<span class="focus"></span>' + text);
+        this.startEditingText({"atMarker": ".focus"});
+        return false;
+    }   
   },
   textChange: function(e) {
     var collection = this.model.collection;
index 952da17b84a4d0df15598c83d1382be5e9eb5cd2..a5111ab7af0db4e3e47358cbe099e7fcafcbb1a6 100644 (file)
@@ -352,6 +352,9 @@ var TodoView = Backbone.View.extend({
   isFocusAtBeginning: function() {
     return getCaretPosition(this.$el.find("> .text")[0]) === 0;
   },
+  isFocusAtEnd: function() {
+    return false; // TODO
+  },
   decodeText: function(encodedText) {
     return $("<div/>").html(encodedText).text();
   },
@@ -384,7 +387,6 @@ var TodoView = Backbone.View.extend({
     } else if (this.isFocusAtBeginning()) {
         var text = this.model.get("text");
         this.model.remove(this.model.collection);
-        var focusReminderElement = $('<span class="focus"></span>');
         previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
         previousNode.getView().startEditingText({"atMarker": ".focus"});
         return false;
@@ -402,7 +404,14 @@ var TodoView = Backbone.View.extend({
         this.model.remove(this.model.collection);
         nextNode.getView().startEditingText();
         return false;
-    }
+    } else if (this.isFocusAtEnd()) {
+        var text = nextNode.get("text");
+        nextNode.remove(this.model.collection);
+        this.stopEditingText();
+        this.model.setText(this.model.get("text") + '<span class="focus"></span>' + text);
+        this.startEditingText({"atMarker": ".focus"});
+        return false;
+    }   
   },
   textChange: function(e) {
     var collection = this.model.collection;
index d9ce2b2bf05e41442f0661542b2e4088704d0c09..305e5ec99d58a88e6a3299ff9de1e963dd0cad8b 100644 (file)
@@ -43,6 +43,9 @@ var TodoView = Backbone.View.extend({
   isFocusAtBeginning: function() {
     return getCaretPosition(this.$el.find("> .text")[0]) === 0;
   },
+  isFocusAtEnd: function() {
+    return false; // TODO
+  },
   decodeText: function(encodedText) {
     return $("<div/>").html(encodedText).text();
   },
@@ -75,7 +78,6 @@ var TodoView = Backbone.View.extend({
     } else if (this.isFocusAtBeginning()) {
         var text = this.model.get("text");
         this.model.remove(this.model.collection);
-        var focusReminderElement = $('<span class="focus"></span>');
         previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
         previousNode.getView().startEditingText({"atMarker": ".focus"});
         return false;
@@ -93,7 +95,14 @@ var TodoView = Backbone.View.extend({
         this.model.remove(this.model.collection);
         nextNode.getView().startEditingText();
         return false;
-    }
+    } else if (this.isFocusAtEnd()) {
+        var text = nextNode.get("text");
+        nextNode.remove(this.model.collection);
+        this.stopEditingText();
+        this.model.setText(this.model.get("text") + '<span class="focus"></span>' + text);
+        this.startEditingText({"atMarker": ".focus"});
+        return false;
+    }   
   },
   textChange: function(e) {
     var collection = this.model.collection;