The encapsulateSelection method of jquery.textSelection is now inserting content in the wrong place when editing Page: pages on Wikisource.
The origin of this problem is that change  (T185917) is now using the getContents method of jquery.textSelection that is returning not only the text that is in the main textarea but also some extra wikitext for the header and footer. The introduction of such wikitext (useful when switching between VisualEditor and WikiEditor) is making the positions where the insertion should happen wrong, leading to introduce tags in the wrong places.
To reproduce this issue:
- Go to https://en.wikisource.org/w/index.php?title=Page:The_American_Indian.djvu/197&action=edit (it should load the WikiEditor)
- Select some text
- Click on the button to insert bold
- The bold tags quotes are not inserted in the right place.