mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-04-29 15:04:05 +08:00
feat(editor): update 支持 selectedAfterUpdate 参数控制是否更新 nodes
Made-with: Cursor
This commit is contained in:
parent
59716e909b
commit
26efa75ff2
@ -509,7 +509,10 @@ class Editor extends BaseService {
|
|||||||
|
|
||||||
public async doUpdate(
|
public async doUpdate(
|
||||||
config: MNode,
|
config: MNode,
|
||||||
{ changeRecords = [] }: { changeRecords?: ChangeRecord[] } = {},
|
{
|
||||||
|
changeRecords = [],
|
||||||
|
selectedAfterUpdate = true,
|
||||||
|
}: { changeRecords?: ChangeRecord[]; selectedAfterUpdate?: boolean } = {},
|
||||||
): Promise<{ newNode: MNode; oldNode: MNode; changeRecords?: ChangeRecord[] }> {
|
): Promise<{ newNode: MNode; oldNode: MNode; changeRecords?: ChangeRecord[] }> {
|
||||||
const root = this.get('root');
|
const root = this.get('root');
|
||||||
if (!root) throw new Error('root为空');
|
if (!root) throw new Error('root为空');
|
||||||
@ -554,10 +557,12 @@ class Editor extends BaseService {
|
|||||||
parentNodeItems[index] = newConfig;
|
parentNodeItems[index] = newConfig;
|
||||||
|
|
||||||
// 将update后的配置更新到nodes中
|
// 将update后的配置更新到nodes中
|
||||||
const nodes = this.get('nodes');
|
if (selectedAfterUpdate) {
|
||||||
const targetIndex = nodes.findIndex((nodeItem: MNode) => `${nodeItem.id}` === `${newConfig.id}`);
|
const nodes = this.get('nodes');
|
||||||
nodes.splice(targetIndex, 1, newConfig);
|
const targetIndex = nodes.findIndex((nodeItem: MNode) => `${nodeItem.id}` === `${newConfig.id}`);
|
||||||
this.set('nodes', [...nodes]);
|
nodes.splice(targetIndex, 1, newConfig);
|
||||||
|
this.set('nodes', [...nodes]);
|
||||||
|
}
|
||||||
|
|
||||||
if (isPage(newConfig) || isPageFragment(newConfig)) {
|
if (isPage(newConfig) || isPageFragment(newConfig)) {
|
||||||
this.set('page', newConfig as MPage | MPageFragment);
|
this.set('page', newConfig as MPage | MPageFragment);
|
||||||
@ -580,7 +585,7 @@ class Editor extends BaseService {
|
|||||||
*/
|
*/
|
||||||
public async update(
|
public async update(
|
||||||
config: MNode | MNode[],
|
config: MNode | MNode[],
|
||||||
data: { changeRecords?: ChangeRecord[] } = {},
|
data: { changeRecords?: ChangeRecord[]; selectedAfterUpdate?: boolean } = {},
|
||||||
): Promise<MNode | MNode[]> {
|
): Promise<MNode | MNode[]> {
|
||||||
this.captureSelectionBeforeOp();
|
this.captureSelectionBeforeOp();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user