Alter comments

pull/21833/head
Luke Barnard 2017-08-15 09:25:23 +01:00
parent 5f00bbbff6
commit 65dc9fda6e
1 changed files with 4 additions and 1 deletions

View File

@ -202,6 +202,9 @@ export function selectionStateToTextOffsets(selectionState: SelectionState,
export function textOffsetsToSelectionState({start, end}: SelectionRange, export function textOffsetsToSelectionState({start, end}: SelectionRange,
contentBlocks: Array<ContentBlock>): SelectionState { contentBlocks: Array<ContentBlock>): SelectionState {
let selectionState = SelectionState.createEmpty(); let selectionState = SelectionState.createEmpty();
// Subtract block lengths from `start` and `end` until they are less than the current
// block length (accounting for the NL at the end of each block). Set them to -1 to
// indicate that the corresponding selection state has been determined.
for (const block of contentBlocks) { for (const block of contentBlocks) {
const blockLength = block.getLength(); const blockLength = block.getLength();
// -1 indicating that the position start position has been found // -1 indicating that the position start position has been found
@ -223,7 +226,7 @@ export function textOffsetsToSelectionState({start, end}: SelectionRange,
focusKey: block.getKey(), focusKey: block.getKey(),
focusOffset: end, focusOffset: end,
}); });
end = -1; // selection state for the start calculated end = -1; // selection state for the end calculated
} else { } else {
end -= blockLength + 1; // +1 to account for newline between blocks end -= blockLength + 1; // +1 to account for newline between blocks
} }