Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update append behavior #848

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions packages/blocks/src/components/slash-menu/slash-menu-node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { paragraphConfig } from '@blocksuite/global/config';
import type { BaseBlockModel } from '@blocksuite/store';
import { BaseBlockModel, PrelimText } from '@blocksuite/store';
import { css, html, LitElement } from 'lit';
import { customElement, property, query, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
Expand Down Expand Up @@ -178,15 +178,37 @@ export class SlashMenu extends LitElement {
this.abortController.abort(this._searchString);
const { flavour, type } = this._filterItems[index];

// WARNING: This flag is a simple prototype implementation, just for proof of product.
if (this.model.page.awarenessStore.getFlag('enable_append_flavor_slash')) {
// Add new block
const page = this.model.page;
const parent = page.getParent(this.model);
if (!parent) {
throw new Error('Failed add block!');
}
// TODO merge with `handleBlockSplit` and it will the issue of children not extending.
const richText = getRichTextByModel(this.model);
if (!richText) {
throw new Error("Can't get richText instance!");
}
const quill = richText.quill;
const selection = quill.getSelection();
const text = this.model.text;
if (!text || text instanceof PrelimText) {
throw new Error("Can't get text or text is PrelimText!");
}
const [left, right] = text.split(selection.index, 0);
page.captureSync();
page.markTextSplit(text, left, right);
page.updateBlock(this.model, { text: left });

const index = parent.children.indexOf(this.model);
const id = page.addBlockByFlavour(flavour, { type }, parent, index + 1);
const id = page.addBlockByFlavour(
flavour,
{ type, text: right },
parent,
index + 1
);
asyncFocusRichText(page, id);
return;
}
Expand Down