diff --git a/src/TextAnnotator.jsx b/src/TextAnnotator.jsx index f08aeba..2a26a33 100644 --- a/src/TextAnnotator.jsx +++ b/src/TextAnnotator.jsx @@ -39,7 +39,7 @@ export default class TextAnnotator extends Component { componentDidMount() { this.highlighter = new Highlighter(this.props.contentEl, this.props.formatter); - this.selectionHandler = new SelectionHandler(this.props.contentEl, this.highlighter); + this.selectionHandler = new SelectionHandler(this.props.contentEl, this.highlighter, this.props.readOnly); this.selectionHandler.on('select', this.handleSelect); this.relationsLayer = new RelationsLayer(this.props.contentEl); diff --git a/src/selection/SelectionHandler.js b/src/selection/SelectionHandler.js index 5b1a843..1c3e63b 100644 --- a/src/selection/SelectionHandler.js +++ b/src/selection/SelectionHandler.js @@ -5,11 +5,12 @@ const IS_TOUCH = 'ontouchstart' in window || navigator.maxTouchPoints > 0; export default class SelectionHandler extends EventEmitter { - constructor(element, highlighter) { + constructor(element, highlighter, readOnly) { super(); this.el = element; this.highlighter = highlighter; + this.readOnly = readOnly; this.isEnabled = true; @@ -47,7 +48,7 @@ export default class SelectionHandler extends EventEmitter { // De-select this.emit('select', {}); } - } else { + } else if (!this.readOnly) { const selectedRange = trimRange(selection.getRangeAt(0)); // Make sure the selection is entirely inside this.el