feat(workspace): split bulletpoint paragraph at cursor position on Enter
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 59s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 59s
This commit is contained in:
1 parent
5cf6b59377
commit
fdbf691a8d
2 files changed
+26
-7
No files matched your search
@@ -55,7 +55,7 @@ export interface OutlinerBlockProps {
|
||||
levelOffset?: number;
|
||||
onZoomBlock?: (blockId: string) => void;
|
||||
onUpdateBlock: (updated: DocumentBlock, immediate?: boolean) => void;
|
||||
onCreateBlockBelow: (afterBlockId: string, currentContent: string) => void;
|
||||
onCreateBlockBelow: (afterBlockId: string, newContent?: string) => void;
|
||||
onDeleteBlock: (blockId: string, deleteSubtree?: boolean) => void;
|
||||
onIndentBlock: (blockId: string, delta: 1 | -1) => void;
|
||||
onNavigateFocus: (blockId: string, direction: 'up' | 'down') => void;
|
||||
@@ -366,7 +366,7 @@ export const OutlinerBlock: React.FC<OutlinerBlockProps> = ({
|
||||
// 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
|
||||
// - Otherwise split paragraph at cursor and create new block below
|
||||
if (e.key === 'Enter' && !e.shiftKey && block.type !== 'code') {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@@ -385,8 +385,27 @@ export const OutlinerBlock: React.FC<OutlinerBlockProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
flushDebounce(localContent);
|
||||
onCreateBlockBelowRef.current(block.id, localContent);
|
||||
const start = e.currentTarget.selectionStart ?? localContent.length;
|
||||
const end = e.currentTarget.selectionEnd ?? start;
|
||||
let beforeText = localContent.slice(0, start);
|
||||
let afterText = localContent.slice(end);
|
||||
|
||||
// Clean linebreaks at the split boundary if present
|
||||
if (beforeText.endsWith('\r\n')) {
|
||||
beforeText = beforeText.slice(0, -2);
|
||||
} else if (beforeText.endsWith('\n')) {
|
||||
beforeText = beforeText.slice(0, -1);
|
||||
}
|
||||
if (afterText.startsWith('\r\n')) {
|
||||
afterText = afterText.slice(2);
|
||||
} else if (afterText.startsWith('\n')) {
|
||||
afterText = afterText.slice(1);
|
||||
}
|
||||
|
||||
setLocalContent(beforeText);
|
||||
localContentRef.current = beforeText;
|
||||
flushDebounce(beforeText);
|
||||
onCreateBlockBelowRef.current(block.id, afterText);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user