Behaviour SwRS-MDOKFSTUDIO-BLOCK-234
Preview edits keep the line endings of the document
When the extension plans or writes back a preview edit, it SHALL treat LF, CR LF and a lone CR as line ends, count one more empty last line after a final line break, and keep the line ending that the edited text ended with, write the line breaks inside an edited multi-line block with the one line ending the block (or, for a block of one line, the document) already uses, including the CR LF endings of a table and the presence or absence of its final line ending.
Another outcome at step 2 of path 1 in StRS-MDOKFSTUDIO-BLOCK-025, in the state “The typed text is in the document”.
Scenarios 5
The situations the tests check; open one to read it.
nominalA save restores the trailing line ending of the block
| Original block text ends with | Text posted by the save |
|---|---|
| LF | the text box content plus the same LF |
| CR LF | the text box content plus the same CR LF |
| CR | the text box content plus the same CR |
| no line ending (a block at the end of a file without a final line break) | the text box content with no trailing line break either |
nominalA multi-line block keeps its line ending when saved
| Input | Outcome |
|---|---|
| A block of several lines in a CR LF document, a line added in the text box (which returns LF) | The lines written to the document, the new one included, end with CR LF |
| The same in a document whose lines end with a lone CR | The lines written end with CR |
| The same in a document with LF line breaks | The lines written end with LF |
| A block of one line, or the last block of a file without a final line break, in a CR LF or lone-CR document | The lines written end with the one line ending of the document |
| A block whose line endings are mixed (a text that already holds a CR is written as it is) | The lines the edit left alone keep their line endings; a changed line takes the ending of the line it replaces (the line above when lines were added or removed) |
| A document with mixed line endings when the block has no line break | The text box content is written as it is |
nominalA CRLF table keeps its line endings
| Input | Outcome |
|---|---|
| a CRLF table with a trailing line ending and a row inserted, then written back | all lines, the new one included, end with CRLF and the trailing line ending is kept |
| the same table with one cell edited, then written back | the line endings are unchanged |
| a CRLF table without a trailing line ending | the absence of the final line ending is kept |
nominalA save on a real CRLF, LF or mixed file changes the block only
| Input | Outcome |
|---|---|
| A paragraph or a list saved in a document read from a file with CR LF line endings (with or without a final line break), LF line endings, or both | Every byte outside the block is the one of the file; the block keeps its own line ending |
| Any of these saves in a CR LF file | No bare LF is added |
| Any of these saves in an LF file | No CR is added |
boundaryCounting lines
| Input | Outcome |
|---|---|
| a document `a\r\nb\nc\rd` and an edit that names line 4 | the edit lands on `d`, because the text has four lines a, b, c and d |
| the text `a\n` and an edit that names line 2 | line 2 exists and is empty |
Implemented in 4
Tested by 11
- test/core/edits/lineEndingPreservation.test.tsunit
- test/core/edits/matchLineEndings.test.tsunit
- test/core/edits/sourceEdits.test.tsunit
- test/core/edits/textEdit.test.tsunit
- test/host/editLineEndings.test.tsunit
- test/integration/realInput/qa210Replays.tsintegration
- test/page/modules/markdownTable.test.tsunit
- test/page/runtimeBlockEditorLineEndings.test.tsunit
- test/session/blockReq.requirements.test.tsunit
- test/session/lineEndingSave.test.tsunit
- test/visual/scenarioDefinitions1.tsvisual