Skip to content

Commit 90dd67a

Browse files
committed
Clamping values b/w min and max
1 parent 91d3506 commit 90dd67a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/diff/cell.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ class CodeMirrorSplitDiffWidget extends BaseDiffWidget {
120120
arrowBtn.title = 'Revert Block';
121121

122122
arrowBtn.onclick = () => {
123+
const docB = paneB.state.doc;
124+
const docLength = docB.length;
125+
126+
const safeFromB = Math.min(Math.max(0, fromB), docLength);
127+
const safeToB = Math.min(Math.max(safeFromB, toB), docLength);
128+
123129
const origText = paneA.state.doc.sliceString(fromA, toA);
124130
paneB.dispatch({
125-
changes: { from: fromB, to: toB, insert: origText }
131+
changes: { from: safeFromB, to: safeToB, insert: origText }
126132
});
127133
this._renderArrowButtons();
128134
};

0 commit comments

Comments
 (0)