Skip to content

Commit

Permalink
Merge pull request #246 from virtualidentityag/feat/DELPHI-189-send-m…
Browse files Browse the repository at this point in the history
…sg-via-keyboard

feat (DELPHI-189): custom key binding
  • Loading branch information
koepferd authored Oct 9, 2024
2 parents eb96843 + 8ff4d2d commit 7145a69
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
branch: ${{env.BRANCH}}
force: true
tags: true
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-videos
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dockerImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts
echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.conf
npm run test:build
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: buildfiles
path: build/**/*
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Download buildfiles artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: buildfiles
path: build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
convertToRaw,
DraftHandleValue,
EditorState,
getDefaultKeyBinding,
RichUtils
} from 'draft-js';
import { draftToMarkdown } from 'markdown-draft-js';
Expand Down Expand Up @@ -404,17 +405,12 @@ export const MessageSubmitInterfaceComponent = ({
]
);

const handleEditorKeyCommand = useCallback(
(command) => {
const newState = RichUtils.handleKeyCommand(editorState, command);
if (newState) {
handleEditorChange(newState);
return 'handled';
}
return 'not-handled';
},
[editorState, handleEditorChange]
);
const handleCustomKeyBinding = (event) => {
if (event.key === 'Enter' && event.shiftKey) {
return 'shift-enter';
}
return getDefaultKeyBinding(event);
};

const resizeTextarea = useCallback(() => {
const textInput: any = textareaInputRef.current;
Expand Down Expand Up @@ -782,6 +778,23 @@ export const MessageSubmitInterfaceComponent = ({
userData
]);

const handleEditorKeyCommand = useCallback(
(command) => {
const newState = RichUtils.handleKeyCommand(editorState, command);
if (command === 'shift-enter') {
handleButtonClick();
return 'handled';
}

if (newState) {
handleEditorChange(newState);
return 'handled';
}
return 'not-handled';
},
[editorState, handleEditorChange, handleButtonClick]
);

const handleRequestFeedbackCheckbox = useCallback(() => {
setRequestFeedbackCheckboxChecked(
(requestFeedbackCheckboxChecked) => !requestFeedbackCheckboxChecked
Expand Down Expand Up @@ -1026,6 +1039,7 @@ export const MessageSubmitInterfaceComponent = ({
handleKeyCommand={
handleEditorKeyCommand
}
keyBindingFn={handleCustomKeyBinding}
placeholder={
hasRequestFeedbackCheckbox &&
requestFeedbackCheckboxChecked
Expand Down

0 comments on commit 7145a69

Please sign in to comment.