Fix regressions in note content rendering logic
Changelog-None Closes: https://github.com/damus-io/damus/issues/3150 Closes: https://github.com/damus-io/damus/issues/3158 Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -124,6 +124,7 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
if can_hide_last_previewable_refs {
|
if can_hide_last_previewable_refs {
|
||||||
let _: ()? = blocks.withList({ blocksList in
|
let _: ()? = blocks.withList({ blocksList in
|
||||||
let endIndex = blocksList.count
|
let endIndex = blocksList.count
|
||||||
|
hide_text_index = endIndex
|
||||||
return blocksList.forEachItemReversed({ index, block in
|
return blocksList.forEachItemReversed({ index, block in
|
||||||
if block.is_previewable {
|
if block.is_previewable {
|
||||||
switch block {
|
switch block {
|
||||||
@@ -138,8 +139,7 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
return .loopBreak
|
return .loopBreak
|
||||||
}
|
}
|
||||||
case .url(let url_block):
|
case .url(let url_block):
|
||||||
guard let url_string = NdbBlock.convertToStringCopy(from: url_block),
|
guard let url = URL(string: url_block.as_str()) else {
|
||||||
let url = URL(string: url_string) else {
|
|
||||||
return .loopContinue // We can't classify this, ignore and move on
|
return .loopContinue // We can't classify this, ignore and move on
|
||||||
}
|
}
|
||||||
let url_type = classify_url(url)
|
let url_type = classify_url(url)
|
||||||
@@ -166,6 +166,9 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
// We should hide whitespace at the end sequence.
|
// We should hide whitespace at the end sequence.
|
||||||
hide_text_index = index
|
hide_text_index = index
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return .loopBreak
|
||||||
|
}
|
||||||
case .hashtag(_):
|
case .hashtag(_):
|
||||||
// SPECIAL CASE:
|
// SPECIAL CASE:
|
||||||
// We should keep hashtags at the end sequence but hide all the other previewables around it.
|
// We should keep hashtags at the end sequence but hide all the other previewables around it.
|
||||||
@@ -179,11 +182,9 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var ind: Int = -1
|
|
||||||
let txt: CompatibleText? = try? blocks.withList({ blocksList in
|
let txt: CompatibleText? = try? blocks.withList({ blocksList in
|
||||||
let endIndex = blocksList.count
|
let endIndex = blocksList.count
|
||||||
return try blocksList.reduce(initialResult: CompatibleText(), { index, str, block in
|
return try blocksList.reduce(initialResult: CompatibleText(), { index, str, block in
|
||||||
ind = ind + 1
|
|
||||||
|
|
||||||
// Add the rendered previewable blocks to their type-specific lists.
|
// Add the rendered previewable blocks to their type-specific lists.
|
||||||
switch block {
|
switch block {
|
||||||
@@ -204,7 +205,7 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
if can_hide_last_previewable_refs {
|
if can_hide_last_previewable_refs {
|
||||||
// If there are previewable blocks that occur before the consecutive sequence of them at the end of the content,
|
// If there are previewable blocks that occur before the consecutive sequence of them at the end of the content,
|
||||||
// we should not hide the text representation of any previewable block to avoid altering the format of the note.
|
// we should not hide the text representation of any previewable block to avoid altering the format of the note.
|
||||||
if ind < hide_text_index && block.is_previewable {
|
if index < hide_text_index && block.is_previewable {
|
||||||
hide_text_index = endIndex
|
hide_text_index = endIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,15 +214,15 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
// This is to save unnecessary use of screen space.
|
// This is to save unnecessary use of screen space.
|
||||||
// The only exception is that if there are hashtags embedded in the end sequence, which is not uncommon,
|
// The only exception is that if there are hashtags embedded in the end sequence, which is not uncommon,
|
||||||
// then we still want to show those hashtags but hide everything else that is previewable in the end sequence.
|
// then we still want to show those hashtags but hide everything else that is previewable in the end sequence.
|
||||||
if ind >= hide_text_index {
|
if index >= hide_text_index {
|
||||||
switch block {
|
switch block {
|
||||||
case .text(let txt_block):
|
case .text(let txt_block):
|
||||||
if let txt = NdbBlock.convertToStringCopy(from: txt_block),
|
if let txt = NdbBlock.convertToStringCopy(from: txt_block),
|
||||||
txt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
txt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||||
let returnItem: CompatibleText? = blocksList.useItem(at: ind + 1, { matchingBlock in
|
let returnItem: CompatibleText? = blocksList.useItem(at: index + 1, { matchingBlock in
|
||||||
switch matchingBlock {
|
switch matchingBlock {
|
||||||
case .hashtag(_):
|
case .hashtag(_):
|
||||||
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt))
|
return str + CompatibleText(stringLiteral: reduce_text_block(ind: index, hide_text_index: hide_text_index, txt: txt))
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -233,8 +234,9 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
case .hashtag(let htag):
|
case .hashtag(let htag):
|
||||||
return .loopReturn(str + hashtag_str(htag.as_str()))
|
return .loopReturn(str + hashtag_str(htag.as_str()))
|
||||||
default:
|
default:
|
||||||
break
|
return .loopContinue
|
||||||
}
|
}
|
||||||
|
return .loopReturn(str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +249,7 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
return .loopReturn(str + mention_str(.any(mention), profiles: profiles))
|
return .loopReturn(str + mention_str(.any(mention), profiles: profiles))
|
||||||
case .text(let txt):
|
case .text(let txt):
|
||||||
var hide_text_index_argument = hide_text_index
|
var hide_text_index_argument = hide_text_index
|
||||||
blocksList.useItem(at: ind+1, { block in
|
blocksList.useItem(at: index+1, { block in
|
||||||
switch block {
|
switch block {
|
||||||
case .hashtag(_):
|
case .hashtag(_):
|
||||||
// SPECIAL CASE:
|
// SPECIAL CASE:
|
||||||
@@ -258,7 +260,7 @@ func render_blocks(blocks: borrowing NdbBlockGroup, profiles: Profiles, can_hide
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return .loopReturn(str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index_argument, txt: txt.as_str())))
|
return .loopReturn(str + CompatibleText(stringLiteral: reduce_text_block(ind: index, hide_text_index: hide_text_index_argument, txt: txt.as_str())))
|
||||||
case .hashtag(let htag):
|
case .hashtag(let htag):
|
||||||
return .loopReturn(str + hashtag_str(htag.as_str()))
|
return .loopReturn(str + hashtag_str(htag.as_str()))
|
||||||
case .invoice(let invoice):
|
case .invoice(let invoice):
|
||||||
|
|||||||
Reference in New Issue
Block a user