Skip to content

Source desync with Carriage Return #899

Description

@cady-b

Description

Uploading this file with a carriage return into a new project (base64 to avoid the CR being filtered out):

echo "I2xldCBmb28gPSBbIyIiXQoNCiNsZXQgYmFyID0gWyMiIl0K" | base64 -d > error.typ

If I (for example, but other actions may cause it too):

  1. Make a selection from within the first line, over the blank like (with CR), to the end of the second line
  2. Press Delete
  3. Undo the deletion

Things get messed up:

Image

This seems to be a desync, as if I then perform further actions, perfectly good looking files show compiler errors. Reloading the tab reveals the state it was in and lets me fix the issues, after which I can work as normal again if I avoid the line with the CR.

To me, this seems to be an issue in the webapp and not incremental as my neovim setup is fine and the following produces expected results:

use typst_syntax::{FileId, RootedPath, Source, VirtualPath, VirtualRoot};
fn main() {
    let start = "#let foo = [#\"\"]\n\r\n#let bar = [#\"\"]";
    let inter = "#let foo = [#\"";

    let mut a = Source::new(
        FileId::new(RootedPath::new(
            VirtualRoot::Project,
            VirtualPath::new("main.typ").unwrap(),
        )),
        start.to_owned(),
    );

    a.replace(inter);
    a.replace(start);

    println!("{} | {:#?}", a.text(), a.root());
}

The issue was initially reported on Discord by Honza_Suran: https://discord.com/channels/1054443721975922748/1518929890278375474

They are also seeing issues with their cursor around Carriage-returns, but I cannot reproduce this in Firefox. The other issue happens in both Chromium and Firefox under Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.editorRelated to the text/markup editor.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions