Skip to content

Commit

Permalink
Fix format bar position (#28591)
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros authored Nov 29, 2024
1 parent d68c5a2 commit 2b4ce62
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/views/rooms/MessageComposerFormatBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ interface IState {

export default class MessageComposerFormatBar extends React.PureComponent<IProps, IState> {
private readonly formatBarRef = createRef<HTMLDivElement>();
/**
* The height of the format bar in pixels.
* Height 32px + 2px border
* @private
*/
private readonly BAR_HEIGHT = 34;

public constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -96,7 +102,7 @@ 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`;
const halfBarHeight = this.formatBarRef.current.clientHeight / 2; // used to center the bar
const halfBarHeight = this.BAR_HEIGHT / 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);
Expand Down

0 comments on commit 2b4ce62

Please sign in to comment.