Skip to content

Commit

Permalink
fix(text): set user-select to text paragraph instead of event.prevent…
Browse files Browse the repository at this point in the history
…Default #WIK-15691 (#902)
  • Loading branch information
huanhuanwa authored Jun 4, 2024
1 parent c6e292d commit 22d2431
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .changeset/slow-flies-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@plait/common': patch
'@plait/core': patch
'@plait/mind': patch
'@plait/text': patch
---

set user-select to text paragraph instead of event.preventDefault
4 changes: 0 additions & 4 deletions packages/common/src/plugins/with-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export const withResize = <T extends PlaitElementOrArray = PlaitElementOrArray,
options: resizeHitTestRef.options
};
preventTouchMove(board, event, true);
// prevent text from being selected when user pressed shift and pointer down
event.preventDefault();
return;
}
pointerDown(event);
Expand All @@ -71,8 +69,6 @@ export const withResize = <T extends PlaitElementOrArray = PlaitElementOrArray,
return;
}
if (startPoint && resizeHitTestRef && !isResizing(board)) {
// prevent text from being selected
event.preventDefault();
const endPoint = [event.x, event.y];
const distance = distanceBetweenPointAndPoint(startPoint[0], startPoint[1], endPoint[0], endPoint[1]);
if (distance > PRESS_AND_MOVE_BUFFER) {
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/plugins/with-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function withSelection(board: PlaitBoard) {
let selectionRectangleG: SVGGElement | null;
let previousSelectedElements: PlaitElement[];
let isShift = false;
let isTextSelection = false;

board.pointerDown = (event: PointerEvent) => {
if (!isShift && event.shiftKey) {
Expand All @@ -57,12 +56,6 @@ export function withSelection(board: PlaitBoard) {
isShift = false;
}
const isHitText = !!(event.target instanceof Element && event.target.closest('.plait-richtext-container'));
isTextSelection = isHitText && PlaitBoard.hasBeenTextEditing(board);

// prevent text from being selected
if (event.shiftKey && !isTextSelection) {
event.preventDefault();
}

const point = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
const isHitTarget = isHitElement(board, point);
Expand All @@ -76,10 +69,6 @@ export function withSelection(board: PlaitBoard) {
};

board.pointerMove = (event: PointerEvent) => {
if (!isTextSelection) {
// prevent text from being selected
event.preventDefault();
}
if (PlaitBoard.isPointer(board, PlaitPointerType.selection) && start) {
const movedTarget = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
const rectangle = RectangleClient.getRectangleByPoints([start, movedTarget]);
Expand Down Expand Up @@ -138,7 +127,6 @@ export function withSelection(board: PlaitBoard) {
}
start = null;
end = null;
isTextSelection = false;
preventTouchMove(board, event, false);
globalPointerUp(event);
};
Expand Down
2 changes: 0 additions & 2 deletions packages/mind/src/plugins/with-abstract-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export const withAbstract: PlaitPlugin = (board: PlaitBoard) => {
touchedAbstract = handleTouchedAbstract(board, touchedAbstract, endPoint);

if (abstractHandlePosition && activeAbstractElement) {
// prevent text from being selected
event.preventDefault();
const nodeLayout = MindQueries.getCorrectLayoutByElement(board, activeAbstractElement as MindElement) as MindLayoutType;
const isHorizontal = isHorizontalLayout(nodeLayout);
const parentElement = MindElement.getParent(activeAbstractElement);
Expand Down
3 changes: 0 additions & 3 deletions packages/mind/src/plugins/with-node-dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ export const withNodeDnd = (board: PlaitBoard) => {
};

board.pointerMove = (event: PointerEvent) => {
// const xx = activeElements.
if (!board.options.readonly && activeElements.length && startPoint) {
// prevent text from being selected
event.preventDefault();
const endPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
const distance = distanceBetweenPointAndPoint(startPoint[0], startPoint[1], endPoint[0], endPoint[1]);
if (distance < DRAG_MOVE_BUFFER) {
Expand Down
5 changes: 4 additions & 1 deletion packages/text/src/plugins/paragraph/paragraph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { ParagraphElement } from '../../custom-types';
selector: 'div[plaitTextParagraphElement]',
template: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true
standalone: true,
host: {
class: 'plait-text-paragraph'
}
})
export class ParagraphElementComponent extends BaseElementComponent<ParagraphElement> implements OnInit {
ngOnInit(): void {
Expand Down
6 changes: 6 additions & 0 deletions packages/text/src/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
outline: none;
padding: 0;
cursor: default;
.plait-text-paragraph {
user-select: none;
}
&.editing {
cursor: text;
.plait-text-paragraph {
user-select: text;
}
}
}

Expand Down

0 comments on commit 22d2431

Please sign in to comment.