From 612304ee6cc6dad10dde36792327a774d6ff7f81 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Wed, 2 Nov 2022 14:10:11 +0300 Subject: [PATCH 1/2] GO-431: fix object and link setting Signed-off-by: AnastasiaShemyakinskaya --- core/block/simple/text/text.go | 10 ++++- core/block/simple/text/text_test.go | 62 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/core/block/simple/text/text.go b/core/block/simple/text/text.go index ea62e5fa1..9a28b5281 100644 --- a/core/block/simple/text/text.go +++ b/core/block/simple/text/text.go @@ -186,7 +186,7 @@ func (t *Text) SetMarkForAllText(mark *model.BlockContentTextMark) { } filteredMarks := t.content.Marks.Marks[:0] for _, m := range t.content.Marks.Marks { - if m.Type != mark.Type { + if m.Type != mark.Type && !isIncompatibleType(m.Type, mark.Type) { filteredMarks = append(filteredMarks, m) } } @@ -699,3 +699,11 @@ func (t *Text) IsEmpty() bool { } return false } + +func isIncompatibleType(firstType, secondType model.BlockContentTextMarkType ) bool { + if (firstType == model.BlockContentTextMark_Link && secondType == model.BlockContentTextMark_Object) || + (secondType == model.BlockContentTextMark_Link && firstType == model.BlockContentTextMark_Object) { + return true + } + return false +} \ No newline at end of file diff --git a/core/block/simple/text/text_test.go b/core/block/simple/text/text_test.go index 9df8c6a67..cabc9f88e 100644 --- a/core/block/simple/text/text_test.go +++ b/core/block/simple/text/text_test.go @@ -355,6 +355,68 @@ func TestText_SetMarkForAllText(t *testing.T) { assert.Len(t, tb.Model().GetText().Marks.Marks, 2) } +func TestText_IncompatibleTypes(t *testing.T) { + b := NewText(&model.Block{ + Content: &model.BlockContentOfText{ + Text: &model.BlockContentText{ + Text: "1234567890", + Marks: &model.BlockContentTextMarks{ + Marks: []*model.BlockContentTextMark{ + &model.BlockContentTextMark{ + Range: &model.Range{ + From: 0, + To: 10, + }, + Type: 5, + Param: "https://www.youtube.com/", + }, + }, + }, + }, + }, + }) + tb := b.(Block) + tb.SetMarkForAllText(&model.BlockContentTextMark{ + Type: model.BlockContentTextMark_Object, + Range: &model.Range{ + From: 0, + To: 10, + }, + Param: "bafyba2frjwd6jnmisz7ejfld2yg3qe7z6g2f5r5dkwkfknkvs2xyuatc", + }) + assert.Len(t, tb.Model().GetText().Marks.Marks, 1) + + b = NewText(&model.Block{ + Content: &model.BlockContentOfText{ + Text: &model.BlockContentText{ + Text: "1234567890", + Marks: &model.BlockContentTextMarks{ + Marks: []*model.BlockContentTextMark{ + &model.BlockContentTextMark{ + Range: &model.Range{ + From: 0, + To: 10, + }, + Type: 10, + Param: "bafyba2frjwd6jnmisz7ejfld2yg3qe7z6g2f5r5dkwkfknkvs2xyuatc", + }, + }, + }, + }, + }, + }) + tb = b.(Block) + tb.SetMarkForAllText(&model.BlockContentTextMark{ + Type: model.BlockContentTextMark_Object, + Range: &model.Range{ + From: 0, + To: 10, + }, + Param: "https://www.youtube.com/", + }) + assert.Len(t, tb.Model().GetText().Marks.Marks, 1) +} + func TestText_RemoveMarkType(t *testing.T) { b := NewText(&model.Block{ Content: &model.BlockContentOfText{ From 5935e25d7530559c3983d367197cd44177a9c5e4 Mon Sep 17 00:00:00 2001 From: AnastasiaShemyakinskaya Date: Thu, 3 Nov 2022 12:23:44 +0300 Subject: [PATCH 2/2] GO-431: fix comments Signed-off-by: AnastasiaShemyakinskaya --- core/block/simple/text/text_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/block/simple/text/text_test.go b/core/block/simple/text/text_test.go index cabc9f88e..5a9c1b3ef 100644 --- a/core/block/simple/text/text_test.go +++ b/core/block/simple/text/text_test.go @@ -367,7 +367,7 @@ func TestText_IncompatibleTypes(t *testing.T) { From: 0, To: 10, }, - Type: 5, + Type: model.BlockContentTextMark_Link, Param: "https://www.youtube.com/", }, }, @@ -397,7 +397,7 @@ func TestText_IncompatibleTypes(t *testing.T) { From: 0, To: 10, }, - Type: 10, + Type: model.BlockContentTextMark_Object, Param: "bafyba2frjwd6jnmisz7ejfld2yg3qe7z6g2f5r5dkwkfknkvs2xyuatc", }, },