Skip to content

Commit

Permalink
Unwrap mention tags when entering annotation edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Feb 10, 2025
1 parent cf33ef3 commit cadccc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sidebar/components/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { isMacOS } from '../../shared/user-agent';
import {
getContainingMentionOffsets,
termBeforePosition,
unwrapMentions,
} from '../helpers/mentions';
import {
LinkType,
Expand Down Expand Up @@ -566,6 +567,8 @@ export default function MarkdownEditor({
// The input element where the user inputs their comment.
const input = useRef<HTMLTextAreaElement>(null);

const textWithoutMentionTags = useMemo(() => unwrapMentions(text), [text]);

useEffect(() => {
if (!preview) {
input.current?.focus();
Expand Down Expand Up @@ -624,7 +627,7 @@ export default function MarkdownEditor({
containerRef={input}
onKeyDown={handleKeyDown}
onEditText={onEditText}
value={text}
value={textWithoutMentionTags}
style={textStyle}
mentionsEnabled={mentionsEnabled}
usersForMentions={usersForMentions}
Expand Down
10 changes: 10 additions & 0 deletions src/sidebar/components/test/MarkdownEditor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
import { mount } from '@hypothesis/frontend-testing';
import { render } from 'preact';
import { act } from 'preact/test-utils';
import sinon from 'sinon';

import { wrapMentions } from '../../helpers/mentions';
import { LinkType } from '../../markdown-commands';
import MarkdownEditor, { $imports } from '../MarkdownEditor';

Expand Down Expand Up @@ -313,6 +315,14 @@ describe('MarkdownEditor', () => {
assert.equal(inputField.prop('placeholder'), 'Enter comment');
});

it('unwraps mention tags', () => {
const wrapper = createComponent({
text: wrapMentions('Hello @bob', 'hypothes.is'),
});

assert.equal(wrapper.find('TextArea').prop('value'), 'Hello @bob');
});

describe('keyboard navigation', () => {
let wrapper;

Expand Down

0 comments on commit cadccc1

Please sign in to comment.