Markdown toolbar: improve logic for syntax insertion depending on cursor position #17718
Labels
area: publishing experience
issues related to an authors experience publishing. Tags, series, etc.
This issue covers two main logic improvements for markdown formatting
1. Inserting formatting in the middle of a line or word
At the moment, we insert any formatting wherever the cursor currently is, without regard to where that is. Let's improve that:
If the cursor is in the middle of a word, and no text is selected, and an "inline" formatter is used, we format the whole word
Inline formatters are those which do not require new lines to be inserted. For example bold, italic, underline, strikethrough.
For example, (imagine the
|
character is a cursor) given the cursor positionsome|thing
, pressing the bold formatter would result in**something**
. i.e. when the cursor is in the middle of a word, with no text selected, then the formatter buttons behave as if the whole word had been selected.If the cursor is in or at the end of a word, and no text is selected, and a "block" formatter is used, we bring the given word into the inserted block formatting
Block formatters are ones which require new lines on either side. For example: ordered/unordered lists, code blocks, blockquotes, new lines, headings.
Given the user has their cursor at the end of word, e.g. (imagine
|
character is the cursor)Something|
orSome|thing
, when a user uses a block formatter like unordered list, the word "Something" would be brought into the formatting, e.g.:In other words, when the cursor is inside or at the end of the word, the formatter behaves as if the whole word had been selected
2. Ignore leading and trailing whitespace
When a user highlights trailing whitespaces on either side of a phrase, currently we treat this as part of a selection meaning we might insert e.g.
**some text **
. Similarly, if a user doesn't highlight the exact portion of formatted text, clicking the button will not 'undo' that syntax - e.g. if user highlights**something**
(including trailing space), the result would be****something** **
.Let's improve the UX here by ignoring any trailing/leading whitespace on a word selection. i.e. if a user highlights a word or phrase that begins and/or ends with a space, the result should be the same as if they had not selected the spaces.
The text was updated successfully, but these errors were encountered: