compose: Allow pasting plainly, when Shift is held down, for Firefox.

We introduce a state variable `shift_pressed` for the purpose of
detecting whether the Shift key is pressed when pasting content. Only if
it is not, do we proceed with the default formatted paste behavior.

In Chrome, plain paste works out of the box for `Ctrl+Shift+V`, but in
Firefox, we need to handle it ourselves.
This commit is contained in:
N-Shar-ma 2023-11-07 14:00:40 +05:30 committed by Tim Abbott
parent dac56b4d08
commit ff5e389e9b
2 changed files with 11 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import * as stream_data from "./stream_data";
import * as user_status from "./user_status";
export let compose_spinner_visible = false;
export let shift_pressed = false; // true or false
let full_size_status = false; // true or false
// Some functions to handle the full size status explicitly
@ -325,6 +326,9 @@ export function make_compose_box_original_size() {
}
export function handle_keydown(event, $textarea) {
if (event.key === "Shift") {
shift_pressed = true;
}
// The event.key property will have uppercase letter if
// the "Shift + <key>" combo was used or the Caps Lock
// key was on. We turn to key to lowercase so the key bindings
@ -350,6 +354,9 @@ export function handle_keydown(event, $textarea) {
}
export function handle_keyup(_event, $textarea) {
if (_event?.key === "Shift") {
shift_pressed = false;
}
// Set the rtl class if the text has an rtl direction, remove it otherwise
rtl.set_rtl_class_for_textarea($textarea);
}

View File

@ -543,7 +543,10 @@ export function paste_handler(event) {
return;
}
if (paste_html && page_params.development_environment) {
// Unlike Chrome, Firefox doesn't automatically paste plainly on using Ctrl+Shift+V,
// hence we need to handle it ourselves, by checking if shift key is pressed, and only
// if not, we proceed with the default formatted paste.
if (paste_html && !compose_ui.shift_pressed && page_params.development_environment) {
event.preventDefault();
event.stopPropagation();
const text = paste_handler_converter(paste_html);