I tried to edit a post and I noticed there were some keys which needed kbd formatting. I selected the text and clicked kbd, but the result was strange. The text looked before:
Afterwards, it looked like:
While in the desired result the SHIFTs should not have been there.
Interestingly, trying again worked, and worked and then failed. This seemed interesting on me, so I started testing to find the bug.
After a bit of digging, I realized there were 2 interesting variable assignments in sox.common.jssurroundSelectedText() function:
const selS = textarea.selectionStart;
const selE = textarea.selectionEnd;
This however, doesn't seem write. What if I select the text with my cursor from right to left? Then selS would have selectionEnd and selEselectionStartactually. This appeared to produce the strange results.
A fix is to check if selectionStart is less than selectionEnd and vice versa and assign accordingly. After all, the feature now works regardless of how you select the text.
I tried to edit a post and I noticed there were some keys which needed
kbd
formatting. I selected the text and clickedkbd
, but the result was strange. The text looked before:Afterwards, it looked like:
While in the desired result the
SHIFT
s should not have been there.Interestingly, trying again worked, and worked and then failed. This seemed interesting on me, so I started testing to find the bug.
After a bit of digging, I realized there were 2 interesting variable assignments in
sox.common.js
surroundSelectedText()
function:This however, doesn't seem write. What if I select the text with my cursor from right to left? Then
selS
would haveselectionEnd
andselE
selectionStart
actually. This appeared to produce the strange results.A fix is to check if
selectionStart
is less thanselectionEnd
and vice versa and assign accordingly. After all, the feature now works regardless of how you select the text.