SO-Close-Vote-Reviewers / UserScripts

Various user scripts that add features to the review queue or to the chat room
Other
57 stars 40 forks source link

Magic Editor: Cannot use backspace to delete whitespace part of a code block if it is selected #109

Closed ferrybig closed 6 years ago

ferrybig commented 6 years ago

Based on my deleted MSO question: https://meta.stackoverflow.com/questions/358761/cannot-use-backspace-to-delete-whitespace-part-of-a-code-block-if-it-is-selected

When selecting the newline + intention only, and then pressing backspace, something happens inside the SO editor, making it unable to actually delete the text.

Steps to reproduce:

  1. Code the code block to the answer section on the page (or press edit)
  2. Start your selection from the end of <tit line
  3. End your selection just before le>
  4. Press backspace, as you are trying to "fix" the code
  5. Expect that the unneeded newline is deleted
  6. Observe the newline is still there, and your selection cleared
  7. ???

I expect when I select from the enter after a line to the next word, that when I press backspace, the full block is deleted, however nothing happens.

Example, because this bug is hard to explain:

! Bug that shows when pressing backspace after selecting whitespace only

Try it out here:

<html>
    <head>
         <tit
         le>test</title>
    </head>
</html>

After discussing in the comments on Meta SO, it seemed like this bug was caused by something inside the Magic Editor

surajrao commented 6 years ago

There seems to be a workaround which I tried to explain in the comment section in your question. Below is the recording.

When using magic editor I used Option + Delete to remove selected content. In windows it could be Alt + Backspace/Delete

makyen commented 6 years ago

On Windows I can duplicate this using Backspace. A (Windows) workaround is to just use the Delete key instead.

makyen commented 6 years ago

Notes: Our Magic™Editor fork gets the code for this functionality from Better handling of indentation and the TAB key when editing posts. Unfortunately, the repository for that project appears to be unmaintained (last update 2012-03-27). However, the owner did interact with a pull request on 2016-03-17. The owner is still around (i.e. active on Stack Exchange & an SO employee). There are three pull requests pending, including one from 2015 that addresses this issue (or at least something quite close). The repository is hosted on bitbucket.org, which does not support filing issues.

The other PR which we might be interested in incorporating would not be compatible with IE (if that's something we are attempting to maintain), but could be easily changed to be compatible with IE.

The most recent PR on that project only affects things specific to that project being a separate userscript.

mogsdad commented 6 years ago

Balpha's script intended to treat backspace as a tab alignment, when the line began with just whitespace. However, it didn't specifically handle selections properly. I think it's best if we go with native behavior for backspace when there is a selection, otherwise preserving the tab alignment behavior.