55

To reproduce

Replace indented code with snippet in a question which has more explanation after the code

Expected result

Snippet replaces code

Actual result (in latest Chrome at least)

Snippet replaces code AND some of the text after the code - unless 3 empty lines before the text

Example (NITPICKERS: Yes it is not supposed to be in a snippet but shows the issue)

  1. Original question enter image description here
  2. Highlighting and cutting code enter image description here
  3. After inserting snippet enter image description here
13
  • 22
    Picking nits here, but that code shouldn't be in a snippet.
    – user4639281
    Commented Jun 5, 2017 at 16:50
  • 4
    Clearly the editor behavior is a bug, but why are you trying to turn that into a snippet in the first place? It isn't a complete runnable example.
    – Ben Voigt
    Commented Jun 5, 2017 at 16:50
  • 12
    @nitpickers - I used it as an example. I often use the snippet editor to format code or JSON and then remove the top line so it is no longer a snippet. As I commented, the example is poor but it shows the issue which is an issue for ANY code between texts
    – mplungjan
    Commented Jun 5, 2017 at 17:01
  • I'm having a hard time duplicating this. Playing around with adding a snippet by selecting existing code first isn't obliterating the text just below it. I've tried in the answer box here and in one on Main.
    – BSMP
    Commented Jun 5, 2017 at 17:22
  • 3
    @BSMP: I can repro this (on Chromium 58 / Linux), but only if I click the snippet button immediately after cutting the code from the edit box. Moving the cursor or making any changes to the edit box before launching the snippet editor makes this bug stop happening. So does even just clicking inside the box. Weird. Commented Jun 5, 2017 at 17:29
  • Maybe it's the specific version? I'm on version 57 on my work machine.
    – BSMP
    Commented Jun 5, 2017 at 18:04
  • 1
    Note that highlighting the code (without removing it) then creating a snippet and inserting it works as expected. I can only reproduce this when taking the extra step of removing the code prior to inserting a snippet.
    – user4639281
    Commented Jun 5, 2017 at 19:00
  • 1
    Sure I know how to work around, but forget it and then have to redo everything
    – mplungjan
    Commented Jun 5, 2017 at 19:12
  • 1
    I've also experienced this using Chrome 58 on a Win10 machine. Commented Jun 5, 2017 at 19:31
  • 14
    Oh thank God someone reported this. I thought that it was just me.
    – j08691
    Commented Jun 5, 2017 at 19:42
  • 1
    latest chrome has also other issues for me that half of the webs rich text editors don't function properly anymore. they must have changed something big under the hood. Commented Jun 6, 2017 at 12:31
  • 3
    Reminds me of another site I use that decided to "upgrade" their forum software and now you can't make posts from a mobile device. At least, not without severe effort (the software deletes the first space (and first symbol!) after every word, regardless of if the user taps the spacebar or if its autoinserted). I reported it and the site said, "It wasn't meant to be mobile friendly. [Closed: Won't Fix]" The site offers mobile-specific content. Commented Jun 6, 2017 at 15:55
  • 10
    I've been able to reproduce this. Going to do some investigation and see if we can get a fix.
    – Jon Chan StaffMod
    Commented Jun 7, 2017 at 16:23

1 Answer 1

7

Issue should be fixed now. This was an interesting one.

Basically what was happening was that when a user selected text then deleted it, the JavaScript plugin that we're using to detect the cursor selection's end point never updated. That means if you selected something like 50 characters then hit backspace, the editor would still remove the 50 characters after you add a snippet even though the original 50 characters you selected are now gone. It basically still thought you were highlighting some text after you hit backspace.

This was actually a problem for any of the editor's tools that added text to the body of the editor. This fix should make things a whole lot less confusing now.

1
  • This just happened to me. I was editing my answer in stackoverflow.com/questions/44464112/…. When I changed the code in the answer to a snippet, the explanation I had after the code disappeared.
    – Barmar
    Commented Jun 9, 2017 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .