bugfix: Allow selection to start/end before line marker

This commit is contained in:
John McLear 2021-09-24 16:46:53 +01:00 committed by Richard Hansen
parent 37a33042d2
commit c361df52d2
2 changed files with 29 additions and 5 deletions

View file

@ -103,12 +103,12 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
const markerWidth = this.lineHasMarker(row) ? 1 : 0;
if (lineLength - markerWidth < 0) throw new Error(`line ${row} has negative length`);
const startCol = row === start[0] ? start[1] : markerWidth;
if (startCol - markerWidth < 0) throw new RangeError('selection starts before line start');
if (start[1] < 0) throw new RangeError('selection starts at negative column');
const startCol = Math.max(markerWidth, row === start[0] ? start[1] : 0);
if (startCol > lineLength) throw new RangeError('selection starts after line end');
const endCol = row === end[0] ? end[1] : lineLength;
if (endCol - markerWidth < 0) throw new RangeError('selection ends before line start');
if (end[1] < 0) throw new RangeError('selection ends at negative column');
const endCol = Math.max(markerWidth, row === end[0] ? end[1] : lineLength);
if (endCol > lineLength) throw new RangeError('selection ends after line end');
if (startCol > endCol) throw new RangeError('selection ends before it starts');