Custom line separator will cause offset/length mismatch

If you use a custom line separator, say \r\n, you can get the string back with the expected line separator by using state.doc.sliceString(from, to, state.lineBreak) which is great. And it also seems like the insertNewline uses state.lineBreak which is great.

If you document then contains a single “newline”, in this case the full document would be \r\n, there should be two characters. The length of the document should be 2, but it is 1. This casues issues when you’re trying to do something like coordsAtPos(2).

Is this intentional? Do you have any suggestion on a workaround?

This is intentional. In the addressing system inside the editor, line breaks always count as 1 unit. The fact that this differs from the strings you get out when you serialize the document is expected.

1 Like