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..5a9c1b3ef 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: model.BlockContentTextMark_Link, + 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: model.BlockContentTextMark_Object, + 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{