mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 09:35:00 +09:00
Merge pull request #1598 from anytypeio/go-431-blocktextlistsetmark-fix-apply-link
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
commit
4366d317ec
2 changed files with 71 additions and 1 deletions
|
@ -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
|
||||
}
|
|
@ -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{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue