Skip to content

Commit f044658

Browse files
committed
Fix bogus newline insertion on typing over multiple lines at end of document
FIX: Fix a bug where, when selecting full lines at the end of the document and inserting a character on Chrome, an inappropriate extra newline was inserted. See https://discuss.codemirror.net/t/extra-line-being-inserted/9620
1 parent e0968d4 commit f044658

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/domchange.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class DOMChange {
2727
this.newSel = null
2828
} else if (start > -1 && (this.bounds = domBoundsAround(view.docView.tile, start, end, 0))) {
2929
let selPoints = iHead || iAnchor ? [] : selectionPoints(view)
30-
let reader = new DOMReader(selPoints, view.state)
30+
let reader = new DOMReader(selPoints, view)
3131
reader.readRange(this.bounds.startDOM, this.bounds.endDOM)
3232
this.text = reader.text
3333
this.newSel = selectionFromPoints(selPoints, this.bounds.from)

src/domreader.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Tile} from "./tile"
22
import {domIndex, maxOffset, isBlockElement} from "./dom"
3+
import {EditorView} from "./editorview"
34
import {EditorState} from "@codemirror/state"
45

56
export const LineBreakPlaceholder = "\uffff"
@@ -8,8 +9,8 @@ export class DOMReader {
89
text: string = ""
910
lineSeparator: string | undefined
1011

11-
constructor(private points: DOMPoint[], state: EditorState) {
12-
this.lineSeparator = state.facet(EditorState.lineSeparator)
12+
constructor(private points: DOMPoint[], private view: EditorView) {
13+
this.lineSeparator = view.state.facet(EditorState.lineSeparator)
1314
}
1415

1516
append(text: string) {
@@ -29,7 +30,7 @@ export class DOMReader {
2930
this.readNode(cur)
3031
let tile = Tile.get(cur), next: Node | null = cur.nextSibling
3132
if (next == end) {
32-
if (tile?.breakAfter && !next) this.lineBreak()
33+
if (tile?.breakAfter && !next && parent != this.view.contentDOM) this.lineBreak()
3334
break
3435
}
3536
let nextTile = Tile.get(next!)

0 commit comments

Comments
 (0)