Search code examples
mobiledoc-kit

Break link insertion with space in Mobiledoc-kit


Right now "default" behavior, when the user converts some text into the link, is to recognize consecutively inputted text as the part of the 'a' tag.

Let's take demo app as example:

  1. there is a text 'This is Mobiledoc-kit' on the page

  2. I select 'Mobiledoc-kit' fragment of it and make it a link pointing to the https://bustlelabs.github.io/mobiledoc-kit/demo/

  3. Right after that I started to type and entered ' example app' (pay attention to leading space).

  4. And this text became a part of the link, so now link is not just 'Mobiledoc-kit', but also all the text till the end of the line: 'Mobiledoc-kit example app'

Question here is how to make it 'humble'/not greedy' - denote that link border is within selected text only?


Solution

  • @lessless Thanks for this question!

    This "bug" has been fixed now in mobiledoc-kit as of v0.10.2. The "left/right inclusivity rules" for mobiledoc-kit markups were updated in this PR: https://github.com/bustlelabs/mobiledoc-kit/pull/438.

    Links ("A" markups) have very conservative inclusivity...the cursor is only considered to be part of the link if it is completely within the text of the link (as opposed to on the left or right side).

    A neat thing about this change is that in the future we can open up inclusivity rules to users of mobiledoc-kit, also. For instance you could deliberately make some markups "greedy" if you wanted to (e.g., normally a char is only bold if the character to the immediate left of the cursor was bold when the char was typed, but you could change the left-inclusivity of the bold markup so that text that is typed on the left side of a chunk of bold text also becomes bold...)