Skip to content

Commit

Permalink
Remove Select operation from Text (#589)
Browse files Browse the repository at this point in the history
* Remove Select operation from Text

* Retaining the order of protobuf message
  • Loading branch information
joonhyukchoi authored Aug 1, 2023
1 parent 036a991 commit f571e72
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 187 deletions.
3 changes: 1 addition & 2 deletions api/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func TestConverter(t *testing.T) {
Edit(0, 1, "한").
Edit(0, 1, "하").
Edit(1, 1, "느").
Edit(1, 2, "늘").
Select(1, 2)
Edit(1, 2, "늘")

// rich text
root.SetNewText("k3").
Expand Down
27 changes: 0 additions & 27 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ func FromOperations(pbOps []*api.Operation) ([]operations.Operation, error) {
op, err = fromRemove(decoded.Remove)
case *api.Operation_Edit_:
op, err = fromEdit(decoded.Edit)
case *api.Operation_Select_:
op, err = fromSelect(decoded.Select)
case *api.Operation_Style_:
op, err = fromStyle(decoded.Style)
case *api.Operation_Increase_:
Expand Down Expand Up @@ -421,31 +419,6 @@ func fromRemove(pbRemove *api.Operation_Remove) (*operations.Remove, error) {
), nil
}

func fromSelect(pbSelect *api.Operation_Select) (*operations.Select, error) {
parentCreatedAt, err := fromTimeTicket(pbSelect.ParentCreatedAt)
if err != nil {
return nil, err
}
from, err := fromTextNodePos(pbSelect.From)
if err != nil {
return nil, err
}
to, err := fromTextNodePos(pbSelect.To)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbSelect.ExecutedAt)
if err != nil {
return nil, err
}
return operations.NewSelect(
parentCreatedAt,
from,
to,
executedAt,
), nil
}

func fromEdit(pbEdit *api.Operation_Edit) (*operations.Edit, error) {
parentCreatedAt, err := fromTimeTicket(pbEdit.ParentCreatedAt)
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ func ToOperations(ops []operations.Operation) ([]*api.Operation, error) {
pbOperation.Body, err = toRemove(op)
case *operations.Edit:
pbOperation.Body, err = toEdit(op)
case *operations.Select:
pbOperation.Body, err = toSelect(op)
case *operations.Style:
pbOperation.Body, err = toStyle(op)
case *operations.Increase:
Expand Down Expand Up @@ -368,17 +366,6 @@ func toEdit(e *operations.Edit) (*api.Operation_Edit_, error) {
}, nil
}

func toSelect(s *operations.Select) (*api.Operation_Select_, error) {
return &api.Operation_Select_{
Select: &api.Operation_Select{
ParentCreatedAt: ToTimeTicket(s.ParentCreatedAt()),
From: toTextNodePos(s.From()),
To: toTextNodePos(s.To()),
ExecutedAt: ToTimeTicket(s.ExecutedAt()),
},
}, nil
}

func toStyle(style *operations.Style) (*api.Operation_Style_, error) {
return &api.Operation_Style_{
Style: &api.Operation_Style{
Expand Down
15 changes: 0 additions & 15 deletions pkg/document/crdt/rga_tree_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,6 @@ func (pos *RGATreeSplitNodePos) Equal(other *RGATreeSplitNodePos) bool {
return pos.relativeOffset == other.relativeOffset
}

// Selection represents the selection of text range in the editor.
type Selection struct {
from *RGATreeSplitNodePos
to *RGATreeSplitNodePos
updatedAt *time.Ticket
}

func newSelection(from, to *RGATreeSplitNodePos, updatedAt *time.Ticket) *Selection {
return &Selection{
from,
to,
updatedAt,
}
}

// RGATreeSplitNode is a node of RGATreeSplit.
type RGATreeSplitNode[V RGATreeSplitValue] struct {
id *RGATreeSplitNodeID
Expand Down
13 changes: 0 additions & 13 deletions pkg/document/crdt/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func InitialTextNode() *RGATreeSplitNode[*TextValue] {
// Text is an extended data type for the contents of a text editor.
type Text struct {
rgaTreeSplit *RGATreeSplit[*TextValue]
selectionMap map[string]*Selection
createdAt *time.Ticket
movedAt *time.Ticket
removedAt *time.Ticket
Expand All @@ -126,7 +125,6 @@ type Text struct {
func NewText(elements *RGATreeSplit[*TextValue], createdAt *time.Ticket) *Text {
return &Text{
rgaTreeSplit: elements,
selectionMap: make(map[string]*Selection),
createdAt: createdAt,
}
}
Expand Down Expand Up @@ -276,17 +274,6 @@ func (t *Text) Style(
return nil
}

// Select stores that the given range has been selected.
func (t *Text) Select(
from *RGATreeSplitNodePos,
to *RGATreeSplitNodePos,
executedAt *time.Ticket,
) {
if prev, ok := t.selectionMap[executedAt.ActorIDHex()]; !ok || executedAt.After(prev.updatedAt) {
t.selectionMap[executedAt.ActorIDHex()] = newSelection(from, to, executedAt)
}
}

// Nodes returns the internal nodes of this Text.
func (t *Text) Nodes() []*RGATreeSplitNode[*TextValue] {
return t.rgaTreeSplit.nodes()
Expand Down
26 changes: 0 additions & 26 deletions pkg/document/json/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,3 @@ func (p *Text) Style(from, to int, attributes map[string]string) *Text {

return p
}

// Select stores that the given range has been selected.
func (p *Text) Select(from, to int) *Text {
if from > to {
panic("from should be less than or equal to to")
}
fromPos, toPos, err := p.Text.CreateRange(from, to)
if err != nil {
panic(err)
}

ticket := p.context.IssueTimeTicket()
p.Text.Select(
fromPos,
toPos,
ticket,
)

p.context.Push(operations.NewSelect(
p.CreatedAt(),
fromPos,
toPos,
ticket,
))
return p
}
91 changes: 0 additions & 91 deletions pkg/document/operations/select.go

This file was deleted.

0 comments on commit f571e72

Please sign in to comment.