return caretPos;
}
+function setRangeAtMarker(markerElement, options) {
+ options = options || {};
+ if (window.getSelection && document.createRange) {
+ var range = document.createRange();
+ range.setStartBefore(markerElement);
+ range.setEndBefore(markerElement);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ if (options.remove) {
+ markerElement.parentNode.removeChild(markerElement);
+ }
+}
+
/**
* @depend ../library/cursorToEnd.js
*/
},
startEditingText: function(options) {
options = options || {};
- if (!options.atEnd) {
- this.$el.find("> .text").focus();
- } else {
+ if (options.atEnd) {
setEndOfContenteditable(this.$el.find("> .text")[0]);
+ } else if (options.atMarker) {
+ var marker = this.$el.find("> .text").find(options.atMarker)[0];
+ if (!marker) {
+ console.log("Marker not found");
+ return;
+ }
+ setRangeAtMarker(marker, {"remove": true});
+ } else {
+ this.$el.find("> .text").focus();
}
return this;
},
if (!previousNode) {
return;
}
- if (this.model.get("text") === "") { // Or focus is at the beginning
+ if (this.model.get("text") === "") {
e.preventDefault();
this.model.remove(this.model.collection);
previousNode.getView().startEditingText({"atEnd":true});
- } else if (this.isFocusAtBeginning()) {
+ } else if (this.isFocusAtBeginning() && e.keyCode !== 8 /* backspace only */) {
e.preventDefault();
var text = this.model.get("text");
this.model.remove(this.model.collection);
- // TODO: Keep focus between the two halves
- // var focusReminderElement = this.$("<span class=\"focus\"></span>")
- previousNode.setText(previousNode.get("text")/* + focusReminderElement*/ + text);
- previousNode.getView().startEditingText(/*{"atMarker": focusReminderElement}*/);
+ var focusReminderElement = $('<span class="focus"></span>');
+ previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
+ previousNode.getView().startEditingText({"atMarker": ".focus"});
}
},
textChange: function(e) {
}
return this;
},
- template: "<div class=\"text\" contenteditable=\"plaintext-only\">{{text}}</div><div class=\"bullets\"></div>",
+ template: "<div class=\"text\" contenteditable=\"plaintext-only\">{{{text}}}</div><div class=\"bullets\"></div>",
addChild: function(el, position) {
if(typeof position === 'undefined' || position === -1) {
console.log("TodoView:addChild called without a position");
return caretPos;
}
+function setRangeAtMarker(markerElement, options) {
+ options = options || {};
+ if (window.getSelection && document.createRange) {
+ var range = document.createRange();
+ range.setStartBefore(markerElement);
+ range.setEndBefore(markerElement);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ if (options.remove) {
+ markerElement.parentNode.removeChild(markerElement);
+ }
+}
+
/**
* @depend ../library/cursorToEnd.js
*/
},
startEditingText: function(options) {
options = options || {};
- if (!options.atEnd) {
- this.$el.find("> .text").focus();
- } else {
+ if (options.atEnd) {
setEndOfContenteditable(this.$el.find("> .text")[0]);
+ } else if (options.atMarker) {
+ var marker = this.$el.find("> .text").find(options.atMarker)[0];
+ if (!marker) {
+ console.log("Marker not found");
+ return;
+ }
+ setRangeAtMarker(marker, {"remove": true});
+ } else {
+ this.$el.find("> .text").focus();
}
return this;
},
if (!previousNode) {
return;
}
- if (this.model.get("text") === "") { // Or focus is at the beginning
+ if (this.model.get("text") === "") {
e.preventDefault();
this.model.remove(this.model.collection);
previousNode.getView().startEditingText({"atEnd":true});
- } else if (this.isFocusAtBeginning()) {
+ } else if (this.isFocusAtBeginning() && e.keyCode !== 8 /* backspace only */) {
e.preventDefault();
var text = this.model.get("text");
this.model.remove(this.model.collection);
- // TODO: Keep focus between the two halves
- // var focusReminderElement = this.$("<span class=\"focus\"></span>")
- previousNode.setText(previousNode.get("text")/* + focusReminderElement*/ + text);
- previousNode.getView().startEditingText(/*{"atMarker": focusReminderElement}*/);
+ var focusReminderElement = $('<span class="focus"></span>');
+ previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
+ previousNode.getView().startEditingText({"atMarker": ".focus"});
}
},
textChange: function(e) {
}
return this;
},
- template: "<div class=\"text\" contenteditable=\"plaintext-only\">{{text}}</div><div class=\"bullets\"></div>",
+ template: "<div class=\"text\" contenteditable=\"plaintext-only\">{{{text}}}</div><div class=\"bullets\"></div>",
addChild: function(el, position) {
if(typeof position === 'undefined' || position === -1) {
console.log("TodoView:addChild called without a position");
}
return caretPos;
}
+
+function setRangeAtMarker(markerElement, options) {
+ options = options || {};
+ if (window.getSelection && document.createRange) {
+ var range = document.createRange();
+ range.setStartBefore(markerElement);
+ range.setEndBefore(markerElement);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ if (options.remove) {
+ markerElement.parentNode.removeChild(markerElement);
+ }
+}
},
startEditingText: function(options) {
options = options || {};
- if (!options.atEnd) {
- this.$el.find("> .text").focus();
- } else {
+ if (options.atEnd) {
setEndOfContenteditable(this.$el.find("> .text")[0]);
+ } else if (options.atMarker) {
+ var marker = this.$el.find("> .text").find(options.atMarker)[0];
+ if (!marker) {
+ console.log("Marker not found");
+ return;
+ }
+ setRangeAtMarker(marker, {"remove": true});
+ } else {
+ this.$el.find("> .text").focus();
}
return this;
},
if (!previousNode) {
return;
}
- if (this.model.get("text") === "") { // Or focus is at the beginning
+ if (this.model.get("text") === "") {
e.preventDefault();
this.model.remove(this.model.collection);
previousNode.getView().startEditingText({"atEnd":true});
- } else if (this.isFocusAtBeginning()) {
+ } else if (this.isFocusAtBeginning() && e.keyCode !== 8 /* backspace only */) {
e.preventDefault();
var text = this.model.get("text");
this.model.remove(this.model.collection);
- // TODO: Keep focus between the two halves
- // var focusReminderElement = this.$("<span class=\"focus\"></span>")
- previousNode.setText(previousNode.get("text")/* + focusReminderElement*/ + text);
- previousNode.getView().startEditingText(/*{"atMarker": focusReminderElement}*/);
+ var focusReminderElement = $('<span class="focus"></span>');
+ previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
+ previousNode.getView().startEditingText({"atMarker": ".focus"});
}
},
textChange: function(e) {
}
return this;
},
- template: "<div class=\"text\" contenteditable=\"plaintext-only\">{{text}}</div><div class=\"bullets\"></div>",
+ template: "<div class=\"text\" contenteditable=\"plaintext-only\">{{{text}}}</div><div class=\"bullets\"></div>",
addChild: function(el, position) {
if(typeof position === 'undefined' || position === -1) {
console.log("TodoView:addChild called without a position");