Add CTRL + ENTER to force send message.

Fix: cursor jumping to the end of message area.
Fix: inconsistent message send button on mobile.
This commit is contained in:
Paul 2021-08-30 18:01:32 +01:00
parent 3628aeffdd
commit d368820aeb
5 changed files with 36 additions and 19 deletions

View file

@ -6,6 +6,7 @@ import { decodeTime } from "ulid";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
import { useDictionary } from "../../../lib/i18n"; import { useDictionary } from "../../../lib/i18n";
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import { dayjs } from "../../../context/Locale"; import { dayjs } from "../../../context/Locale";
@ -34,9 +35,11 @@ export default styled.div<BaseMessageProps>`
flex-direction: row; flex-direction: row;
padding-inline-end: 16px; padding-inline-end: 16px;
@media (pointer: coarse) { ${() =>
user-select: none; isTouchscreenDevice &&
} css`
user-select: none;
`}
${(props) => ${(props) =>
props.contrast && props.contrast &&

View file

@ -3,7 +3,7 @@ import Axios, { CancelTokenSource } from "axios";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { ChannelPermission } from "revolt.js/dist/api/permissions"; import { ChannelPermission } from "revolt.js/dist/api/permissions";
import { Channel } from "revolt.js/dist/maps/Channels"; import { Channel } from "revolt.js/dist/maps/Channels";
import styled from "styled-components"; import styled, { css } from "styled-components";
import { ulid } from "ulid"; import { ulid } from "ulid";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
@ -99,11 +99,13 @@ const Action = styled.div`
padding: 12px; padding: 12px;
} }
.mobile { ${() =>
@media (pointer: fine) { !isTouchscreenDevice &&
display: none; css`
} .mobile {
} display: none;
}
`}
`; `;
// For sed replacement // For sed replacement
@ -503,6 +505,11 @@ export default observer(({ channel }: Props) => {
value={draft ?? ""} value={draft ?? ""}
padding="var(--message-box-padding)" padding="var(--message-box-padding)"
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.ctrlKey && e.key === "Enter") {
e.preventDefault();
return send();
}
if (onKeyDown(e)) return; if (onKeyDown(e)) return;
if ( if (

View file

@ -1,10 +1,11 @@
import { DownArrowAlt } from "@styled-icons/boxicons-regular"; import { DownArrowAlt } from "@styled-icons/boxicons-regular";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { Channel } from "revolt.js/dist/maps/Channels"; import { Channel } from "revolt.js/dist/maps/Channels";
import styled from "styled-components"; import styled, { css } from "styled-components";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
import { isTouchscreenDevice } from "../../../../lib/isTouchscreenDevice";
import { getRenderer } from "../../../../lib/renderer/Singleton"; import { getRenderer } from "../../../../lib/renderer/Singleton";
const Bar = styled.div` const Bar = styled.div`
@ -42,11 +43,13 @@ const Bar = styled.div`
transform: translateY(1px); transform: translateY(1px);
} }
@media (pointer: coarse) { ${() =>
height: 34px; isTouchscreenDevice &&
top: -32px; css`
padding: 0 12px; height: 34px;
} top: -32px;
padding: 0 12px;
`}
} }
`; `;

View file

@ -37,9 +37,11 @@ export default styled.div<Props>`
padding: 0 12px; padding: 0 12px;
}*/ }*/
@media (pointer: coarse) { ${() =>
height: 56px; isTouchscreenDevice &&
} css`
height: 56px;
`}
${(props) => ${(props) =>
props.background && props.background &&

View file

@ -99,7 +99,9 @@ export default function TextAreaAutoSize(props: TextAreaAutoSizeProps) {
// ? it is a quick and dirty hack to fix // ? it is a quick and dirty hack to fix
// ? value not setting correctly // ? value not setting correctly
// ? I have no clue what's going on // ? I have no clue what's going on
ref.current.value = value; // ref.current.value = value;
// * commented out of 30-08-21
// * hopefully nothing breaks :v
if (!autoFocus) return; if (!autoFocus) return;
function keyDown(e: KeyboardEvent) { function keyDown(e: KeyboardEvent) {