Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Limit formatting bar offset to top of composer #9365

Merged
merged 4 commits into from
Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/views/rooms/MessageComposerFormatBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export default class MessageComposerFormatBar extends React.PureComponent<IProps
this.setState({ visible: true });
const parentRect = this.formatBarRef.current.parentElement.getBoundingClientRect();
this.formatBarRef.current.style.left = `${selectionRect.left - parentRect.left}px`;
// 16 is half the height of the bar (e.g. to center it) and 18 is an offset that felt ok.
this.formatBarRef.current.style.top = `${selectionRect.top - parentRect.top - 16 - 18}px`;
const halfBarHeight = this.formatBarRef.current.clientHeight / 2; // used to center the bar
const offset = halfBarHeight + 2; // makes sure the bar won't cover selected text
const offsetLimit = halfBarHeight + offset;
const position = Math.max(selectionRect.top - parentRect.top - offsetLimit, -offsetLimit);
this.formatBarRef.current.style.top = `${position}px`;
}

public hide(): void {
Expand Down