mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 03:48:39 +00:00
feat: repair paste cursor
This commit is contained in:
@@ -905,6 +905,19 @@ class SlateUtils {
|
||||
);
|
||||
}
|
||||
|
||||
public insertNodes(
|
||||
nodes: SlateNode | Array<SlateNode>,
|
||||
options?: Parameters<typeof Transforms.insertNodes>[2]
|
||||
) {
|
||||
Transforms.insertNodes(this.editor, nodes, {
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
public getNodeByPath(path: Path) {
|
||||
Editor.node(this.editor, path);
|
||||
}
|
||||
|
||||
public getStartSelection() {
|
||||
return {
|
||||
anchor: this.getStart(),
|
||||
|
||||
@@ -3,7 +3,13 @@ import type {
|
||||
SlateUtils,
|
||||
TextAlignOptions,
|
||||
} from '@toeverything/components/common';
|
||||
import { Point, Selection as SlateSelection } from 'slate';
|
||||
import {
|
||||
BaseRange,
|
||||
Node,
|
||||
Path,
|
||||
Point,
|
||||
Selection as SlateSelection,
|
||||
} from 'slate';
|
||||
import { Editor } from '../editor';
|
||||
|
||||
type TextUtilsFunctions =
|
||||
@@ -28,7 +34,10 @@ type TextUtilsFunctions =
|
||||
| 'removeSelection'
|
||||
| 'insertReference'
|
||||
| 'isCollapsed'
|
||||
| 'blur';
|
||||
| 'blur'
|
||||
| 'setSelection'
|
||||
| 'insertNodes'
|
||||
| 'getNodeByPath';
|
||||
|
||||
type ExtendedTextUtils = SlateUtils & {
|
||||
setLinkModalVisible: (visible: boolean) => void;
|
||||
@@ -193,6 +202,59 @@ export class BlockHelper {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set selection of a text input
|
||||
* @param {string} blockId
|
||||
* @param {BaseRange} selection
|
||||
* @return {*}
|
||||
* @memberof BlockHelper
|
||||
*/
|
||||
public setSelection(blockId: string, selection: BaseRange) {
|
||||
const text_utils = this._blockTextUtilsMap[blockId];
|
||||
if (text_utils) {
|
||||
return text_utils.setSelection(selection);
|
||||
}
|
||||
console.warn('Could find the block text utils');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* insert nodes in text
|
||||
* @param {string} blockId
|
||||
* @param {Array<Node>} nodes
|
||||
* @param {Parameters<TextUtils['insertNodes']>[1]} options
|
||||
* @return {*}
|
||||
* @memberof BlockHelper
|
||||
*/
|
||||
public insertNodes(
|
||||
blockId: string,
|
||||
nodes: Array<Node>,
|
||||
options?: Parameters<TextUtils['insertNodes']>[1]
|
||||
) {
|
||||
const text_utils = this._blockTextUtilsMap[blockId];
|
||||
if (text_utils) {
|
||||
return text_utils.insertNodes(nodes, options);
|
||||
}
|
||||
console.warn('Could find the block text utils');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get text(slate node) by path
|
||||
* @param {string} blockId
|
||||
* @param {Path} path
|
||||
* @return {*}
|
||||
* @memberof BlockHelper
|
||||
*/
|
||||
public getNodeByPath(blockId: string, path: Path) {
|
||||
const text_utils = this._blockTextUtilsMap[blockId];
|
||||
if (text_utils) {
|
||||
return text_utils.getNodeByPath(path);
|
||||
}
|
||||
console.warn('Could find the block text utils');
|
||||
}
|
||||
|
||||
public transformPoint(
|
||||
blockId: string,
|
||||
...restArgs: Parameters<TextUtils['transformPoint']>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HooksRunner } from '../types';
|
||||
/* eslint-disable max-lines */
|
||||
import {
|
||||
OFFICE_CLIPBOARD_MIMETYPE,
|
||||
InnerClipInfo,
|
||||
@@ -187,10 +187,15 @@ export class Paste {
|
||||
const pureText = !shouldSplitBlock
|
||||
? blocks[0].properties.text.value
|
||||
: [{ text: '' }];
|
||||
this._editor.blockHelper.setBlockBlur(
|
||||
currentSelectInfo.blocks[0].blockId
|
||||
this._editor.blockHelper.insertNodes(
|
||||
selectedBlock.id,
|
||||
pureText,
|
||||
{ select: true }
|
||||
);
|
||||
return;
|
||||
//TODO repair the following logics
|
||||
|
||||
/**
|
||||
const { startInfo, endInfo } = currentSelectInfo.blocks[0];
|
||||
|
||||
// 选中的当前的可编辑block的文字信息
|
||||
@@ -414,13 +419,13 @@ export class Paste {
|
||||
},
|
||||
});
|
||||
|
||||
const pastedTextLength = pureText.reduce(
|
||||
(sumLength: number, textItem: TextValueItem) => {
|
||||
sumLength += textItem.text.length;
|
||||
return sumLength;
|
||||
},
|
||||
0
|
||||
);
|
||||
// const pastedTextLength = pureText.reduce(
|
||||
// (sumLength: number, textItem: TextValueItem) => {
|
||||
// sumLength += textItem.text.length;
|
||||
// return sumLength;
|
||||
// },
|
||||
// 0
|
||||
// );
|
||||
|
||||
// this._editor.selectionManager.moveCursor(
|
||||
// window.getSelection().getRangeAt(0),
|
||||
@@ -429,6 +434,7 @@ export class Paste {
|
||||
// );
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
const pasteBlocks = await this._createBlocks(blocks);
|
||||
pasteBlocks.forEach(block => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Editor} from "../editor";
|
||||
import { Editor } from '../editor';
|
||||
|
||||
export const shouldHandlerContinue = (event: Event, editor: Editor) => {
|
||||
const filterNodes = ['INPUT', 'SELECT', 'TEXTAREA'];
|
||||
|
||||
@@ -322,16 +322,16 @@ export class SelectionManager implements VirgoSelection {
|
||||
if (selectionRect.isIntersect(domToRect(block.dom))) {
|
||||
const childrenBlocks = await block.children();
|
||||
// should check directly in structured block
|
||||
const structuredChildrenBlocks: Array<AsyncBlock> = childrenBlocks.filter(
|
||||
childBlock => {
|
||||
const structuredChildrenBlocks: Array<AsyncBlock> =
|
||||
childrenBlocks.filter(childBlock => {
|
||||
return this._editor.getView(childBlock.type).layoutOnly;
|
||||
}
|
||||
);
|
||||
});
|
||||
for await (const childBlock of structuredChildrenBlocks) {
|
||||
const childSelectedNodes = await this.calcRenderBlockIntersect(
|
||||
selectionRect,
|
||||
childBlock
|
||||
);
|
||||
const childSelectedNodes =
|
||||
await this.calcRenderBlockIntersect(
|
||||
selectionRect,
|
||||
childBlock
|
||||
);
|
||||
selectedNodes.push(...childSelectedNodes);
|
||||
}
|
||||
const selectableChildren = childrenBlocks.filter(childBlock => {
|
||||
@@ -348,10 +348,11 @@ export class SelectionManager implements VirgoSelection {
|
||||
}
|
||||
// if just only has one selected maybe select the children
|
||||
if (selectedNodes.length === 1) {
|
||||
const childrenSelectedNodes: Array<AsyncBlock> = await this.calcRenderBlockIntersect(
|
||||
selectionRect,
|
||||
selectedNodes[0]
|
||||
);
|
||||
const childrenSelectedNodes: Array<AsyncBlock> =
|
||||
await this.calcRenderBlockIntersect(
|
||||
selectionRect,
|
||||
selectedNodes[0]
|
||||
);
|
||||
if (childrenSelectedNodes.length)
|
||||
return childrenSelectedNodes;
|
||||
}
|
||||
@@ -584,7 +585,8 @@ export class SelectionManager implements VirgoSelection {
|
||||
} else {
|
||||
const new_node = await this._editor.getBlockById(newNodeId);
|
||||
if (new_node) {
|
||||
const new_node_children_ids = await new_node.childrenIds;
|
||||
const new_node_children_ids =
|
||||
await new_node.childrenIds;
|
||||
let select_ids_new = this._selectedNodesIds;
|
||||
if (
|
||||
new_node_children_ids &&
|
||||
|
||||
Reference in New Issue
Block a user