From a0ceaecbbd4ab010bbbc9e9b31b04d7cf4a70a3b Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 27 Feb 2024 12:31:16 +0400 Subject: [PATCH] UBERF-5626: set autofocus end on message edit (#4784) Signed-off-by: Kristina Fefelova --- .../text-editor/src/components/ReferenceInput.svelte | 4 ++++ packages/text-editor/src/components/TextEditor.svelte | 2 ++ .../src/components/AttachmentRefInput.svelte | 11 +++-------- .../components/chat-message/ChatMessageInput.svelte | 2 ++ .../chat-message/ChatMessagePresenter.svelte | 4 +++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/text-editor/src/components/ReferenceInput.svelte b/packages/text-editor/src/components/ReferenceInput.svelte index 8d6e938d72..351ddd3268 100644 --- a/packages/text-editor/src/components/ReferenceInput.svelte +++ b/packages/text-editor/src/components/ReferenceInput.svelte @@ -24,6 +24,8 @@ checkAdaptiveMatching } from '@hcengineering/ui' import { createEventDispatcher } from 'svelte' + import { FocusPosition } from '@tiptap/core' + import { Completion } from '../Completion' import textEditorPlugin from '../plugin' import { RefAction, TextEditorHandler, TextFormatCategory } from '../types' @@ -47,6 +49,7 @@ export let loading: boolean = false export let focusable: boolean = false export let boundary: HTMLElement | undefined = undefined + export let autofocus: FocusPosition = false const dispatch = createEventDispatcher() const buttonSize = 'medium' @@ -126,6 +129,7 @@ { if (!isEmpty || haveAttachment) { diff --git a/packages/text-editor/src/components/TextEditor.svelte b/packages/text-editor/src/components/TextEditor.svelte index 95dd4bd03b..8eb89f7f8b 100644 --- a/packages/text-editor/src/components/TextEditor.svelte +++ b/packages/text-editor/src/components/TextEditor.svelte @@ -40,6 +40,7 @@ export let supportSubmit = true export let editorAttributes: Record = {} export let boundary: HTMLElement | undefined = undefined + export let autofocus: FocusPosition = false let element: HTMLElement let editor: Editor @@ -123,6 +124,7 @@ element, editorProps: { attributes: mergeAttributes(defaultEditorAttributes, editorAttributes) }, content, + autofocus, extensions: [ EditorKit, ...(supportSubmit ? [Handle] : []), // order important diff --git a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte index 3464327157..606c4bf0b6 100644 --- a/plugins/attachment-resources/src/components/AttachmentRefInput.svelte +++ b/plugins/attachment-resources/src/components/AttachmentRefInput.svelte @@ -17,14 +17,7 @@ import { Attachment } from '@hcengineering/attachment' import { Account, Class, Doc, generateId, IdMap, Ref, Space, toIdMap } from '@hcengineering/core' import { IntlString, setPlatformStatus, unknownError, Asset } from '@hcengineering/platform' - import { - createQuery, - DraftController, - draftsStore, - getClient, - getFileUrl, - getImageSize - } from '@hcengineering/presentation' + import { createQuery, DraftController, draftsStore, getClient } from '@hcengineering/presentation' import textEditor, { AttachIcon, type RefAction, ReferenceInput } from '@hcengineering/text-editor' import { Loading, type AnySvelteComponent } from '@hcengineering/ui' import { deleteFile, getAttachmentMetadata, uploadFile } from '../utils' @@ -43,6 +36,7 @@ export let attachments: IdMap = new Map() export let loading = false export let focusIndex: number = -1 + export let autofocus = false export function submit (): void { refInput.submit() } @@ -296,6 +290,7 @@ {labelSend} {showSend} {showActions} + autofocus={autofocus ? 'end' : false} loading={loading || progress} {boundary} extraActions={[ diff --git a/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte b/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte index 951047b717..bfd16b3f40 100644 --- a/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte +++ b/plugins/chunter-resources/src/components/chat-message/ChatMessageInput.svelte @@ -29,6 +29,7 @@ export let boundary: HTMLElement | undefined = undefined export let loading = false export let collection: string = 'comments' + export let autofocus = false type MessageDraft = Pick @@ -186,6 +187,7 @@ bind:objectId={_id} {shouldSaveDraft} {boundary} + {autofocus} on:message={onMessage} on:update={onUpdate} on:focus diff --git a/plugins/chunter-resources/src/components/chat-message/ChatMessagePresenter.svelte b/plugins/chunter-resources/src/components/chat-message/ChatMessagePresenter.svelte index 04b64521fb..092c3236aa 100644 --- a/plugins/chunter-resources/src/components/chat-message/ChatMessagePresenter.svelte +++ b/plugins/chunter-resources/src/components/chat-message/ChatMessagePresenter.svelte @@ -174,7 +174,7 @@ {isSelected} {shouldScroll} {embedded} - {withActions} + withActions={withActions && !isEditing} actions={additionalActions} {showEmbedded} {hideFooter} @@ -213,6 +213,8 @@ bind:this={refInput} chatMessage={value} shouldSaveDraft={false} + focusIndex={1000} + autofocus {object} on:submit={() => { isEditing = false