Tweaked readOnly mode

This commit is contained in:
Rainer Simon 2020-05-29 10:44:11 +02:00
parent a2599a9237
commit 71f390b316
2 changed files with 4 additions and 3 deletions

View File

@ -39,7 +39,7 @@ export default class TextAnnotator extends Component {
componentDidMount() { componentDidMount() {
this.highlighter = new Highlighter(this.props.contentEl, this.props.formatter); 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.selectionHandler.on('select', this.handleSelect);
this.relationsLayer = new RelationsLayer(this.props.contentEl); this.relationsLayer = new RelationsLayer(this.props.contentEl);

View File

@ -5,11 +5,12 @@ const IS_TOUCH = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
export default class SelectionHandler extends EventEmitter { export default class SelectionHandler extends EventEmitter {
constructor(element, highlighter) { constructor(element, highlighter, readOnly) {
super(); super();
this.el = element; this.el = element;
this.highlighter = highlighter; this.highlighter = highlighter;
this.readOnly = readOnly;
this.isEnabled = true; this.isEnabled = true;
@ -47,7 +48,7 @@ export default class SelectionHandler extends EventEmitter {
// De-select // De-select
this.emit('select', {}); this.emit('select', {});
} }
} else { } else if (!this.readOnly) {
const selectedRange = trimRange(selection.getRangeAt(0)); const selectedRange = trimRange(selection.getRangeAt(0));
// Make sure the selection is entirely inside this.el // Make sure the selection is entirely inside this.el