Skip to content

Commit

Permalink
Add boundary type 'none' and apply lint
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonGyu1 committed Sep 15, 2023
1 parent 482e252 commit 5bef0ad
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ enum BoundaryType {
BOUNDARY_TYPE_AFTER = 1;
BOUNDARY_TYPE_START = 2;
BOUNDARY_TYPE_END = 3;
BOUNDARY_TYPE_NONE = 4;
}

message TextNodeBoundary {
Expand Down
1 change: 1 addition & 0 deletions src/api/yorkie/v1/resources_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/api/yorkie/v1/resources_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down
16 changes: 15 additions & 1 deletion src/document/crdt/rga_tree_split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

/**
Expand Down Expand Up @@ -415,10 +417,16 @@ export class RGATreeSplitNode<
return this.insPrev!.getID();
}

/**
* `getStyleOpsBefore` returns a styleOpsBefore of this node.
*/
public getStyleOpsBefore(): Set<StyleOperation> | undefined {
return this.styleOpsBefore;
}

/**
* `getStyleOpsAfter` returns a styleOpsAfter of this node.
*/
public getStyleOpsAfter(): Set<StyleOperation> | undefined {
return this.styleOpsAfter;
}
Expand Down Expand Up @@ -463,10 +471,16 @@ export class RGATreeSplitNode<
}
}

/**
* `setStyleOpsBefore` sets styleOpsBefore of this node.
*/
public setStyleOpsBefore(operations: Set<StyleOperation>): void {
this.styleOpsBefore = operations;
}

/**
* `setStyleOpsAfter` sets styleOpsAfter of this node.
*/
public setStyleOpsAfter(operations: Set<StyleOperation>): void {
this.styleOpsAfter = operations;
}
Expand Down Expand Up @@ -844,7 +858,7 @@ export class RGATreeSplit<T extends RGATreeSplitValue> {
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);
Expand Down
11 changes: 7 additions & 4 deletions src/document/crdt/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type AttributeSpec = {
export type MarkSpec = {
expand: 'before' | 'after' | 'both' | 'none';
allowMultiple: boolean;
excludes?: string[];
excludes?: Array<string>;
attributes?: { [key: string]: AttributeSpec };
};

Expand Down Expand Up @@ -272,7 +272,10 @@ export class CRDTText<A extends Indexable = Indexable> 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<string, TimeTicket>();
Expand Down Expand Up @@ -405,8 +408,8 @@ export class CRDTText<A extends Indexable = Indexable> extends CRDTGCElement {
);

return [
RGATreeSplitBoundary.of(fromRight.getID()),
RGATreeSplitBoundary.of(toRight?.getID()),
RGATreeSplitBoundary.of(fromRight.getID(), BoundaryType.None),
RGATreeSplitBoundary.of(toRight?.getID(), BoundaryType.None),
];
}

Expand Down
8 changes: 6 additions & 2 deletions src/document/json/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,12 @@ export class Text<A extends Indexable = Indexable> {
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) {

Check warning on line 240 in src/document/json/text.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'fromIdx' is defined but never used

Check warning on line 240 in src/document/json/text.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'toIdx' is defined but never used

Check warning on line 240 in src/document/json/text.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'attributes' is defined but never used
// TODO(MoonGyu1): Peritext 1. Add removeStyle method
}

/**
* `indexRangeToPosRange` returns TextRangeStruct of the given index range.
Expand Down

0 comments on commit 5bef0ad

Please sign in to comment.