feat(outliner): prevent creating extra empty block on enter on last empty root bullet
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 59s

This commit is contained in:
sandrodach committed 2026-10-27 17:43:20 +01:00
1 parent 122ebccf8d
commit bce103e2c6
2 files changed
+19 -6

No files matched your search

@@ -41,6 +41,7 @@ const SLASH_COMMANDS: SlashCommand[] = [
export interface OutlinerBlockProps { export interface OutlinerBlockProps {
block: DocumentBlock; block: DocumentBlock;
index: number; index: number;
isLast: boolean;
maxAllowedLevel: number; maxAllowedLevel: number;
hasChildren: boolean; hasChildren: boolean;
isFocused: boolean; isFocused: boolean;
@@ -65,6 +66,7 @@ export interface OutlinerBlockProps {
export const OutlinerBlock: React.FC<OutlinerBlockProps> = ({ export const OutlinerBlock: React.FC<OutlinerBlockProps> = ({
block, block,
index, index,
isLast,
maxAllowedLevel, maxAllowedLevel,
hasChildren, hasChildren,
isFocused, isFocused,
@@ -343,17 +345,26 @@ export const OutlinerBlock: React.FC<OutlinerBlockProps> = ({
return; return;
} }
// 2. Enter (without Shift) -> If block is completely empty and level > minLevel, outdent (Shift+Tab behaviour), otherwise create new block below // 2. Enter (without Shift) -> If block is completely empty:
// - If level > minLevel, outdent (Shift+Tab behaviour)
// - If already at minLevel and is the last block, do NOT create another empty block below
// - Otherwise create new block below
if (e.key === 'Enter' && !e.shiftKey && block.type !== 'code') { if (e.key === 'Enter' && !e.shiftKey && block.type !== 'code') {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
setSlashSearch(null); setSlashSearch(null);
const minLevel = levelOffset || 0; const minLevel = levelOffset || 0;
if (localContent === '' && Math.max(0, block.level || 0) > minLevel) { if (localContent === '') {
flushDebounce(localContent); if (Math.max(0, block.level || 0) > minLevel) {
onIndentBlockRef.current(block.id, -1); flushDebounce(localContent);
return; onIndentBlockRef.current(block.id, -1);
return;
}
if (isLast) {
// Bereits auf oberster Ebene und der letzte Block: kein weiterer leerer Block
return;
}
} }
flushDebounce(localContent); flushDebounce(localContent);
@@ -360,12 +360,14 @@ export const OutlinerTree: React.FC<OutlinerTreeProps> = ({
return ( return (
<div className="space-y-0.5"> <div className="space-y-0.5">
{visibleEntries.map(({ block, index, hasChildren, maxAllowedLevel }) => { {visibleEntries.map(({ block, index, hasChildren, maxAllowedLevel }, entryIdx) => {
const isLast = entryIdx === visibleEntries.length - 1;
return ( return (
<OutlinerBlock <OutlinerBlock
key={block.id} key={block.id}
block={block} block={block}
index={index} index={index}
isLast={isLast}
maxAllowedLevel={maxAllowedLevel} maxAllowedLevel={maxAllowedLevel}
hasChildren={hasChildren} hasChildren={hasChildren}
isFocused={focusedBlockId === block.id} isFocused={focusedBlockId === block.id}