Skip to content

Commit

Permalink
fix: do not focus textarea when clicking paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Enter-tainer committed Sep 28, 2024
1 parent 26549e6 commit e6ba21e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions frontend/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const _handleAnchor = async () => {

await _selectOffsetParagraph({
el: paragraph,
focusReply: true,
openCommentsPanel: true,
});

const commentEl = document.querySelector<HTMLDivElement>(
Expand Down Expand Up @@ -196,20 +196,20 @@ const _registerDialog = ({

const _selectOffsetParagraph = async ({
el,
focusReply = false,
openCommentsPanel = false,
}: {
el: HTMLElement;
focusReply?: boolean;
openCommentsPanel?: boolean;
}) => {
if (selectedOffset !== el) {
delete selectedOffset?.dataset.reviewSelected;
selectedOffset = el;
}

if (selectedOffset?.dataset.reviewHasComments || focusReply) {
if (selectedOffset?.dataset.reviewHasComments || openCommentsPanel) {
delete selectedOffset.dataset.reviewFocused;
selectedOffset.dataset.reviewSelected = "true";
await _openCommentsPanel();
await _openCommentsPanel(false);
}
};

Expand All @@ -234,7 +234,7 @@ const _createContextMenu = ({ el }: { el: HTMLElement }) => {
() => {
_selectOffsetParagraph({
el,
focusReply: true,
openCommentsPanel: true,
});
},
],
Expand Down Expand Up @@ -274,7 +274,7 @@ const _closeContextMenu = ({ el }: { el: HTMLElement }) => {
contextMenu.style.display = "none";
};

const _openCommentsPanel = async () => {
const _openCommentsPanel = async (focusTextarea: boolean = true) => {
const comments = [...(await _fetchComments())];

const selected = selectedOffset;
Expand Down Expand Up @@ -317,10 +317,12 @@ const _openCommentsPanel = async () => {
behavior: "smooth",
block: "start",
});
const textarea = selectedCommentsGroup?.querySelector(
".comment_actions_panel textarea",
) as HTMLTextAreaElement | undefined;
textarea?.focus();
if (focusTextarea) {
const textarea = selectedCommentsGroup?.querySelector(
".comment_actions_panel textarea",
) as HTMLTextAreaElement | undefined;
textarea?.focus();
}

commentsButton.classList.add("review_hidden");
commentsPanel.classList.remove("review_hidden");
Expand Down

0 comments on commit e6ba21e

Please sign in to comment.