Skip to content

Commit 3eba564

Browse files
committed
fix sd-model selection position issue
1 parent a8e12f8 commit 3eba564

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/directives/model.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,29 @@ module.exports = {
2626
: 'value'
2727

2828
// attach listener
29-
self.set = function () {
30-
self.vm.$set(self.key, el[attr])
31-
}
29+
self.set = self.filters
30+
? function () {
31+
// if this directive has filters
32+
// we need to let the vm.$set trigger
33+
// update() so filters are applied.
34+
// therefore we have to record cursor position
35+
// so that after vm.$set changes the input
36+
// value we can put the cursor back at where it is
37+
var cursorPos
38+
try {
39+
cursorPos = el.selectionStart
40+
} catch (e) {}
41+
self.vm.$set(self.key, el[attr])
42+
if (cursorPos !== undefined) {
43+
el.setSelectionRange(cursorPos, cursorPos)
44+
}
45+
}
46+
: function () {
47+
// no filters, don't let it trigger update()
48+
self.lock = true
49+
self.vm.$set(self.key, el[attr])
50+
self.lock = false
51+
}
3252
el.addEventListener(self.event, self.set)
3353

3454
// fix shit for IE9
@@ -51,6 +71,7 @@ module.exports = {
5171
},
5272

5373
update: function (value) {
74+
if (this.lock) return
5475
/* jshint eqeqeq: false */
5576
var self = this,
5677
el = self.el

0 commit comments

Comments
 (0)