[FIX] web_widget_char_switchcase: keep caret position

This commit is contained in:
Simone Rubino
2018-10-18 10:41:39 +02:00
committed by SimoRubi
parent a32d65bd9b
commit 4752f6dc6f
3 changed files with 11 additions and 1 deletions

View File

@@ -21,9 +21,18 @@ odoo.define('web_widget_char_switchcase', function (require) {
console.error(this.current_transformation + ' case unknown');
},
_onKeyUp: function (event) {
// save caret position
var input = this.$input[0];
var start = input.selectionStart;
var end = input.selectionEnd;
// transform the value
var old_val = this.$input.val();
var new_val = this.current_transformation_handler(old_val);
this.$input.val(new_val);
// restore caret position
input.setSelectionRange(start, end);
},
parse_value: function (val, def) {
return this._super(this.current_transformation_handler(val), def);