Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

fix: rerender makes select behavior wrong#179

Open
kamesan012 wants to merge 1 commit into
marktext:masterfrom
kamesan012:master
Open

fix: rerender makes select behavior wrong#179
kamesan012 wants to merge 1 commit into
marktext:masterfrom
kamesan012:master

Conversation

@kamesan012
Copy link
Copy Markdown

No description provided.

@kamesan012
Copy link
Copy Markdown
Author

@Jocs Hello, please review this code. I'm not sure this will effect other parts.

@Jocs
Copy link
Copy Markdown
Member

Jocs commented Nov 5, 2024

@kamesan012 Please describe the issue which you want to fix?

@kamesan012
Copy link
Copy Markdown
Author

@kamesan012 Please describe the issue which you want to fix?

#175

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent incorrect selection behavior caused by unnecessary inline re-rendering, primarily by avoiding DOM rewrites when the rendered HTML hasn’t changed and by preserving cursor context during certain updates.

Changes:

  • Skip innerHTML assignment in InlineRenderer.patch when the computed HTML matches the existing DOM.
  • Pass a cursor into Format.blurHandler()’s update() call to better preserve inline rendering behavior around the selection.
  • Relax Content.getCursor()’s “selection must be in this block” gating by commenting out the anchorBlock/focusBlock check.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/inlineRenderer/index.ts Avoids rewriting inline HTML when unchanged to reduce selection disruption.
packages/core/src/block/base/format.ts Updates blur re-render flow to optionally supply a cursor to update().
packages/core/src/block/base/content.ts Changes getCursor() behavior by removing the per-block selection guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 211 to 224
const {
anchor,
focus,
anchorBlock,
focusBlock,
// anchorBlock,
// focusBlock,
isCollapsed,
isSelectionInSameBlock, // This is always be true.
direction,
type,
} = selection;

if (anchorBlock !== this || focusBlock !== this)
return null;
// if (anchorBlock !== this || focusBlock !== this)
// return null;

Comment on lines 337 to 357
override blurHandler() {
super.blurHandler();
const needRender = this.checkNeedRender();
const _cursor = this.getCursor();
let cursor = null;
if (_cursor) {
const { start, end } = _cursor;
cursor = {
path: this.path,
block: this,
anchor: {
offset: start.offset,
},
focus: {
offset: end.offset,
},
};
}
if (needRender)
this.update();
cursor ? this.update(cursor) : this.update();
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants