import { Paper } from "./paper";

// Determines if a <br> in the editable area is part of the document or a doorstop at the end of a block.
export function isBRPlaceholder(paper: Paper, node: Node) {
  if (node.nodeName !== 'BR') return false;
  return isLastNode(paper, node);
}

// Check if this is the last node (not counting empty text nodes)
function isLastNode(paper: Paper, node: Node) {
  let next = node.nextSibling;
  while (next && next.nodeValue === '') next = next.nextSibling;
  if (next) {
    if (next.nodeType === Node.ELEMENT_NODE) {
      return paper.blocks.matches(next as Element) || next.firstChild?.nodeType === Node.ELEMENT_NODE && paper.blocks.matches(next.firstChild as Element);
    }
  }
  return !node.parentNode || paper.blocks.matches(node.parentNode as Element) ? true : isLastNode(paper, node.parentNode);
}

import { Paper } from "./paper";

// Determines if a <br> in the editable area is part of the document or a doorstop at the end of a block.
export function isBRPlaceholder(paper: Paper, node: Node) {
  if (node.nodeName !== 'BR') return false;
  return isLastNode(paper, node);
}

// Check if this is the last node (not counting empty text nodes)
function isLastNode(paper: Paper, node: Node) {
  let next = node.nextSibling;
  while (next && next.nodeValue === '') next = next.nextSibling;
  if (next) return false;
  return !node.parentNode || paper.blocks.matches(node.parentNode as Element) ? true : isLastNode(paper, node.parentNode);
}

--- 
+++ 
@@ -10,6 +10,10 @@
 function isLastNode(paper: Paper, node: Node) {
   let next = node.nextSibling;
   while (next && next.nodeValue === '') next = next.nextSibling;
-  if (next) return false;
+  if (next) {
+    if (next.nodeType === Node.ELEMENT_NODE) {
+      return paper.blocks.matches(next as Element) || next.firstChild?.nodeType === Node.ELEMENT_NODE && paper.blocks.matches(next.firstChild as Element);
+    }
+  }
   return !node.parentNode || paper.blocks.matches(node.parentNode as Element) ? true : isLastNode(paper, node.parentNode);
 }
Fix selection-off issue with trailing BRs in lists
