Skip to content

Commit

Permalink
fix: update slash menu append behavior (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs authored Jan 25, 2023
1 parent 6f577c9 commit 95111e2
Showing 1 changed file with 24 additions and 2 deletions.
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

2 comments on commit 95111e2

@vercel
Copy link

@vercel vercel bot commented on 95111e2 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blocksuite-react – ./packages/react/examples/next

blocksuite-react-toeverything.vercel.app
blocksuite-react.vercel.app
blocksuite-react-git-master-toeverything.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 95111e2 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blocksuite – ./packages/playground

blocksuite-five.vercel.app
blocksuite-toeverything.vercel.app
blocksuite-git-master-toeverything.vercel.app

Please sign in to comment.