Open message in editing mode when keyboard up is pressed (RTE) (#10079)
Move to previous message when arrow up is pressed in the main composer (RTE)
This commit is contained in:
parent
f1a08cd572
commit
2b66cfc25f
11 changed files with 487 additions and 365 deletions
|
@ -15,9 +15,11 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
|
||||
|
||||
import EditorStateTransfer from "../../../../../utils/EditorStateTransfer";
|
||||
import { IRoomState } from "../../../../structures/RoomView";
|
||||
import { ComposerContextState } from "../ComposerContext";
|
||||
|
||||
// From EditMessageComposer private get events(): MatrixEvent[]
|
||||
export function getEventsFromEditorStateTransfer(
|
||||
|
@ -44,3 +46,14 @@ export function getEventsFromEditorStateTransfer(
|
|||
const isInThread = Boolean(editorStateTransfer.getEvent().getThread());
|
||||
return liveTimelineEvents.concat(isInThread ? [] : pendingEvents);
|
||||
}
|
||||
|
||||
// From SendMessageComposer private onKeyDown = (event: KeyboardEvent): void
|
||||
export function getEventsFromRoom(
|
||||
composerContext: ComposerContextState,
|
||||
roomContext: IRoomState,
|
||||
): MatrixEvent[] | undefined {
|
||||
const isReplyingToThread = composerContext.eventRelation?.key === THREAD_RELATION_TYPE.name;
|
||||
return roomContext.liveTimeline
|
||||
?.getEvents()
|
||||
.concat(isReplyingToThread ? [] : roomContext.room?.getPendingEvents() || []);
|
||||
}
|
||||
|
|
|
@ -44,15 +44,21 @@ export function isCaretAtStart(editor: HTMLElement): boolean {
|
|||
const selection = document.getSelection();
|
||||
|
||||
// No selection or the caret is not at the beginning of the selected element
|
||||
if (!selection || selection.anchorOffset !== 0) {
|
||||
if (!selection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// When we are pressing keyboard up in an empty main composer, the selection is on the editor with an anchorOffset at O or 1 (yes, this is strange)
|
||||
const isOnFirstElement = selection.anchorNode === editor && selection.anchorOffset <= 1;
|
||||
if (isOnFirstElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// In case of nested html elements (list, code blocks), we are going through all the first child
|
||||
let child = editor.firstChild;
|
||||
do {
|
||||
if (child === selection.anchorNode) {
|
||||
return true;
|
||||
return selection.anchorOffset === 0;
|
||||
}
|
||||
} while ((child = child?.firstChild || null));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue