mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Beta editor: Fix crash when switching between notes that use CRLF line endings (#10531)
This commit is contained in:
parent
c9fb06fd0c
commit
e049698012
@ -103,4 +103,14 @@ describe('CodeMirrorControl', () => {
|
||||
control.execCommand('deleteLine');
|
||||
expect(control.getValue()).toBe('Hello\n');
|
||||
});
|
||||
|
||||
it('should replace the editor body in a document with CRLF', () => {
|
||||
const initialContent = 'Hello\r\nWorld\r\na';
|
||||
const control = createEditorControl(initialContent);
|
||||
control.setCursor(1, initialContent.length);
|
||||
|
||||
control.updateBody('Hello\r\nWorld\r\n');
|
||||
control.updateBody('Hello\r\nWorld\r\ntest');
|
||||
control.updateBody('Hello\r\n');
|
||||
});
|
||||
});
|
||||
|
@ -102,7 +102,11 @@ export default class CodeMirrorControl extends CodeMirror5Emulation implements E
|
||||
// to ensure that the selection stays within the document
|
||||
// (and thus avoids an exception).
|
||||
const mainCursorPosition = this.editor.state.selection.main.anchor;
|
||||
const newCursorPosition = Math.min(mainCursorPosition, newBody.length);
|
||||
|
||||
// The maximum cursor position needs to be calculated using the EditorState,
|
||||
// to correctly account for line endings.
|
||||
const maxCursorPosition = this.editor.state.toText(newBody).length;
|
||||
const newCursorPosition = Math.min(mainCursorPosition, maxCursorPosition);
|
||||
|
||||
this.editor.dispatch(this.editor.state.update({
|
||||
changes: {
|
||||
|
Loading…
Reference in New Issue
Block a user