mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-08 01:39:22 +08:00
fix(editor): should show toolbar after mouse is released (#10698)
This commit is contained in:
+15
-17
@@ -205,23 +205,21 @@ export class AffinePageDraggingAreaWidget extends WidgetComponent<
|
|||||||
const state = ctx.get('pointerState');
|
const state = ctx.get('pointerState');
|
||||||
const { button } = state.raw;
|
const { button } = state.raw;
|
||||||
if (button !== 0) return;
|
if (button !== 0) return;
|
||||||
if (isDragArea(state)) {
|
if (!isDragArea(state)) return;
|
||||||
if (!this._viewport) {
|
if (!this._viewport) return;
|
||||||
return;
|
|
||||||
}
|
this._dragging = true;
|
||||||
this._dragging = true;
|
const { scrollLeft, scrollTop } = this._viewport;
|
||||||
const { scrollLeft, scrollTop } = this._viewport;
|
this._initialScrollOffset = {
|
||||||
this._initialScrollOffset = {
|
left: scrollLeft,
|
||||||
left: scrollLeft,
|
top: scrollTop,
|
||||||
top: scrollTop,
|
};
|
||||||
};
|
this._initialContainerOffset = {
|
||||||
this._initialContainerOffset = {
|
x: state.containerOffset.x,
|
||||||
x: state.containerOffset.x,
|
y: state.containerOffset.y,
|
||||||
y: state.containerOffset.y,
|
};
|
||||||
};
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
{ global: true }
|
{ global: true }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -274,8 +274,10 @@ export class AffineToolbarWidget extends WidgetComponent {
|
|||||||
const dragStart = () => flags.toggle(Flag.Hiding, true);
|
const dragStart = () => flags.toggle(Flag.Hiding, true);
|
||||||
const dragEnd = () => flags.toggle(Flag.Hiding, false);
|
const dragEnd = () => flags.toggle(Flag.Hiding, false);
|
||||||
const eventOptions = { passive: false };
|
const eventOptions = { passive: false };
|
||||||
this.handleEvent('dragStart', dragStart);
|
this.handleEvent('dragStart', () => {
|
||||||
this.handleEvent('dragEnd', dragEnd);
|
dragStart();
|
||||||
|
host.addEventListener('pointerup', dragEnd, { once: true });
|
||||||
|
});
|
||||||
this.handleEvent('nativeDrop', dragEnd);
|
this.handleEvent('nativeDrop', dragEnd);
|
||||||
disposables.addFromEvent(host, 'dragenter', dragStart, eventOptions);
|
disposables.addFromEvent(host, 'dragenter', dragStart, eventOptions);
|
||||||
disposables.addFromEvent(
|
disposables.addFromEvent(
|
||||||
@@ -288,9 +290,9 @@ export class AffineToolbarWidget extends WidgetComponent {
|
|||||||
const rect = host.getBoundingClientRect();
|
const rect = host.getBoundingClientRect();
|
||||||
if (
|
if (
|
||||||
x >= rect.left &&
|
x >= rect.left &&
|
||||||
|
x <= rect.right &&
|
||||||
y >= rect.top &&
|
y >= rect.top &&
|
||||||
x <= rect.bottom &&
|
y <= rect.bottom
|
||||||
y <= rect.right
|
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
dragEnd();
|
dragEnd();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { test } from '@affine-test/kit/playwright';
|
import { test } from '@affine-test/kit/playwright';
|
||||||
import { locateFormatBar } from '@affine-test/kit/utils/editor';
|
import { locateToolbar } from '@affine-test/kit/utils/editor';
|
||||||
import {
|
import {
|
||||||
pressEnter,
|
pressEnter,
|
||||||
pressShiftTab,
|
pressShiftTab,
|
||||||
@@ -33,16 +33,16 @@ test('heading icon should be updated after change heading level', async ({
|
|||||||
const paragraph = page.locator('affine-note affine-paragraph').nth(0);
|
const paragraph = page.locator('affine-note affine-paragraph').nth(0);
|
||||||
|
|
||||||
await selectAllByKeyboard(page);
|
await selectAllByKeyboard(page);
|
||||||
const formatBar = locateFormatBar(page);
|
const toolbar = locateToolbar(page);
|
||||||
await formatBar.getByLabel('Conversions').click();
|
await toolbar.getByLabel('Conversions').click();
|
||||||
await formatBar.getByLabel('Heading 1').click();
|
await toolbar.getByLabel('Heading 1').click();
|
||||||
|
|
||||||
await paragraph.hover();
|
await paragraph.hover();
|
||||||
await expect(page.getByTestId('heading-icon-1')).toBeVisible();
|
await expect(page.getByTestId('heading-icon-1')).toBeVisible();
|
||||||
|
|
||||||
await selectAllByKeyboard(page);
|
await selectAllByKeyboard(page);
|
||||||
await formatBar.getByLabel('Conversions').click();
|
await toolbar.getByLabel('Conversions').click();
|
||||||
await formatBar.getByLabel('Heading 2').click();
|
await toolbar.getByLabel('Heading 2').click();
|
||||||
|
|
||||||
await paragraph.hover();
|
await paragraph.hover();
|
||||||
await expect(page.getByTestId('heading-icon-1')).toBeHidden();
|
await expect(page.getByTestId('heading-icon-1')).toBeHidden();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { test } from '@affine-test/kit/playwright';
|
import { test } from '@affine-test/kit/playwright';
|
||||||
import { locateFormatBar } from '@affine-test/kit/utils/editor';
|
import { locateToolbar } from '@affine-test/kit/utils/editor';
|
||||||
|
import { selectAllByKeyboard } from '@affine-test/kit/utils/keyboard';
|
||||||
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
||||||
import {
|
import {
|
||||||
clickNewPageButton,
|
clickNewPageButton,
|
||||||
@@ -34,6 +35,33 @@ test.beforeEach(async ({ page }) => {
|
|||||||
await waitForEmptyEditor(page);
|
await waitForEmptyEditor(page);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should toggle toolbar when dragging page area', async ({ page }) => {
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await page.keyboard.type('Roman');
|
||||||
|
await selectAllByKeyboard(page);
|
||||||
|
|
||||||
|
const toolbar = locateToolbar(page);
|
||||||
|
|
||||||
|
await expect(toolbar).toBeVisible();
|
||||||
|
await expect(toolbar).toBeInViewport();
|
||||||
|
|
||||||
|
const paragraph = page.locator('affine-note affine-paragraph').nth(0);
|
||||||
|
const bounds = await paragraph.boundingBox();
|
||||||
|
|
||||||
|
expect(bounds).toBeTruthy();
|
||||||
|
const { x, y, width } = bounds!;
|
||||||
|
|
||||||
|
await page.mouse.move(x + width + 10, y - 10, { steps: 2 });
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(x + width - 10, y + 10, { steps: 2 });
|
||||||
|
|
||||||
|
await expect(toolbar).toBeHidden();
|
||||||
|
|
||||||
|
await page.mouse.up();
|
||||||
|
|
||||||
|
await expect(toolbar).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
test.describe('Formatting', () => {
|
test.describe('Formatting', () => {
|
||||||
test('should change text color', async ({ page }) => {
|
test('should change text color', async ({ page }) => {
|
||||||
await page.keyboard.press('Enter');
|
await page.keyboard.press('Enter');
|
||||||
@@ -43,12 +71,12 @@ test.describe('Formatting', () => {
|
|||||||
await page.keyboard.press('Shift+ArrowLeft');
|
await page.keyboard.press('Shift+ArrowLeft');
|
||||||
await page.keyboard.press('Shift+ArrowLeft');
|
await page.keyboard.press('Shift+ArrowLeft');
|
||||||
|
|
||||||
const formatBar = locateFormatBar(page);
|
const toolbar = locateToolbar(page);
|
||||||
const highlightButton = formatBar.locator('affine-highlight-duotone-icon');
|
const highlightButton = toolbar.locator('affine-highlight-duotone-icon');
|
||||||
|
|
||||||
await highlightButton.click();
|
await highlightButton.click();
|
||||||
|
|
||||||
const fgGreenButton = formatBar.locator('[data-testid="foreground-green"]');
|
const fgGreenButton = toolbar.locator('[data-testid="foreground-green"]');
|
||||||
await fgGreenButton.click();
|
await fgGreenButton.click();
|
||||||
const fgColor = await fgGreenButton
|
const fgColor = await fgGreenButton
|
||||||
.locator('affine-text-duotone-icon')
|
.locator('affine-text-duotone-icon')
|
||||||
@@ -73,12 +101,12 @@ test.describe('Formatting', () => {
|
|||||||
await page.keyboard.press('Shift+ArrowLeft');
|
await page.keyboard.press('Shift+ArrowLeft');
|
||||||
await page.keyboard.press('Shift+ArrowLeft');
|
await page.keyboard.press('Shift+ArrowLeft');
|
||||||
|
|
||||||
const formatBar = locateFormatBar(page);
|
const toolbar = locateToolbar(page);
|
||||||
const highlightButton = formatBar.locator('affine-highlight-duotone-icon');
|
const highlightButton = toolbar.locator('affine-highlight-duotone-icon');
|
||||||
|
|
||||||
await highlightButton.click();
|
await highlightButton.click();
|
||||||
|
|
||||||
const fgGreenButton = formatBar.locator('[data-testid="foreground-green"]');
|
const fgGreenButton = toolbar.locator('[data-testid="foreground-green"]');
|
||||||
await fgGreenButton.click();
|
await fgGreenButton.click();
|
||||||
|
|
||||||
await page.waitForTimeout(200);
|
await page.waitForTimeout(200);
|
||||||
@@ -104,9 +132,7 @@ test.describe('Formatting', () => {
|
|||||||
await highlightButton.click();
|
await highlightButton.click();
|
||||||
|
|
||||||
const yellow = 'var(--affine-text-highlight-yellow)';
|
const yellow = 'var(--affine-text-highlight-yellow)';
|
||||||
const bgYellowButton = formatBar.locator(
|
const bgYellowButton = toolbar.locator('[data-testid="background-yellow"]');
|
||||||
'[data-testid="background-yellow"]'
|
|
||||||
);
|
|
||||||
await bgYellowButton.click();
|
await bgYellowButton.click();
|
||||||
|
|
||||||
const textSpan2 = paragraph
|
const textSpan2 = paragraph
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export async function focusDocTitle(page: Page, editorIndex = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================== Page ==================
|
// ================== Page ==================
|
||||||
export function locateFormatBar(page: Page, editorIndex = 0) {
|
export function locateToolbar(page: Page, editorIndex = 0) {
|
||||||
return locateEditorContainer(page, editorIndex).locator(
|
return locateEditorContainer(page, editorIndex).locator(
|
||||||
'affine-toolbar-widget editor-toolbar'
|
'affine-toolbar-widget editor-toolbar'
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user