mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-09-11 14:36:35 +03:00
feat(frontend): handle no brain selection (#2932)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
685558560c
commit
b6bb55d133
@ -63,7 +63,24 @@ export const Editor = ({
|
||||
return (
|
||||
<EditorContent
|
||||
className="w-full caret-accent"
|
||||
onKeyDown={(event) => void submitOnEnter(event)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" && !event.shiftKey && !currentBrain) {
|
||||
event.preventDefault();
|
||||
const lastChar = editor?.state.doc.textBetween(
|
||||
editor.state.selection.$from.pos - 1,
|
||||
editor.state.selection.$from.pos,
|
||||
undefined,
|
||||
"\ufffc"
|
||||
);
|
||||
if (lastChar === " ") {
|
||||
editor?.chain().insertContent("@").focus().run();
|
||||
} else {
|
||||
editor?.chain().insertContent(" @").focus().run();
|
||||
}
|
||||
} else {
|
||||
submitOnEnter(event);
|
||||
}
|
||||
}}
|
||||
editor={editor}
|
||||
/>
|
||||
);
|
||||
|
@ -16,7 +16,7 @@ export const useCreateEditorState = (placeholder?: string) => {
|
||||
const { BrainMention, items } = useBrainMention();
|
||||
const { remainingCredits } = useUserSettingsContext();
|
||||
|
||||
const PreventEnter = Extension.create({
|
||||
const PreventNewline = Extension.create({
|
||||
addKeyboardShortcuts: () => {
|
||||
return {
|
||||
Enter: () => true,
|
||||
@ -35,7 +35,7 @@ export const useCreateEditorState = (placeholder?: string) => {
|
||||
preserveWhitespace: "full",
|
||||
},
|
||||
extensions: [
|
||||
PreventEnter,
|
||||
PreventNewline,
|
||||
Placeholder.configure({
|
||||
showOnlyWhenEditable: true,
|
||||
placeholder: placeholder ?? t("actions_bar_placeholder"),
|
||||
|
Loading…
Reference in New Issue
Block a user