Skip to content

Commit

Permalink
compose: Add destroy autosize on compose_height state change.
Browse files Browse the repository at this point in the history
This commit destroys the autosize of textarea when the full
screen sized compose box is toggled on. And everytime when it is
turned off, it reinitialises the autosize. This also adds a
condition in autosize_textarea to only autosize when composebox
is not in full height state.

Fixes #17660
  • Loading branch information
Signior-X committed Apr 14, 2021
1 parent 8a3c991 commit 0c558c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 9 additions & 5 deletions static/js/compose_actions.js
Expand Up @@ -118,11 +118,15 @@ function clear_box() {
}

export function autosize_message_content() {
autosize($("#compose-textarea"), {
callback() {
maybe_scroll_up_selected_message();
},
});
if (compose_height.get_is_full_size()) {
maybe_scroll_up_selected_message();
} else {
autosize($("#compose-textarea"), {
callback() {
maybe_scroll_up_selected_message();
},
});
}
}

export function expand_compose_box() {
Expand Down
13 changes: 9 additions & 4 deletions static/js/compose_height.js
@@ -1,9 +1,6 @@
// Making this similar to compose_state.js

import autosize from "autosize";
import $ from "jquery";

import * as compose_ui from "./compose_ui";

const compose_textarea = $("#compose-textarea");
let is_full_size = false; // true or false

Expand All @@ -25,6 +22,10 @@ export function get_is_full_size() {
export function make_compose_box_full_size() {
set_is_full_size(true);

// The autosize should be destroyed for the full size compose
// box else it will interfare and shrink its size accordingly.
autosize.destroy($("#compose-textarea"));

compose_textarea.css("max-height", get_expected_full_height());
compose_textarea.css("height", get_expected_full_height());
$("#floating_recipient_bar").css("z-index", -1);
Expand All @@ -39,6 +40,10 @@ export function make_compose_box_original_size() {
compose_textarea.css("max-height", "calc(50vh - 50px)");
$("#floating_recipient_bar").css("z-index", 98);

// Again initialise the compose textarea as it was destroyed
// when compose box was made full screen
autosize($("#compose-textarea"));

$("#collapse_composebox_button").hide();
$("#expand_composebox_button").show();
}
5 changes: 4 additions & 1 deletion static/js/compose_ui.js
@@ -1,14 +1,17 @@
import autosize from "autosize";
import $ from "jquery";

import * as compose_height from "./compose_height";
import {$t} from "./i18n";
import * as people from "./people";
import * as user_status from "./user_status";

export function autosize_textarea(textarea) {
// Since this supports both compose and file upload, one must pass
// in the text area to autosize.
autosize.update(textarea);
if (!compose_height.get_is_full_size()) {
autosize.update(textarea);
}
}

export function smart_insert(textarea, syntax) {
Expand Down

0 comments on commit 0c558c3

Please sign in to comment.