···312312 })
313313314314 if (postLinkFacet) {
315315- // remove the post link from the text
316316- rt.delete(
317317- postLinkFacet.index.byteStart,
318318- postLinkFacet.index.byteEnd,
319319- )
315315+ const isAtStart = postLinkFacet.index.byteStart === 0
316316+ const isAtEnd =
317317+ postLinkFacet.index.byteEnd === rt.unicodeText.graphemeLength
320318321321- // re-trim the text, now that we've removed the post link
322322- //
323323- // if the post link is at the start of the text, we don't want to leave a leading space
324324- // so trim on both sides
325325- if (postLinkFacet.index.byteStart === 0) {
326326- rt = new RichText({text: rt.text.trim()}, {cleanNewlines: true})
327327- } else {
328328- // otherwise just trim the end
329329- rt = new RichText(
330330- {text: rt.text.trimEnd()},
331331- {cleanNewlines: true},
319319+ // remove the post link from the text
320320+ if (isAtStart || isAtEnd) {
321321+ rt.delete(
322322+ postLinkFacet.index.byteStart,
323323+ postLinkFacet.index.byteEnd,
332324 )
333325 }
326326+327327+ rt = new RichText({text: rt.text.trim()}, {cleanNewlines: true})
334328 }
335329 }
336330 } catch (error) {