Skip to content

Edits using the visual editor can cause the wrong line to get executed when running individual lines #12021

Closed

Description

@ronblum

System details

RStudio Edition : Desktop and Server
RStudio Version : 2022.11.0-daily+202
OS Version      : MacOS 13, Ubuntu 20.04 via Chrome on MacOS 13
R Version       : 4.2.1

Steps to reproduce the problem

  1. Create a new Quarto document.
  2. Switch to source mode.
  3. Paste in the contents of the file at https://github.com/hadley/r4ds/blob/c24e0b86920aba0b57c7ca314215c04716cd0f3c/iteration.qmd
  4. Switch to visual mode.
  5. Click on the first line in the first chunk, #| results: "asis"
  6. Cmd-Return
    • The first bit of code is executed
    • Note: the warning is expected because we didn't create the file being sourced, but that's not important.
> #| results: "asis"
> #| echo: false
> source("_common.R")
Warning: cannot open file '_common.R': No such file or directoryError in file(filename, "r", encoding = encoding) : 
  cannot open the connection
  1. Place the cursor at the end of the first header, Iteration, and hit Return
  2. Enter some text, e.g. Now is the winter of our discontent.
  3. Click on the first line in the first chunk, #| results: "asis"
  4. Cmd-Return
  • The new text above is executed.
> Now is the winter of our discontent.
Error: unexpected symbol in "Now is"
  1. Click on the last line in the first chunk, status("drafting")
  2. Cmd-Return
    • The line above it is executed.
> source("_common.R")
Warning: cannot open file '_common.R': No such file or directoryError in file(filename, "r", encoding = encoding) : 
  cannot open the connection

Describe the problem in detail

After a chunk's line of code is run and new lines are added, running a line of code tries to execute a line above it—even if that line is in the body of the text and not in the chunk.

I haven't been able to pinpoint a minimal example—whether it's the length of the file or something specific to the contents—which is why I'm using all ofiteration.qmd in the reprex.

Describe the behavior you expected

Cmd-Return should always run the current line. This works correctly in RStudio Desktop 2022.07.2+576 on MacOS 13.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added
    visual markdown
    on Sep 22, 2022
  2. added this to the Elsbeth Geranium milestone on Sep 22, 2022
  3. ronblum commented on Sep 23, 2022

    @ronblum
    ContributorAuthor

    Note: Switching to source mode and back resolves the issue temporarily, but once a new line is inserted again, the problem recurs.

  4. kevinushey commented on Sep 23, 2022

    @kevinushey
    Collaborator

    Also saw this warning in the JS console.

    Screen Shot 2022-09-23 at 12 08 35 PM

  5. kevinushey commented on Sep 23, 2022

    @kevinushey
    Collaborator

    It looks like the issue might be related to indented chunks (which live as part of a bulleted list)? I can reproduce fairly readily with a document like this:

    ---
    editor: 
      markdown: 
        wrap: sentence
    ---
    
    # Reprexathon
    
    ```{r}
    # I'm a chunk!
    ```
    
    ### Indentathon
    
    1.  Here's an indented chunk.
    
        ```{r}
        # I sure hope I don't break anything!
        ```
    
  6. jmcphers commented on Sep 23, 2022

    @jmcphers
    Member

    All the code execution happens in the source editor; the warning indicates that the code that aligns the source editor with the visual editor (which we do every time you execute code) isn't seeing a consistent view of the set of chunks. It is almost certainly responsible for the error.

  7. hadley commented on Sep 25, 2022

    @hadley
    Member

    It just occurred to me that this setting might also add to the problem:

    Screen Shot 2022-09-25 at 09 23 12

  8. hadley commented on Sep 26, 2022

    @hadley
    Member

    FWIW this is making the visual editor almost unusable for me (and I can't switch back to the released version, because the data corruption there is a worse problem).

  9. jonvanausdeln commented on Sep 29, 2022

    @jonvanausdeln

    Verified on 2022.11.0-daily+228
    Windows 11, Ubuntu 22.04

    Tested with OP example and additional example from Kevin. Both work as expected. I also tried with a few other variations of those 2 examples.

  10. hadley commented on Oct 5, 2022

    @hadley
    Member

    I'm still seeing this in 2022.11.0-daily+245 😞

  11. 12 remaining items

  12. jmcphers commented on Nov 9, 2022

    @jmcphers
    Member

    Moved this to Test. @hadley fix should be in build 319 or newer if you want to try it out.

  13. hadley commented on Nov 9, 2022

    @hadley
    Member

    DOWNLOADING NOW

  14. hadley commented on Nov 9, 2022

    @hadley
    Member

    So far so good!

  15. hadley commented on Nov 10, 2022

    @hadley
    Member

    Ok, I hit the problem again, but this time it was because I had accidentally created a corrupted code chunk that looked like this:

    ``` {)}
    
    # They have the same width
    str_width(u)
    # But a different length
    ```
    
  16. jonvanausdeln commented on Nov 10, 2022

    @jonvanausdeln

    When I tried that corrupted chunk, it doesn't execute anything. The original example works.

  17. hadley commented on Nov 10, 2022

    @hadley
    Member

    @jonvanausdeln you would need to put the corrupted chunk somewhere further down the document.

  18. jonvanausdeln commented on Nov 15, 2022

    @jonvanausdeln

    @kevinushey , should this be moved back to in-progress? Or should this corrupted chunk be broken out into a separate issue?

  19. kevinushey commented on Nov 15, 2022

    @kevinushey
    Collaborator

    I placed the issue back to in-progress. @jmcphers, do you have the bandwidth to take a look?

  20. mikebessuille commented on Nov 15, 2022

    @mikebessuille
    Contributor

    Is that new problem as critical to fix for Elsbeth? We are looking to move out anything that isn't absolutely critical at this point...

  21. kevinushey commented on Nov 15, 2022

    @kevinushey
    Collaborator

    @hadley is the existing fix "good enough" or are you still bumping into this on a regular basis?

  22. hadley commented on Nov 17, 2022

    @hadley
    Member

    Oh yeah, this is working well for me, thanks!

  23. mikebessuille commented on Nov 17, 2022

    @mikebessuille
    Contributor

    @kevinushey @jonvanausdeln i feel like if we're going to fix part of this for Elsbeth, and defer the special case, it should be split into a separate issue.

  24. removed
    info needed
    on Nov 17, 2022
  25. jonvanausdeln commented on Nov 17, 2022

    @jonvanausdeln

    I agree. I will create a new issue for the special case and close out this one as it resolves the main issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugregressionvisual markdown

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions