-
-
+
+
+
+
-
+
-
+
diff --git a/addons/mail/static/src/models/composer_text_input_view.js b/addons/mail/static/src/models/composer_text_input_view.js
new file mode 100644
index 00000000000..1829b576550
--- /dev/null
+++ b/addons/mail/static/src/models/composer_text_input_view.js
@@ -0,0 +1,52 @@
+/** @odoo-module **/
+
+import { registerModel } from '@mail/model/model_core';
+import { attr, one } from '@mail/model/model_field';
+
+registerModel({
+ name: 'ComposerTextInputView',
+ recordMethods: {
+ onComponentUpdate() {
+ if (!this.component.root.el) {
+ return;
+ }
+ if (this.owner.doFocus) {
+ this.owner.update({ doFocus: false });
+ if (this.messaging.device.isSmall) {
+ this.component.root.el.scrollIntoView();
+ }
+ this.textareaRef.el.focus();
+ }
+ if (this.owner.hasToRestoreContent) {
+ this.textareaRef.el.value = this.owner.composer.textInputContent;
+ if (this.owner.isFocused) {
+ this.textareaRef.el.setSelectionRange(
+ this.owner.composer.textInputCursorStart,
+ this.owner.composer.textInputCursorEnd,
+ this.owner.composer.textInputSelectionDirection,
+ );
+ }
+ this.owner.update({ hasToRestoreContent: false });
+ }
+ this.owner.updateTextInputHeight();
+ },
+ },
+ fields: {
+ component: attr(),
+ /**
+ * This is the invisible textarea used to compute the composer height
+ * based on the text content. We need it to downsize the textarea
+ * properly without flicker.
+ */
+ mirroredTextareaRef: attr(),
+ owner: one('ComposerView', {
+ identifying: true,
+ inverse: 'textInput',
+ }),
+ /**
+ * Reference of the textarea. Useful to set height, selection and
+ * content.
+ */
+ textareaRef: attr(),
+ },
+});
diff --git a/addons/mail/static/src/models/composer_view.js b/addons/mail/static/src/models/composer_view.js
index c8aa819b8e2..a459994e73b 100644
--- a/addons/mail/static/src/models/composer_view.js
+++ b/addons/mail/static/src/models/composer_view.js
@@ -284,10 +284,10 @@ registerModel({
return;
}
this.saveStateInStore();
- if (this.textareaLastInputValue !== this.textareaRef.el.value) {
+ if (this.textareaLastInputValue !== this.textInput.textareaRef.el.value) {
this.handleCurrentPartnerIsTyping();
}
- this.update({ textareaLastInputValue: this.textareaRef.el.value });
+ this.update({ textareaLastInputValue: this.textInput.textareaRef.el.value });
this.updateTextInputHeight();
},
/**
@@ -626,10 +626,10 @@ registerModel({
*/
saveStateInStore() {
this.composer.update({
- textInputContent: this.textareaRef.el.value,
- textInputCursorEnd: this.textareaRef.el.selectionEnd,
- textInputCursorStart: this.textareaRef.el.selectionStart,
- textInputSelectionDirection: this.textareaRef.el.selectionDirection,
+ textInputContent: this.textInput.textareaRef.el.value,
+ textInputCursorEnd: this.textInput.textareaRef.el.selectionEnd,
+ textInputCursorStart: this.textInput.textareaRef.el.selectionStart,
+ textInputSelectionDirection: this.textInput.textareaRef.el.selectionDirection,
});
},
/**
@@ -669,8 +669,8 @@ registerModel({
* Updates the textarea height of text input.
*/
updateTextInputHeight() {
- this.mirroredTextareaRef.el.value = this.composer.textInputContent;
- this.textareaRef.el.style.height = this.mirroredTextareaRef.el.scrollHeight + 'px';
+ this.textInput.mirroredTextareaRef.el.value = this.composer.textInputContent;
+ this.textInput.textareaRef.el.style.height = this.textInput.mirroredTextareaRef.el.scrollHeight + 'px';
},
/**
* Update a posted message when the message is ready.
@@ -1302,12 +1302,6 @@ registerModel({
identifying: true,
inverse: 'composerViewInEditing',
}),
- /**
- * This is the invisible textarea used to compute the composer height
- * based on the text content. We need it to downsize the textarea
- * properly without flicker.
- */
- mirroredTextareaRef: attr(),
/**
* Determines the next function to execute after the current mention
* RPC is done, if any.
@@ -1426,10 +1420,10 @@ registerModel({
return this.composer.textInputContent.substring(this.suggestionDelimiterPosition + 1, this.composer.textInputCursorStart);
},
}),
- /**
- * Reference of the textarea. Useful to set height, selection and content.
- */
- textareaRef: attr(),
+ textInput: one('ComposerTextInputView', {
+ default: {},
+ inverse: 'owner',
+ }),
/**
* States the thread view on which this composer allows editing (if any).
*/