changeset 1ec06dda2f8c in sao:6.6
details: https://hg.tryton.org/sao?cmd=changeset&node=1ec06dda2f8c
description:
        Compare text with normalized newlines

        The textarea normalize newlines so if the field value contains \r\n or 
\r, it
        is wrongly considered as modified.

        issue11896
        review437611003
        (grafted from 555c9de0746f064cdb94f61ee899d73d31962e4f)
diffstat:

 src/view/form.js |  17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diffs (33 lines):

diff -r 35704f90a072 -r 1ec06dda2f8c src/view/form.js
--- a/src/view/form.js  Sun Nov 13 10:11:11 2022 +0100
+++ b/src/view/form.js  Thu Nov 24 19:23:52 2022 +0100
@@ -2259,15 +2259,26 @@
         },
         get modified() {
             if (this.record && this.field) {
-                return this.field.get_client(this.record) != this.get_value();
+                var value = this._normalize_newline(
+                    this.field.get_client(this.record));
+                return value != this.get_value();
             }
             return false;
         },
         get_value: function() {
-            return this.input.val() || '';
+            return this._normalize_newline(this.input.val() || '');
         },
         set_value: function() {
-            this.field.set_client(this.record, this.get_value());
+            // avoid modification of not normalized value
+            var value = this.get_value();
+            var prev_value = this.field.get_client(this.record);
+            if (value == this._normalize_newline(prev_value)) {
+                value = prev_value;
+            }
+            this.field.set_client(this.record, value);
+        },
+        _normalize_newline: function(content) {
+            return content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
         },
         set_readonly: function(readonly) {
             Sao.View.Form.Text._super.set_readonly.call(this, readonly);

Reply via email to