From c7cdec6c0d4f654ea0cc7481dfedeea9524970f6 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Wed, 20 May 2015 15:55:51 -0700 Subject: [PATCH] Support pressing delete at the end, minus detecting being at the end correctly --- dist/flowy.js | 13 +++++++++++-- dist/flowy.unwrapped.js | 13 +++++++++++-- src/views/todo.js | 13 +++++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/dist/flowy.js b/dist/flowy.js index 0c259cf..8ab18e5 100644 --- a/dist/flowy.js +++ b/dist/flowy.js @@ -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 $("
").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 = $(''); previousNode.setText(previousNode.get("text") + '' + 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") + '' + text); + this.startEditingText({"atMarker": ".focus"}); + return false; + } }, textChange: function(e) { var collection = this.model.collection; diff --git a/dist/flowy.unwrapped.js b/dist/flowy.unwrapped.js index 952da17..a5111ab 100644 --- a/dist/flowy.unwrapped.js +++ b/dist/flowy.unwrapped.js @@ -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 $("
").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 = $(''); previousNode.setText(previousNode.get("text") + '' + 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") + '' + text); + this.startEditingText({"atMarker": ".focus"}); + return false; + } }, textChange: function(e) { var collection = this.model.collection; diff --git a/src/views/todo.js b/src/views/todo.js index d9ce2b2..305e5ec 100644 --- a/src/views/todo.js +++ b/src/views/todo.js @@ -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 $("
").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 = $(''); previousNode.setText(previousNode.get("text") + '' + 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") + '' + text); + this.startEditingText({"atMarker": ".focus"}); + return false; + } }, textChange: function(e) { var collection = this.model.collection; -- 2.47.3