fix(workspace): automatically refocus text field and place cursor at end after slash commands
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 59s

This commit is contained in:
sandrodach committed 2026-10-25 10:16:00 +01:00
1 parent 38e9c28c63
commit 714a8551c7
1 file changed
+23 -1
@@ -944,7 +944,7 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
);
return;
}
if (e.key === 'Enter') {
if (e.key === 'Enter' || e.key === 'Tab') {
e.preventDefault();
const selected = filteredSlashCommands[slashSelectedIndex];
if (selected) {
@@ -1017,6 +1017,27 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
updateBlock(blockId, { type, content: cleanContent, checked: type === 'todo' ? false : undefined });
setSlashBlockId(null);
setSlashSearch('');
// Re-focus immediately into the block's text field and position cursor at end
const focusBlock = () => {
const el = blockInputRefs.current[blockId];
if (el) {
el.focus();
if ('setSelectionRange' in el && typeof (el as any).value === 'string') {
const len = (el as any).value.length;
(el as any).setSelectionRange(len, len);
}
return true;
}
return false;
};
setLastFocusedBlockId(blockId);
setTimeout(() => {
if (!focusBlock()) {
setTimeout(focusBlock, 30);
}
}, 20);
};
const getDirectChildTodos = (blocks: DocumentBlock[], parentIndex: number): DocumentBlock[] => {
@@ -2415,6 +2436,7 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
<button
key={cmd.type}
type="button"
onMouseDown={(e) => e.preventDefault()}
onClick={() => applySlashCommand(block.id, cmd.type)}
className={`w-full text-left px-2 py-1.5 rounded-btn text-xs flex items-center justify-between transition-colors ${
slashSelectedIndex === idx