Skip to content

Commit

Permalink
Remove capital letter mentions (facebook#4991)
Browse files Browse the repository at this point in the history
  • Loading branch information
acywatson authored Sep 13, 2023
1 parent 75c9ae5 commit 10b4e14
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test.describe('Clear All Formatting', () => {

await clearEditor(page);

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');

await waitForSelector(page, '#typeahead-menu ul li');
await assertHTML(
Expand All @@ -142,7 +142,7 @@ test.describe('Clear All Formatting', () => {
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Luke</span>
<span data-lexical-text="true">@Luke</span>
</p>
`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ test.describe('Composition', () => {
await focusEditor(page);
await enableCompositionKeyEvents(page);

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await waitForSelector(page, '#typeahead-menu ul li');
await page.keyboard.press('Enter');

Expand Down Expand Up @@ -491,7 +491,7 @@ test.describe('Composition', () => {
await focusEditor(page);
await enableCompositionKeyEvents(page);

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await waitForSelector(page, '#typeahead-menu ul li');
await page.keyboard.press('Enter');

Expand Down Expand Up @@ -558,7 +558,7 @@ test.describe('Composition', () => {
await focusEditor(page);
await enableCompositionKeyEvents(page);

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await waitForSelector(page, '#typeahead-menu ul li');
await page.keyboard.press('Enter');

Expand Down
123 changes: 81 additions & 42 deletions packages/lexical-playground/__tests__/e2e/Mentions.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ test.describe('Mentions', () => {

test(`Can enter the Luke Skywalker mention`, async ({page}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Luke</span>
<span data-lexical-text="true">@Luke</span>
</p>
`,
);
Expand Down Expand Up @@ -99,22 +103,26 @@ test.describe('Mentions', () => {
page,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Luke</span>
<span data-lexical-text="true">@Luke</span>
</p>
`,
);
Expand Down Expand Up @@ -190,22 +198,26 @@ test.describe('Mentions', () => {
page,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Luke</span>
<span data-lexical-text="true">@Luke</span>
</p>
`,
);
Expand Down Expand Up @@ -262,22 +274,26 @@ test.describe('Mentions', () => {
page,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Luke</span>
<span data-lexical-text="true">@Luke</span>
</p>
`,
);
Expand Down Expand Up @@ -334,22 +350,26 @@ test.describe('Mentions', () => {
page,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Luke</span>
<span data-lexical-text="true">@Luke</span>
</p>
`,
);
Expand Down Expand Up @@ -435,16 +455,20 @@ test.describe('Mentions', () => {
focusPath: [0, 0, 0],
});

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');

await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);

await waitForSelector(page, '#typeahead-menu ul li');
await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">abc Luke def</span>
<span data-lexical-text="true">abc @Luke def</span>
</p>
`,
);
Expand Down Expand Up @@ -505,42 +529,54 @@ test.describe('Mentions', () => {
browserName,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');

await waitForSelector(page, '.mention');

await page.keyboard.type(' ');

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');

await waitForSelector(page, '.mention:nth-child(1)');

await page.keyboard.type(' ');

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');

await waitForSelector(page, '.mention:nth-child(3)');

await page.keyboard.type(' ');

await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');

await waitForSelector(page, '.mention:nth-child(5)');
Expand Down Expand Up @@ -814,15 +850,18 @@ test.describe('Mentions', () => {
page,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await page.keyboard.type('@Luke');
await assertSelection(page, {
anchorOffset: 4,
anchorOffset: 5,
anchorPath: [0, 0, 0],
focusOffset: 4,
focusOffset: 5,
focusPath: [0, 0, 0],
});

await waitForSelector(page, '#typeahead-menu ul li');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');

await waitForSelector(page, '.mention');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ test.describe('Regression test #379', () => {
page,
}) => {
await focusEditor(page);
await page.keyboard.type('Luke');
await waitForSelector(page, '#typeahead-menu ul li');
await page.keyboard.type('@Luke');
await waitForSelector(
page,
'#typeahead-menu ul li:has-text("Luke Skywalker")',
);
await page.keyboard.press('Enter');
await assertHTML(
page,
Expand Down
15 changes: 13 additions & 2 deletions packages/lexical-playground/src/plugins/CommentPlugin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ function CommentInputBox({
correctedLeft = 10;
}
boxElem.style.left = `${correctedLeft}px`;
boxElem.style.top = `${bottom + 20 + (window.pageYOffset || document.documentElement.scrollTop)}px`;
boxElem.style.top = `${
bottom +
20 +
(window.pageYOffset || document.documentElement.scrollTop)
}px`;
const selectionRectsLength = selectionRects.length;
const {container} = selectionState;
const elements: Array<HTMLSpanElement> = selectionState.elements;
Expand All @@ -265,7 +269,14 @@ function CommentInputBox({
container.appendChild(elem);
}
const color = '255, 212, 0';
const style = `position:absolute;top:${selectionRect.top + (window.pageYOffset || document.documentElement.scrollTop)}px;left:${selectionRect.left}px;height:${selectionRect.height}px;width:${selectionRect.width}px;background-color:rgba(${color}, 0.3);pointer-events:none;z-index:5;`;
const style = `position:absolute;top:${
selectionRect.top +
(window.pageYOffset || document.documentElement.scrollTop)
}px;left:${selectionRect.left}px;height:${
selectionRect.height
}px;width:${
selectionRect.width
}px;background-color:rgba(${color}, 0.3);pointer-events:none;z-index:5;`;
elem.style.cssText = style;
}
for (let i = elementsLength - 1; i >= selectionRectsLength; i--) {
Expand Down
Loading

0 comments on commit 10b4e14

Please sign in to comment.