Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hashtag regex blocking transform to heading #5376

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Hashtags.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,46 @@ test.describe('Hashtags', () => {
`,
);
});

test('Should break when additional # added in front of it', async ({
page,
}) => {
await focusEditor(page);
await page.keyboard.type('#hello');

await waitForSelector(page, '.PlaygroundEditorTheme__hashtag');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span class="PlaygroundEditorTheme__hashtag" data-lexical-text="true">
#hello
</span>
</p>
`,
);
await assertSelection(page, {
anchorOffset: 6,
anchorPath: [0, 0, 0],
focusOffset: 6,
focusPath: [0, 0, 0],
});

await moveToEditorBeginning(page);
await page.keyboard.type('#');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">##hello</span>
</p>
`,
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import {moveToEditorBeginning} from '../../keyboardShortcuts/index.mjs';
import {
assertHTML,
focusEditor,
html,
initialize,
test,
} from '../../utils/index.mjs';

test('Headings - can transform to Headings when it has text', async ({
page,
isPlainText,
isCollab,
}) => {
test.skip(isPlainText);
await initialize({isCollab, page});
await focusEditor(page);

await page.keyboard.type('Welcome to the playground');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Welcome to the playground</span>
</p>
`,
);

await moveToEditorBeginning(page);

for (const level of [1, 2, 3, 4, 5, 6, 1]) {
await page.keyboard.type(`${'#'.repeat(level)} `);

await assertHTML(
page,
html`
<h${level}
class="PlaygroundEditorTheme__h${level} PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Welcome to the playground</span>
</h${level}>
`,
);
}
});
2 changes: 1 addition & 1 deletion packages/lexical-react/src/LexicalHashtagPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function getHashtagRegexString(): string {

const hashtagAlpha = '[' + alpha + ']';
const hashtagAlphanumeric = '[' + alphanumeric + ']';
const hashtagBoundary = '^|$|[^&/' + alphanumeric + ']';
const hashtagBoundary = '^|$|[^&/' + alphanumeric + hashChars + ']';
const hashCharList = '[' + hashChars + ']';

// A hashtag contains characters, numbers and underscores,
Expand Down
Loading