chore: allow cursor in none-contenteditable blocks (#11366)
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
stdContext,
|
stdContext,
|
||||||
TextSelection,
|
TextSelection,
|
||||||
} from '@blocksuite/std';
|
} from '@blocksuite/std';
|
||||||
|
import { RANGE_SYNC_EXCLUDE_ATTR } from '@blocksuite/std/inline';
|
||||||
import type { BlockModel, Store } from '@blocksuite/store';
|
import type { BlockModel, Store } from '@blocksuite/store';
|
||||||
import { Text } from '@blocksuite/store';
|
import { Text } from '@blocksuite/store';
|
||||||
import { consume } from '@lit/context';
|
import { consume } from '@lit/context';
|
||||||
@@ -121,6 +122,8 @@ export class BlockCaptionEditor<
|
|||||||
override connectedCallback(): void {
|
override connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
|
||||||
|
this.setAttribute(RANGE_SYNC_EXCLUDE_ATTR, 'true');
|
||||||
|
|
||||||
this.caption = this.model.props.caption;
|
this.caption = this.model.props.caption;
|
||||||
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
SearchIcon,
|
SearchIcon,
|
||||||
} from '@blocksuite/icons/lit';
|
} from '@blocksuite/icons/lit';
|
||||||
import { ShadowlessElement } from '@blocksuite/std';
|
import { ShadowlessElement } from '@blocksuite/std';
|
||||||
|
import { RANGE_SYNC_EXCLUDE_ATTR } from '@blocksuite/std/inline';
|
||||||
import {
|
import {
|
||||||
autoPlacement,
|
autoPlacement,
|
||||||
autoUpdate,
|
autoUpdate,
|
||||||
@@ -383,6 +384,7 @@ export const getDefaultModalRoot = (ele: HTMLElement) => {
|
|||||||
};
|
};
|
||||||
export const createModal = (container: HTMLElement = document.body) => {
|
export const createModal = (container: HTMLElement = document.body) => {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
|
div.setAttribute(RANGE_SYNC_EXCLUDE_ATTR, 'true');
|
||||||
div.style.pointerEvents = 'auto';
|
div.style.pointerEvents = 'auto';
|
||||||
div.style.position = 'absolute';
|
div.style.position = 'absolute';
|
||||||
div.style.left = '0';
|
div.style.left = '0';
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import type { BaseSelection, BlockModel } from '@blocksuite/store';
|
|||||||
import throttle from 'lodash-es/throttle';
|
import throttle from 'lodash-es/throttle';
|
||||||
|
|
||||||
import { TextSelection } from '../../selection/index.js';
|
import { TextSelection } from '../../selection/index.js';
|
||||||
import type { BlockComponent } from '../../view/element/block-component.js';
|
|
||||||
import { BLOCK_ID_ATTR } from '../../view/index.js';
|
|
||||||
import { isActiveInEditor } from './active.js';
|
import { isActiveInEditor } from './active.js';
|
||||||
import { RANGE_SYNC_EXCLUDE_ATTR } from './consts.js';
|
import { RANGE_SYNC_EXCLUDE_ATTR } from './consts.js';
|
||||||
import type { RangeManager } from './range-manager.js';
|
import type { RangeManager } from './range-manager.js';
|
||||||
@@ -211,8 +209,13 @@ export class RangeBinding {
|
|||||||
|
|
||||||
const el = getElement(range.commonAncestorContainer);
|
const el = getElement(range.commonAncestorContainer);
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
const block = el.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
|
|
||||||
if (block?.getAttribute(RANGE_SYNC_EXCLUDE_ATTR) === 'true') return;
|
const closestExclude = el.closest(`[${RANGE_SYNC_EXCLUDE_ATTR}]`);
|
||||||
|
if (closestExclude?.getAttribute(RANGE_SYNC_EXCLUDE_ATTR) === 'true')
|
||||||
|
return;
|
||||||
|
|
||||||
|
const closestEditable = el.closest('[contenteditable]');
|
||||||
|
if (closestEditable?.getAttribute('contenteditable') === 'false') return;
|
||||||
|
|
||||||
const startElement = getElement(range.startContainer);
|
const startElement = getElement(range.startContainer);
|
||||||
const endElement = getElement(range.endContainer);
|
const endElement = getElement(range.endContainer);
|
||||||
|
|||||||
Reference in New Issue
Block a user