From 969ac30874a7a4d1ceb6f0f048dd2bb4c1ae60c0 Mon Sep 17 00:00:00 2001 From: L-Sun Date: Thu, 16 Jan 2025 08:32:15 +0000 Subject: [PATCH] fix(editor): reactive heading icon (#9729) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close [BS-2407](https://linear.app/affine-design/issue/BS-2407/[bug]-edgeless-里选中-title-后更改,hint-没有改变) --- .../block-paragraph/src/heading-icon.ts | 12 ++++-- .../block-paragraph/src/paragraph-block.ts | 9 ++-- .../e2e/blocksuite/paragraph.spec.ts | 42 +++++++++++++++++++ .../e2e/blocksuite/toolbar.spec.ts | 5 ++- tests/kit/src/utils/editor.ts | 8 ++++ 5 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 tests/affine-local/e2e/blocksuite/paragraph.spec.ts diff --git a/blocksuite/affine/block-paragraph/src/heading-icon.ts b/blocksuite/affine/block-paragraph/src/heading-icon.ts index bc805bf16b..3edc80369c 100644 --- a/blocksuite/affine/block-paragraph/src/heading-icon.ts +++ b/blocksuite/affine/block-paragraph/src/heading-icon.ts @@ -8,7 +8,7 @@ import { } from '@blocksuite/affine-components/icons'; import type { ParagraphBlockModel } from '@blocksuite/affine-model'; import { ShadowlessElement } from '@blocksuite/block-std'; -import { WithDisposable } from '@blocksuite/global/utils'; +import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils'; import { cssVarV2 } from '@toeverything/theme/v2'; import { css, html, nothing, unsafeCSS } from 'lit'; import { property } from 'lit/decorators.js'; @@ -32,7 +32,9 @@ function HeadingIcon(i: number) { } } -export class ParagraphHeadingIcon extends WithDisposable(ShadowlessElement) { +export class ParagraphHeadingIcon extends SignalWatcher( + WithDisposable(ShadowlessElement) +) { static override styles = css` affine-paragraph-heading-icon .heading-icon { display: flex; @@ -65,12 +67,14 @@ export class ParagraphHeadingIcon extends WithDisposable(ShadowlessElement) { `; override render() { - const type = this.model.type; + const type = this.model.type$.value; if (!type.startsWith('h')) return nothing; const i = parseInt(type.slice(1)); - return html`
${HeadingIcon(i)}
`; + return html`
+ ${HeadingIcon(i)} +
`; } @property({ attribute: false }) diff --git a/blocksuite/affine/block-paragraph/src/paragraph-block.ts b/blocksuite/affine/block-paragraph/src/paragraph-block.ts index 0623354e77..8f32267ea4 100644 --- a/blocksuite/affine/block-paragraph/src/paragraph-block.ts +++ b/blocksuite/affine/block-paragraph/src/paragraph-block.ts @@ -157,7 +157,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent< this._readonlyCollapsed = collapsed; // reset text selection when selected block is collapsed - if (this.model.type.startsWith('h') && collapsed) { + if (this.model.type$.value.startsWith('h') && collapsed) { const collapsedSiblings = this.collapsedSiblings; const textSelection = this.host.selection.find(TextSelection); @@ -177,7 +177,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent< // # 456 // // we need to update collapsed state of 123 when 456 converted to text - let beforeType = this.model.type; + let beforeType = this.model.type$.peek(); this.disposables.add( effect(() => { const type = this.model.type$.value; @@ -211,7 +211,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent< const collapsedSiblings = this.collapsedSiblings; let style = html``; - if (this.model.type.startsWith('h') && collapsed) { + if (this.model.type$.value.startsWith('h') && collapsed) { style = html`