Skip to content

MDOCS-3155 soft line break bug fix#23

Merged
simon-d-miro merged 4 commits intomainfrom
MDOCS-3155-soft-line-break
Jul 24, 2025
Merged

MDOCS-3155 soft line break bug fix#23
simon-d-miro merged 4 commits intomainfrom
MDOCS-3155-soft-line-break

Conversation

@simon-d-miro
Copy link
Collaborator

@simon-d-miro simon-d-miro commented Jul 22, 2025

Motivation

When pasting text with a soft break in it near the end of a line, the soft break would (1) not be inserted and (2) the orignal preceeding characters would replace the soft breaks. For example

Document:

0123
   ^ - insert at index 3

Change Delta:
{insert: '45[SOFT_LINE_BREAK]67'}

Invalid outcome produced
01245367

Investigation

The issue is in block.ts

 softLines.forEach((str) => {
        if (i < this.length() - 1 || this.children.tail == null) {

After the first invocation of the loop, we should go into the first if statement but we don't because
i < this.length() - 1
doesn't take into account the fact we have modified the document

Fix

  1. Check the if statement first
  2. update insertIndex calculation in the first if Math.min(i, this.length() - 1 + addedChars);

@simon-d-miro simon-d-miro added bug Something isn't working change:bugfix and removed bug Something isn't working labels Jul 22, 2025
@simon-d-miro simon-d-miro force-pushed the MDOCS-3155-soft-line-break branch from b473afb to 41a81db Compare July 22, 2025 13:00
@simon-d-miro simon-d-miro changed the title MDOCS-3155 soft line break MDOCS-3155 soft line break bug fix Jul 22, 2025
Copy link

@DeanWay DeanWay left a comment

Choose a reason for hiding this comment

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

You can apply these suggestions if you like but otherwise the solution works as is, LGTM

@simon-d-miro simon-d-miro force-pushed the MDOCS-3155-soft-line-break branch from d514d1b to 22c3105 Compare July 24, 2025 13:22
@simon-d-miro simon-d-miro merged commit 6ad7c33 into main Jul 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants