Skip to content

Commit

Permalink
compat xhtml
Browse files Browse the repository at this point in the history
  • Loading branch information
sys committed May 3, 2021
1 parent ef62605 commit e7235a4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/blockview.ts
Expand Up @@ -97,8 +97,8 @@ export class LineView extends ContentView implements BlockView {
}
super.sync(track)
let last = this.dom!.lastChild
if (!last || (last.nodeName != "BR" && (ContentView.get(last) instanceof WidgetView))) {
let hack = document.createElement("BR")
if (!last || ((last as Element).localName !== "br" && (ContentView.get(last) instanceof WidgetView))) {
let hack = document.createElement("br")
;(hack as any).cmIgnore = true
this.dom!.appendChild(hack)
}
Expand Down
2 changes: 1 addition & 1 deletion src/buildview.ts
Expand Up @@ -125,5 +125,5 @@ class NullWidget extends WidgetType {
constructor(readonly tag: string) { super() }
eq(other: NullWidget) { return other.tag == this.tag }
toDOM() { return document.createElement(this.tag) }
updateDOM(elt: HTMLElement) { return elt.nodeName.toLowerCase() == this.tag }
updateDOM(elt: HTMLElement) { return elt.localName === this.tag }
}
2 changes: 1 addition & 1 deletion src/cursor.ts
Expand Up @@ -181,7 +181,7 @@ function isSuspiciousCaretResult(node: Node, offset: number, x: number) {
let len
if (node.nodeType != 3 || offset != (len = node.nodeValue!.length)) return false
for (let next = node.nextSibling; next; next = node.nextSibling)
if (next.nodeType != 1 || next.nodeName != "BR") return false
if (next.nodeType != 1 || (next as Element).localName !== "br") return false
return textRange(node as Text, len - 1, len).getBoundingClientRect().left > x
}

Expand Down
2 changes: 1 addition & 1 deletion src/dom.ts
Expand Up @@ -57,7 +57,7 @@ function scanFor(node: Node, off: number, targetNode: Node, targetOff: number, d
for (;;) {
if (node == targetNode && off == targetOff) return true
if (off == (dir < 0 ? 0 : maxOffset(node))) {
if (node.nodeName == "DIV") return false
if ((node as Element).localName === "div") return false
let parent = node.parentNode
if (!parent || parent.nodeType != 1) return false
off = domIndex(node) + (dir < 0 ? 0 : 1)
Expand Down
6 changes: 3 additions & 3 deletions src/domchange.ts
Expand Up @@ -155,7 +155,7 @@ class DOMReader {
if (next == end) break
let view = ContentView.get(cur), nextView = ContentView.get(next!)
if ((view ? view.breakAfter : isBlockElement(cur)) ||
((nextView ? nextView.breakAfter : isBlockElement(next!)) && !(cur.nodeName == "BR" && !(cur as any).cmIgnore)))
((nextView ? nextView.breakAfter : isBlockElement(next!)) && !((cur as Element).localName === "br" && !(cur as any).cmIgnore)))
this.text += this.lineBreak
cur = next!
}
Expand All @@ -169,7 +169,7 @@ class DOMReader {
let text: string | undefined
if (fromView != null) text = fromView.sliceString(0, undefined, this.lineBreak)
else if (node.nodeType == 3) text = node.nodeValue!
else if (node.nodeName == "BR") text = node.nextSibling ? this.lineBreak : ""
else if ((node as Element).localName === "br") text = node.nextSibling ? this.lineBreak : ""
else if (node.nodeType == 1) this.readRange(node.firstChild, null)

if (text != null) {
Expand All @@ -196,7 +196,7 @@ class DOMReader {
}

function isBlockElement(node: Node): boolean {
return node.nodeType == 1 && /^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(node.nodeName)
return node.nodeType == 1 && /^(div|p|li|ul|ol|blockquote|dd|dt|h\d|section|pre)$/.test((node as Element).localName)
}

class DOMPoint {
Expand Down

0 comments on commit e7235a4

Please sign in to comment.