Skip to content

Commit

Permalink
added_markdown_sc (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashraj7890 authored Nov 11, 2023
1 parent 0111e28 commit 6009fe8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/react/src/components/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,30 @@ const ChatInput = () => {
// new line with shift enter. do nothing.
return;
}
if (e.ctrlKey && e.key === 'i') {
e.preventDefault();
let start = e.target.selectionStart;
let end = e.target.selectionEnd;
if (end - start > 0) {
const italic = ` _${messageRef.current.value.slice(start, end)}_ `;
messageRef.current.value = (messageRef.current.value.slice(0, start) + italic + messageRef.current.value.slice(end));
} else {
messageRef.current.value = "__";
e.target.setSelectionRange(start + 1, start + 1);
}
}
if (e.ctrlKey && e.key === 'b') {
e.preventDefault();
let start = e.target.selectionStart;
let end = e.target.selectionEnd;
if (end - start > 0) {
const bold = ` *${messageRef.current.value.slice(start, end)}* `;
messageRef.current.value = (messageRef.current.value.slice(0, start) + bold + messageRef.current.value.slice(end));
} else {
messageRef.current.value = "**";
e.target.setSelectionRange(start + 1, start + 1);
}
}
if ((e.ctrlKey || e.metaKey) && e.keyCode === 13) {
// Insert line break in text input field
messageRef.current.value += '\n';
Expand Down

0 comments on commit 6009fe8

Please sign in to comment.