Skip to content

Commit

Permalink
[BUGFIX beta] Add test to confirm AttrNode does not loose cursor posi…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
rwjblue committed Feb 25, 2015
1 parent 140fe64 commit 72fb390
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/ember-htmlbars/tests/helpers/input_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ QUnit.test("input tabindex is updated when setting tabindex property of view", f
equal(view.$('input').attr('tabindex'), "3", "updates text field after tabindex changes");
});

QUnit.test("cursor position is not lost when updating content", function() {
equal(view.$('input').val(), "hello", "precondition - renders text field with value");

var $input = view.$('input');
var input = $input[0];

// set the cursor position to 3 (no selection)
run(function() {
input.value = 'derp';
input.selectionStart = 3;
input.selectionEnd = 3;
});

run(null, set, controller, 'val', 'derp');

equal(view.$('input').val(), "derp", "updates text field after value changes");

equal(input.selectionStart, 3, 'cursor position was not lost');
equal(input.selectionEnd, 3, 'cursor position was not lost');
});


QUnit.module("{{input type='text'}} - static values", {
setup: function() {
controller = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-views/lib/attr_nodes/attr_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AttrNode.prototype.render = function render(buffer) {
if (this.attrName === 'value' && (value === null || value === undefined)) {
value = '';
}

// If user is typing in a value we don't want to rerender and loose cursor position.
if (this.attrName === 'value' && this._morph.element.value === value) {
return;
Expand Down

0 comments on commit 72fb390

Please sign in to comment.