diff --git a/src/api/converter.ts b/src/api/converter.ts index 648f08a59..1fee5a158 100644 --- a/src/api/converter.ts +++ b/src/api/converter.ts @@ -277,12 +277,18 @@ function toTextNodeBoundary( switch (boundary?.getType()) { case BoundaryType.Before: pbTextNodeBoundary.setType(PbBoundaryType.BOUNDARY_TYPE_BEFORE); + break; case BoundaryType.After: pbTextNodeBoundary.setType(PbBoundaryType.BOUNDARY_TYPE_AFTER); + break; case BoundaryType.Start: pbTextNodeBoundary.setType(PbBoundaryType.BOUNDARY_TYPE_START); + break; case BoundaryType.End: pbTextNodeBoundary.setType(PbBoundaryType.BOUNDARY_TYPE_END); + break; + case BoundaryType.None: + pbTextNodeBoundary.setType(PbBoundaryType.BOUNDARY_TYPE_NONE); } return pbTextNodeBoundary; } @@ -929,14 +935,18 @@ function fromTextNodeBoundary( switch (pbTextNodeBoundary.getType()) { case PbBoundaryType.BOUNDARY_TYPE_BEFORE: boundaryType = BoundaryType.Before; + break; case PbBoundaryType.BOUNDARY_TYPE_AFTER: boundaryType = BoundaryType.After; + break; case PbBoundaryType.BOUNDARY_TYPE_START: boundaryType = BoundaryType.Start; + break; case PbBoundaryType.BOUNDARY_TYPE_END: boundaryType = BoundaryType.End; - default: - boundaryType = undefined; + break; + case PbBoundaryType.BOUNDARY_TYPE_NONE: + boundaryType = BoundaryType.None; } return RGATreeSplitBoundary.of( RGATreeSplitNodeID.of( diff --git a/src/api/yorkie/v1/resources.proto b/src/api/yorkie/v1/resources.proto index 7e5bec2e3..65a1d2010 100644 --- a/src/api/yorkie/v1/resources.proto +++ b/src/api/yorkie/v1/resources.proto @@ -336,6 +336,7 @@ enum BoundaryType { BOUNDARY_TYPE_AFTER = 1; BOUNDARY_TYPE_START = 2; BOUNDARY_TYPE_END = 3; + BOUNDARY_TYPE_NONE = 4; } message TextNodeBoundary { diff --git a/src/api/yorkie/v1/resources_pb.d.ts b/src/api/yorkie/v1/resources_pb.d.ts index 0cf39e6a3..83f60acb0 100644 --- a/src/api/yorkie/v1/resources_pb.d.ts +++ b/src/api/yorkie/v1/resources_pb.d.ts @@ -1619,6 +1619,7 @@ export enum BoundaryType { BOUNDARY_TYPE_AFTER = 1, BOUNDARY_TYPE_START = 2, BOUNDARY_TYPE_END = 3, + BOUNDARY_TYPE_NONE = 4, } export enum ValueType { VALUE_TYPE_NULL = 0, diff --git a/src/api/yorkie/v1/resources_pb.js b/src/api/yorkie/v1/resources_pb.js index 412fe75c9..01c1823a6 100644 --- a/src/api/yorkie/v1/resources_pb.js +++ b/src/api/yorkie/v1/resources_pb.js @@ -13407,7 +13407,8 @@ proto.yorkie.v1.BoundaryType = { BOUNDARY_TYPE_BEFORE: 0, BOUNDARY_TYPE_AFTER: 1, BOUNDARY_TYPE_START: 2, - BOUNDARY_TYPE_END: 3 + BOUNDARY_TYPE_END: 3, + BOUNDARY_TYPE_NONE: 4 }; /** diff --git a/src/document/crdt/rga_tree_split.ts b/src/document/crdt/rga_tree_split.ts index bf18cc461..2172ae3ea 100644 --- a/src/document/crdt/rga_tree_split.ts +++ b/src/document/crdt/rga_tree_split.ts @@ -63,6 +63,8 @@ export enum BoundaryType { After = 'after', Start = 'start', End = 'end', + // TODO(MoonGyu1): 'None' type can be deleted after replacing existing logic with mark + None = 'none', } /** @@ -415,10 +417,16 @@ export class RGATreeSplitNode< return this.insPrev!.getID(); } + /** + * `getStyleOpsBefore` returns a styleOpsBefore of this node. + */ public getStyleOpsBefore(): Set | undefined { return this.styleOpsBefore; } + /** + * `getStyleOpsAfter` returns a styleOpsAfter of this node. + */ public getStyleOpsAfter(): Set | undefined { return this.styleOpsAfter; } @@ -463,10 +471,16 @@ export class RGATreeSplitNode< } } + /** + * `setStyleOpsBefore` sets styleOpsBefore of this node. + */ public setStyleOpsBefore(operations: Set): void { this.styleOpsBefore = operations; } + /** + * `setStyleOpsAfter` sets styleOpsAfter of this node. + */ public setStyleOpsAfter(operations: Set): void { this.styleOpsAfter = operations; } @@ -844,7 +858,7 @@ export class RGATreeSplit { public splitNodeByBoundary(boundary: RGATreeSplitBoundary): void { const absoluteID = boundary.getID(); if (absoluteID?.getCreatedAt()) { - let node = this.findFloorNodePreferToLeft(absoluteID); + const node = this.findFloorNodePreferToLeft(absoluteID); const relativeOffset = absoluteID.getOffset() - node.getID().getOffset(); this.splitNode(node, relativeOffset); diff --git a/src/document/crdt/text.ts b/src/document/crdt/text.ts index 01cbb60ba..5a251d799 100644 --- a/src/document/crdt/text.ts +++ b/src/document/crdt/text.ts @@ -71,7 +71,7 @@ export type AttributeSpec = { export type MarkSpec = { expand: 'before' | 'after' | 'both' | 'none'; allowMultiple: boolean; - excludes?: string[]; + excludes?: Array; attributes?: { [key: string]: AttributeSpec }; }; @@ -272,7 +272,10 @@ export class CRDTText extends CRDTGCElement { const fromBoundary = range[0]; const toBoundary = range[1]; // 02-1. Update styleOpsBefore and styleOpsAfter if it is a bold type - if (fromBoundary.getType() && toBoundary?.getType()) { + if ( + fromBoundary.getType() != BoundaryType.None && + toBoundary?.getType() != BoundaryType.None + ) { // TODO(MoonGyu1): Peritext 2. Update styleOpsBefore/styleOpsAfter of fromRight/toRight nodes const createdAtMapByActor = new Map(); @@ -405,8 +408,8 @@ export class CRDTText extends CRDTGCElement { ); return [ - RGATreeSplitBoundary.of(fromRight.getID()), - RGATreeSplitBoundary.of(toRight?.getID()), + RGATreeSplitBoundary.of(fromRight.getID(), BoundaryType.None), + RGATreeSplitBoundary.of(toRight?.getID(), BoundaryType.None), ]; } diff --git a/src/document/json/text.ts b/src/document/json/text.ts index 8d7ae03f6..40c476f4c 100644 --- a/src/document/json/text.ts +++ b/src/document/json/text.ts @@ -234,8 +234,12 @@ export class Text { return true; } - // TODO(MoonGyu1): Peritext 1. Add removeStyle method - removeStyle(fromIdx: number, toIdx: number, attributes: A) {} + /** + * `removeStyle` remove styles from text with the given attributes. + */ + removeStyle(fromIdx: number, toIdx: number, attributes: A) { + // TODO(MoonGyu1): Peritext 1. Add removeStyle method + } /** * `indexRangeToPosRange` returns TextRangeStruct of the given index range.