mirror of https://github.com/vector-im/riot-web
Add comments
parent
844ca249d0
commit
5f00bbbff6
|
@ -204,24 +204,26 @@ export function textOffsetsToSelectionState({start, end}: SelectionRange,
|
||||||
let selectionState = SelectionState.createEmpty();
|
let selectionState = SelectionState.createEmpty();
|
||||||
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
|
||||||
if (start !== -1) {
|
if (start !== -1) {
|
||||||
if (start < blockLength + 1) {
|
if (start < blockLength + 1) {
|
||||||
selectionState = selectionState.merge({
|
selectionState = selectionState.merge({
|
||||||
anchorKey: block.getKey(),
|
anchorKey: block.getKey(),
|
||||||
anchorOffset: start,
|
anchorOffset: start,
|
||||||
});
|
});
|
||||||
start = -1;
|
start = -1; // selection state for the start calculated
|
||||||
} else {
|
} else {
|
||||||
start -= blockLength + 1; // +1 to account for newline between blocks
|
start -= blockLength + 1; // +1 to account for newline between blocks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// -1 indicating that the position end position has been found
|
||||||
if (end !== -1) {
|
if (end !== -1) {
|
||||||
if (end < blockLength + 1) {
|
if (end < blockLength + 1) {
|
||||||
selectionState = selectionState.merge({
|
selectionState = selectionState.merge({
|
||||||
focusKey: block.getKey(),
|
focusKey: block.getKey(),
|
||||||
focusOffset: end,
|
focusOffset: end,
|
||||||
});
|
});
|
||||||
end = -1;
|
end = -1; // selection state for the start calculated
|
||||||
} else {
|
} else {
|
||||||
end -= blockLength + 1; // +1 to account for newline between blocks
|
end -= blockLength + 1; // +1 to account for newline between blocks
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue