Skip to content

Commit

Permalink
Fix format bar position
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Nov 28, 2024
1 parent 95175ca commit 3bfabcc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/views/rooms/MessageComposerFormatBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface IState {

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

public constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -96,7 +101,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 3bfabcc

Please sign in to comment.