overleaf/libraries/overleaf-editor-core/test/comment.test.js

117 lines
4.1 KiB
JavaScript
Raw Normal View History

Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
// @ts-check
'use strict'
const { expect } = require('chai')
const Comment = require('../lib/comment')
const Range = require('../lib/range')
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
describe('Comment', function () {
it('should move ranges to the right of insert', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const resComment = comment.applyInsert(3, 5, false)
expect(resComment.ranges).to.eql([new Range(10, 10)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
describe('applyInsert', function () {
it('should insert 1 char before the range', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
expect(comment.applyInsert(4, 1).ranges).to.eql([new Range(6, 10)])
})
it('should insert 1 char at the edge, without expandCommand', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
expect(comment.applyInsert(5, 1).ranges).to.eql([new Range(6, 10)])
})
it('should insert 1 char at the edge, with expandCommand', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
expect(comment.applyInsert(5, 1, true).ranges).to.eql([new Range(5, 11)])
})
it('should expand the range after insert inside it', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
expect(comment.applyInsert(6, 1, true).ranges).to.eql([new Range(5, 11)])
})
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should split the range if inside another and expandComment is false', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyInsert(6, 10, false)
expect(commentRes.ranges).to.eql([new Range(5, 1), new Range(16, 9)])
})
it('should insert the range if expandComment is false', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyInsert(14, 10, false)
expect(commentRes.ranges).to.eql([new Range(5, 9), new Range(24, 1)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should move the range if insert is at range start and expandComment is false', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyInsert(5, 10, false)
expect(commentRes.ranges).to.eql([new Range(15, 10)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should ignore the range if insert is at range end and expandComment is false', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyInsert(15, 10, false)
expect(commentRes.ranges).to.eql([new Range(5, 10)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should expand the range after inserting on the edge of it if expandComment is true', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyInsert(15, 10, true)
expect(commentRes.ranges).to.eql([new Range(5, 20)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
it('should move comment ranges if delete is before it', function () {
const comment = new Comment('c1', [new Range(5, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyDelete(new Range(3, 5))
expect(commentRes.ranges).to.eql([new Range(3, 7)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should merge ranges after delete', function () {
const comment = new Comment('c1', [new Range(5, 10), new Range(20, 10)])
[overleaf-core-editor] Make comment properties immutable (#17022) * make range class immutable * rename variable * use newRanges * range readonly props * skrinkBy test * Fix range shrinking bug * [overleaf-core-editor] Make comment properties immutable * remove added line * format fix * make readonly array * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871) * [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation * added add comment op test * delete comment op test * import core to escape circle deps * desctructure in tests * require directly in builder * invert of add comment is always delete comment * no merging on compose * NoOp if comment is not found * use comment.clone() * update test * change CommentRawData type * jsdoc assert type * fix formating * EditNoOperation * return other in compose * use ReturnType * Revert "use ReturnType" This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992. * transorm add comment operation * transform delete comment operation * moved comment.js * format fix * fix transform addComment and textoperation * fix merge * test more complex test operations * change to else if * move range.js * fix types * fix AddComment and TextOperation transform * fixed AddComment-TextOperation trasform, added test * deletecommentoperation should win * should not delete comment * remove unused function, fix type * fix format * add resolved for existing comment * transform EditNoOperation * fix test description * change the order of EditNoOperation * fix DeleteCommentOperation-DeleteCommentOperation transform * fix types after merging main * refactor operation types * fix errors after merging * fix bad merge * format fix * removed comment.clone() * return old comment * remove unused var GitOrigin-RevId: e31d723075cb04b0b7177e7cae0014c295f92a68
2024-02-20 06:28:51 -05:00
const commentRes = comment.applyDelete(new Range(7, 18))
expect(commentRes.ranges).to.eql([new Range(5, 7)])
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should merge overlapping ranges', function () {
const comment = new Comment('c1', [
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
new Range(5, 10),
new Range(15, 20),
new Range(50, 10),
])
expect(comment.ranges).to.eql([new Range(5, 30), new Range(50, 10)])
})
it('should merge unsorted ranges', function () {
const comment = new Comment('c1', [
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
new Range(15, 20),
new Range(50, 10),
new Range(5, 10),
])
expect(comment.ranges).to.eql([new Range(5, 30), new Range(50, 10)])
})
it('should throw error when ranges overlap', function () {
expect(
() =>
new Comment('c1', [
new Range(5, 10),
new Range(10, 5),
new Range(50, 10),
])
).to.throw()
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
})
it('should join touching ranges', function () {
const comment = new Comment('c1', [
Added applyInsert/applyDelete methods to comments (#16572) * Add CommentList to StringFileData * added more types * use toRaw * using Map rather than array for comments * using Range class * Comment with ranges:Range[] * Revert "Comment with ranges:Range[]" This reverts commit 0783b1837562600637db03cc70c620129061c797. * Comment with ranges:Range[] * remove isDeleted * commentList.toRaw() * using toRaw * commentId to id * Revert "using toRaw" This reverts commit 0c04ca5836f3befd5ec027bad5bf722e8b27f36c. * fix merge * make comment map internal to CommentList * remove unused type * fix parameter name in StringFileData * import types more consistently * more consistent type def * Added moveOnInsert/moveOnDelete methods to comments * use range helper methods * mergeRanges function * rename isAfter to startsAfter * added @ts-checks * using comment.isEmpty * rename overlaps to covers * remove ops in applyDelete * mege, substract, isInRange * ranges fixes, added tests * rename to includes * using pos,length in applyInsert * simplify * extendComment option * check comment edges * added inclusive option * more specific touches() * refactor mergeRanges() * comment.addRange() * remove inclusive option * refactor using more helper methods * fix typo * inserting a comment between ranges tests * test description fixes * support only range * more edge case testing * added more range tests * renamed to containsExcludingEdges * endsAt check edge * using firstIndex, lastIndex * contains, containsIndex * raturn -1 for lastIndex for empty ranges * rename ranges in tests * indexStartsAfter * sort comment ranges * rename to indexIsAfter, fix Range type * add range if expandComment is true * split the range when expandComment is false * added moveBy and extendBy * added more tests * added comments * prettier * small fixes/typos * rename indexIsAfter * merge when deleting with overlaps * added overlap test * same range touches test * test with overlapping comments * delete duplicate test * throw on empty range GitOrigin-RevId: 1252e3d01f2f5dc1d00ce681c579506038e4d121
2024-02-01 06:31:11 -05:00
new Range(5, 10),
new Range(15, 5),
new Range(50, 10),
])
expect(comment.ranges).to.eql([new Range(5, 15), new Range(50, 10)])
})
})