diff --git a/src/selection/Selection.js b/src/selection/Selection.js index d7f1189..9e1b4b2 100644 --- a/src/selection/Selection.js +++ b/src/selection/Selection.js @@ -8,25 +8,19 @@ import uuid from 'uuid/v1'; */ export default class Selection { - constructor(selectors) { + constructor(target) { this._stub = { type: 'Selection', body: [], - target: { - selector: selectors - } + target } } /** Creates a copy of this selection **/ clone = opt_props => { - // Clone selector(s) - const { selector } = this._stub.target; - - const clonedSelector = Array.isArray(selector) ? - selector.map(s => ({ ...s })) : { ...selector }; - - const cloned = new Selection(clonedSelector); + // Deep-clone target + const clonedTarget = JSON.parse(JSON.stringify(this._stub.target)); + const cloned = new Selection(clonedTarget); if (opt_props) cloned._stub = { ...cloned._stub, ...opt_props }; diff --git a/src/selection/SelectionUtils.js b/src/selection/SelectionUtils.js index 71f5d43..50bd897 100644 --- a/src/selection/SelectionUtils.js +++ b/src/selection/SelectionUtils.js @@ -37,14 +37,16 @@ export const rangeToSelection = (range, containerEl) => { const quote = range.toString(); const start = rangeBefore.toString().length; - return new Selection([{ - type: 'TextQuoteSelector', - exact: quote - }, { - type: 'TextPositionSelector', - start: start, - end: start + quote.length - }]); + return new Selection({ + selector: [{ + type: 'TextQuoteSelector', + exact: quote + }, { + type: 'TextPositionSelector', + start: start, + end: start + quote.length + }] + }); };