Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 65dc9fd

Browse files
author
Luke Barnard
committed
Alter comments
1 parent 5f00bbb commit 65dc9fd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/RichText.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ export function selectionStateToTextOffsets(selectionState: SelectionState,
202202
export function textOffsetsToSelectionState({start, end}: SelectionRange,
203203
contentBlocks: Array<ContentBlock>): SelectionState {
204204
let selectionState = SelectionState.createEmpty();
205+
// Subtract block lengths from `start` and `end` until they are less than the current
206+
// block length (accounting for the NL at the end of each block). Set them to -1 to
207+
// indicate that the corresponding selection state has been determined.
205208
for (const block of contentBlocks) {
206209
const blockLength = block.getLength();
207210
// -1 indicating that the position start position has been found
@@ -223,7 +226,7 @@ export function textOffsetsToSelectionState({start, end}: SelectionRange,
223226
focusKey: block.getKey(),
224227
focusOffset: end,
225228
});
226-
end = -1; // selection state for the start calculated
229+
end = -1; // selection state for the end calculated
227230
} else {
228231
end -= blockLength + 1; // +1 to account for newline between blocks
229232
}

0 commit comments

Comments
 (0)