mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 21:24:59 +08:00
add getter for intersecting parts of range, and total length
we'll need this when replacing selection, to preserve newlines, etc ... in the selected range (e.g. we can't just use range.text).
This commit is contained in:
parent
48f1bf1816
commit
77b14beb1f
@ -57,4 +57,27 @@ export default class Range {
|
||||
this._model.replaceRange(this._start, this._end, parts);
|
||||
return newLength - oldLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the (partial) parts within the range.
|
||||
* For partial parts, only the text is adjusted to the part that intersects with the range.
|
||||
*/
|
||||
get parts() {
|
||||
const parts = [];
|
||||
this._start.iteratePartsBetween(this._end, this._model, (part, startIdx, endIdx) => {
|
||||
const serializedPart = part.serialize();
|
||||
serializedPart.text = part.text.substring(startIdx, endIdx);
|
||||
const newPart = this._model.partCreator.deserializePart(serializedPart);
|
||||
parts.push(newPart);
|
||||
});
|
||||
return parts;
|
||||
}
|
||||
|
||||
get length() {
|
||||
let len = 0;
|
||||
this._start.iteratePartsBetween(this._end, this._model, (part, startIdx, endIdx) => {
|
||||
len += endIdx - startIdx;
|
||||
});
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user