From 8f4498506dc2e314d35da3ce91f09aac5310c7c7 Mon Sep 17 00:00:00 2001
From: cmrd Senya <senya@riseup.net>
Date: Thu, 6 Jul 2017 19:32:42 +0300
Subject: [PATCH] Fix autosize for the textarea in conversations

We need to reinit autosize when we navigate in conversations with the backbone router.
---
 app/assets/javascripts/app/views/conversations_inbox_view.js | 1 +
 spec/javascripts/app/views/conversations_inbox_view_spec.js  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/app/assets/javascripts/app/views/conversations_inbox_view.js b/app/assets/javascripts/app/views/conversations_inbox_view.js
index bf8a323e2e..32fe2d2a71 100644
--- a/app/assets/javascripts/app/views/conversations_inbox_view.js
+++ b/app/assets/javascripts/app/views/conversations_inbox_view.js
@@ -24,6 +24,7 @@ app.views.ConversationsInbox = app.views.Base.extend({
         self.selectConversation(conversationId);
         self.setupConversation();
         self.conversationForm.renderMarkdownEditor("#conversation-show .conversation-message-text");
+        autosize(self.$("#conversation-show textarea"));
       }
     });
   },
diff --git a/spec/javascripts/app/views/conversations_inbox_view_spec.js b/spec/javascripts/app/views/conversations_inbox_view_spec.js
index 9de43403b3..756b690dbe 100644
--- a/spec/javascripts/app/views/conversations_inbox_view_spec.js
+++ b/spec/javascripts/app/views/conversations_inbox_view_spec.js
@@ -35,6 +35,7 @@ describe("app.views.ConversationsInbox", function() {
       spyOn(app.views.ConversationsInbox.prototype, "selectConversation");
       spyOn(app.views.ConversationsInbox.prototype, "setupConversation");
       spyOn(app.views.ConversationsForm.prototype, "renderMarkdownEditor");
+      spyOn(window, "autosize");
       this.target.renderConversation(this.conversationId);
       jasmine.Ajax.requests.mostRecent().respondWith({
         status: 200,
@@ -46,6 +47,8 @@ describe("app.views.ConversationsInbox", function() {
       expect(app.views.ConversationsInbox.prototype.selectConversation).toHaveBeenCalledWith(this.conversationId);
       expect(app.views.ConversationsInbox.prototype.setupConversation).toHaveBeenCalled();
       expect(app.views.ConversationsForm.prototype.renderMarkdownEditor).toHaveBeenCalled();
+      expect(window.autosize).toHaveBeenCalled();
+      expect(window.autosize.calls.mostRecent().args[0].is($("#conversation-show textarea")));
       expect($("#conversation-new")).toHaveClass("hidden");
       expect($("#conversation-show")).not.toHaveClass("hidden");
       expect($("#conversation-show #fake-conversation-content").length).toBe(1);
-- 
GitLab