Skip to content

Commit

Permalink
support soft-breaks in messages (detect shift/alt when pressing Enter…
Browse files Browse the repository at this point in the history
… key and respect line breaks when rendering
  • Loading branch information
twrichards committed Oct 20, 2023
1 parent f560d5c commit 537e496
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion client/src/itemDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ export const ItemDisplay = ({
userLookup,
]
)}
{formattedMessage}
<span
css={css`
white-space: pre-line;
`}
>
{formattedMessage}
</span>
</>
)}
</div>
Expand Down
8 changes: 5 additions & 3 deletions client/src/itemInputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ const Suggestion = ({
</div>
);

const isEnterKey = (event: React.KeyboardEvent<HTMLElement>) =>
event.key === "Enter" || event.keyCode === 13;
const isHardReturn = (event: React.KeyboardEvent<HTMLElement>) =>
(event.key === "Enter" || event.keyCode === 13) &&
!event.shiftKey &&
!event.altKey;

const hostname = window?.location.hostname || ".test.";
const gridDomain =
Expand Down Expand Up @@ -292,7 +294,7 @@ export const ItemInputBox = ({
sendItem &&
((event) => {
event.stopPropagation();
if (isEnterKey(event)) {
if (isHardReturn(event)) {
if (!isAsGridPayloadLoading && (message || payloadToBeSent)) {
sendItem();
}
Expand Down

0 comments on commit 537e496

Please sign in to comment.