Skip to content

Commit

Permalink
fix(blocks): newline handling in MixTextAdapter and paste middleware (#…
Browse files Browse the repository at this point in the history
…8821)

Fix #8816

Also related to #8575

Revert and adjust newline insertion logic to improve text handling in the MixTextAdapter and clipboard paste functionality.
  • Loading branch information
lawvs committed Nov 28, 2024
1 parent c7735b6 commit 0c3cc78
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/blocks/src/_common/adapters/mix-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ export class MixTextAdapter extends BaseAdapter<MixText> {
const text = (o.node.props.text ?? { delta: [] }) as {
delta: DeltaInsert[];
};
if (buffer.length > 0) {
buffer += '\n';
}
switch (o.node.flavour) {
case 'affine:code': {
buffer += text.delta.map(delta => delta.insert).join('');
buffer += '\n';
break;
}
case 'affine:paragraph': {
buffer += text.delta.map(delta => delta.insert).join('');
buffer += '\n';
break;
}
case 'affine:list': {
buffer += text.delta.map(delta => delta.insert).join('');
buffer += '\n';
break;
}
case 'affine:divider': {
buffer += '---\n';
buffer += '---';
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ class PasteTr {
this.snapshot.content.forEach((blockSnapshot, i) => {
if (blockSnapshot.props.text) {
const text = this._textFromSnapshot(blockSnapshot);
if (i != 0 && i !== this.snapshot.content.length - 1) {
if (i > 0) {
deltas.push({ insert: '\n' });
}
if (i != 0 && i === this.snapshot.content.length - 1) {
this.lastIndex -= 1;
}
deltas.push(...text.delta);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bc
d
d
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
hi
j
j
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aaa
bbb
ccc
ccc

0 comments on commit 0c3cc78

Please sign in to comment.