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

207 lines
5.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
const { RetainOp, InsertOp, RemoveOp } = require('./operation/scan_op')
const Range = require('./range')
/**
* @import { CommentRawData } from "./types"
* @import TextOperation from "./operation/text_operation"
*/
class Comment {
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
* @readonly
* @type {ReadonlyArray<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
*/
ranges = []
/**
[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
* @readonly
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
* @type {boolean}
*/
resolved = false
/**
* @param {string} id
[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
* @param {ReadonlyArray<Range>} ranges
* @param {boolean} [resolved]
*/
constructor(id, ranges, resolved = false) {
this.id = id
this.resolved = resolved
[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
this.ranges = this.mergeRanges(ranges)
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
}
/**
*
* @param {number} cursor
* @param {number} length
* @param {boolean} [extendComment]
[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
* @returns {Comment}
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
*/
applyInsert(cursor, length, extendComment = false) {
let existingRangeExtended = false
const newRanges = []
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
for (const commentRange of this.ranges) {
if (cursor === commentRange.end) {
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
// insert right after the comment
if (extendComment) {
newRanges.push(commentRange.extendBy(length))
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
existingRangeExtended = true
} else {
newRanges.push(commentRange)
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
}
} else if (cursor === commentRange.start) {
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
// insert at the start of the comment
if (extendComment) {
newRanges.push(commentRange.extendBy(length))
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
existingRangeExtended = true
} else {
newRanges.push(commentRange.moveBy(length))
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
}
} else if (commentRange.startIsAfter(cursor)) {
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
// insert before the comment
newRanges.push(commentRange.moveBy(length))
} else if (commentRange.containsCursor(cursor)) {
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
// insert is inside the comment
if (extendComment) {
newRanges.push(commentRange.extendBy(length))
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
existingRangeExtended = true
} else {
const [rangeUpToCursor, , rangeAfterCursor] = commentRange.insertAt(
cursor,
length
)
// use current commentRange for the part before the cursor
newRanges.push(new Range(commentRange.pos, rangeUpToCursor.length))
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
// add the part after the cursor as a new range
newRanges.push(rangeAfterCursor)
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
}
} else {
// insert is after the comment
newRanges.push(commentRange)
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
}
}
// if the insert is not inside any range, add a new range
if (extendComment && !existingRangeExtended) {
[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
newRanges.push(new Range(cursor, length))
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
return new Comment(this.id, newRanges, this.resolved)
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
}
/**
*
* @param {Range} deletedRange
[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
* @returns {Comment}
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
*/
applyDelete(deletedRange) {
const newRanges = []
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
for (const commentRange of this.ranges) {
if (commentRange.overlaps(deletedRange)) {
newRanges.push(commentRange.subtract(deletedRange))
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
} else if (commentRange.startsAfter(deletedRange)) {
newRanges.push(commentRange.moveBy(-deletedRange.length))
} else {
newRanges.push(commentRange)
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
}
}
return new Comment(this.id, newRanges, this.resolved)
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
}
/**
*
* @param {TextOperation} operation
* @param {string} commentId
[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
* @returns {Comment}
*/
applyTextOperation(operation, commentId) {
[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
/** @type {Comment} */
let comment = this
let cursor = 0
for (const op of operation.ops) {
if (op instanceof RetainOp) {
cursor += op.length
} else if (op instanceof InsertOp) {
comment = comment.applyInsert(
cursor,
op.insertion.length,
op.commentIds?.includes(commentId)
)
cursor += op.insertion.length
} else if (op instanceof RemoveOp) {
[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
comment = comment.applyDelete(new Range(cursor, op.length))
}
}
[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
return comment
}
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
isEmpty() {
return this.ranges.length === 0
}
/**
*
* @returns {CommentRawData}
*/
toRaw() {
/** @type CommentRawData */
const raw = {
id: this.id,
ranges: this.ranges.map(range => range.toRaw()),
}
if (this.resolved) {
raw.resolved = true
}
return raw
}
[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
/**
* @param {ReadonlyArray<Range>} ranges
* @returns {ReadonlyArray<Range>}
*/
mergeRanges(ranges) {
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
/** @type {Range[]} */
const mergedRanges = []
[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 sortedRanges = [...ranges].sort((a, b) => a.start - b.start)
for (const range of sortedRanges) {
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
if (range.isEmpty()) {
continue
}
const lastMerged = mergedRanges[mergedRanges.length - 1]
if (lastMerged?.overlaps(range)) {
throw new Error('Ranges cannot overlap')
}
if (range.isEmpty()) {
throw new Error('Comment range cannot be empty')
}
if (lastMerged?.canMerge(range)) {
mergedRanges[mergedRanges.length - 1] = lastMerged.merge(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
} else {
mergedRanges.push(range)
}
}
[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
return mergedRanges
}
/**
* @param {CommentRawData} rawComment
* @returns {Comment}
*/
static fromRaw(rawComment) {
return new Comment(
rawComment.id,
rawComment.ranges.map(range => Range.fromRaw(range)),
rawComment.resolved
)
}
}
module.exports = Comment