Skip to content

ux: bug fix: improve insertion of uploaded file markup in compose

Andrew Chou requested to merge 2200/compose-file-markup-insert into master

Addresses #2200 (closed)

The implementation is similar but not identical to Github's markdown editor. Github will always insert \n as the prefix and suffix of the inserted text except in the following cases (in which it adds no prefix or suffix):

  1. there is no text before the selection start.
  2. there is a selection range (either some highlighted set of characters) that does not reach the beginning and end of the text e.g. selecting the middle word of a sentence

The main way this implementation differs is how it treats special case (2), as we:

  1. add a space character e.g. for the prefix and suffix. This is because Github inserts XML markup in this case whereas we still insert markdown markup, which benefits from the separation both visually and semantically. Question: would it make sense for us to just always insert \n prefix and suffix in the case? EDIT: We're always making sure that there's \n\n for prefix and suffix in this case now.
  2. set the cursor to the end of the inserted text rather than the beginning (which is what Github does). no strong reason for this, just thought it made enough sense 🤷

Test cases to consider (| indicates selection):

  1. Empty editor:

    • start with

      |
    • adding file results in:

      ![image](...)
      
      |
  2. Insert at end, no selection.

    • start with

      foo|
    • adding file results in:

      foo
      
      ![image](...)
      
      |
  3. Insert with full selection

    • start with

      |foo|
    • adding file results in:

      ![image](...)
      
      |
  4. Insert at end, partial selection

    • start with

      f|oo|
    • adding file results in:

      f
      
      ![image](...)
      
      |
  5. Insert at beginning, no selection.

    • start with

      |foo
    • adding file results in:

      ![image](...)
      
      |foo
  6. Insert at beginning, partial selection.

    • start with

      |fo|o
    • adding file results in:

      ![image](...)
      
      |o
  7. Insert in middle, no selection.

    • start with

      foo|bar
    • adding file results in:

      foo
      
      ![image](...)
      
      |bar
  8. Insert in middle, with partial selection.

    • start with

      foo|bar|baz
    • adding file results in:

      foo
      
      ![image](...)
      
      |baz
Edited by Andrew Chou

Merge request reports

Loading