Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Oct 22, 2024
1 parent 0d5f2b8 commit b5595b7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ export class DragEventWatcher {

if (blocksExcludingChildren.length === 0) return false;

console.log(blocks);
console.log(blocksExcludingChildren);
this._startDragging(blocksExcludingChildren, state);
this.widget.hide();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
} from '../config.js';

export class HandleEventWatcher {
private _onDragHandlePointerDown = (event: PointerEvent) => {
event.stopPropagation();
private _onDragHandlePointerDown = () => {
if (!this.widget.isHoverDragHandleVisible || !this.widget.anchorBlockId)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,50 @@ export class PointerEventWatcher {
);
};

/**
* When click on drag handle
* Should select the block and show slash menu if current block is not selected
* Should clear selection if current block is the first selected block
*/
private _clickHandler: UIEventHandler = ctx => {
if (!this.widget.isHoverDragHandleVisible) return;

const state = ctx.get('pointerState');
const { target } = state.raw;
const element = captureEventTarget(target);
const insideDragHandle = !!element?.closest(AFFINE_DRAG_HANDLE_WIDGET);
if (!insideDragHandle) return;

const anchorBlockId = this.widget.anchorBlockId.peek();

if (!anchorBlockId) return;

const { selection } = this.widget.std;
const selectedBlocks = this.widget.selectionHelper.selectedBlocks;

// Should clear selection if current block is the first selected block
if (
selectedBlocks.length > 0 &&
!includeTextSelection(selectedBlocks) &&
selectedBlocks[0].blockId === anchorBlockId
) {
selection.clear(['block']);
this.widget.dragHoverRect = null;
this.showDragHandleOnHoverBlock();
return;
}

// Should select the block if current block is not selected
const block = this.widget.anchorBlockComponent.peek();
if (!block) return;

if (selectedBlocks.length > 1) {
this.showDragHandleOnHoverBlock();
}

this.widget.selectionHelper.setSelectedBlocks([block]);
};

private _containerStyle = computed(() => {
const draggingAreaRect = this.widget.draggingAreaRect.value;
if (!draggingAreaRect) return null;
Expand Down Expand Up @@ -104,37 +148,6 @@ export class PointerEventWatcher {

private _lastShowedBlock: { id: string; el: BlockComponent } | null = null;

private _onClick = () => {
const anchorBlockId = this.widget.anchorBlockId.peek();

if (!anchorBlockId) return;

const { selection } = this.widget.std;
const selectedBlocks = this.widget.selectionHelper.selectedBlocks;

// Should clear selection if current block is the first selected block
if (
selectedBlocks.length > 0 &&
!includeTextSelection(selectedBlocks) &&
selectedBlocks[0].blockId === anchorBlockId
) {
selection.clear(['block']);
this.widget.dragHoverRect = null;
this.showDragHandleOnHoverBlock();
return;
}

// Should select the block if current block is not selected
const block = this.widget.anchorBlockComponent.peek();
if (!block) return;

if (selectedBlocks.length > 1) {
this.showDragHandleOnHoverBlock();
}

this.widget.selectionHelper.setSelectedBlocks([block]);
};

/**
* When pointer move on block, should show drag handle
* And update hover block id and path
Expand Down Expand Up @@ -317,19 +330,7 @@ export class PointerEventWatcher {
}

watch() {
// this.widget.disposables.addFromEvent(this.widget, 'pointerdown', e => {
// e.stopPropagation();
// return true;
// });

requestAnimationFrame(() => {
this.widget.disposables.addFromEvent(
this.widget.dragHandleContainer,
'click',
this._onClick
);
});
// this.widget.handleEvent('click', this._clickHandler);
this.widget.handleEvent('click', this._clickHandler);
this.widget.handleEvent('pointerMove', this._throttledPointerMoveHandler);
this.widget.handleEvent('pointerOut', this._pointerOutHandler);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { PlaywrightWorkerOptions } from '@playwright/test';

import { defineConfig } from '@playwright/test';
import process from 'node:process';

export default defineConfig({
testDir: '.',
timeout: 40000,
timeout: process.env.CI ? 40000 : 999999,
fullyParallel: true,
snapshotDir: 'snapshots',
snapshotPathTemplate: 'snapshots/{testFilePath}/{arg}{ext}',
Expand Down

0 comments on commit b5595b7

Please sign in to comment.