Skip to content

Commit 7d4a69c

Browse files
committed
Prevent focus loss and redundant re-renders in the Tasks panel during editing and reordering
- in nested tasks,on an empty task, clicking the delete button, or anywhere outside the input field, glitches it (it doesn't get deteled). - when removing a task, while it is in edit mode, we briefly see 'edit' icon button
1 parent db98b41 commit 7d4a69c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎packages/ui/src/components/editor/panel/Tasks/Tasks.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export const Tasks: React.FC<Props> = (props) => {
184184
{params.task.text && (
185185
<IconButton
186186
codicon_icon="forward"
187+
on_mouse_down={
188+
is_editing ? (e) => e.preventDefault() : undefined
189+
}
187190
on_click={(e) => {
188191
e.stopPropagation()
189192
props.on_forward(params.task.text)
@@ -204,6 +207,9 @@ export const Tasks: React.FC<Props> = (props) => {
204207
? { cursor: 'default' }
205208
: undefined
206209
}
210+
on_mouse_down={
211+
is_editing ? (e) => e.preventDefault() : undefined
212+
}
207213
on_click={(e) => {
208214
e.stopPropagation()
209215
navigator.clipboard.writeText(params.task.text)
@@ -233,6 +239,9 @@ export const Tasks: React.FC<Props> = (props) => {
233239
/>
234240
<IconButton
235241
codicon_icon="trash"
242+
on_mouse_down={
243+
is_editing ? (e) => e.preventDefault() : undefined
244+
}
236245
on_click={(e) => {
237246
e.stopPropagation()
238247
props.on_delete(params.task.created_at)

‎packages/ui/src/components/editor/panel/Tasks/components/TaskGroup.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ export const TaskGroup: React.FC<TaskGroupProps> = (props) => {
3232
<>
3333
<ReactSortable<SortableTask>
3434
list={props.items}
35-
setList={props.on_reorder}
35+
setList={(new_items) => {
36+
if (
37+
new_items.length !== props.items.length ||
38+
new_items.every((it, index) => it.id == props.items[index].id)
39+
) {
40+
return
41+
}
42+
props.on_reorder(new_items)
43+
}}
3644
className={props.className}
3745
animation={150}
3846
filter="textarea"

0 commit comments

Comments
 (0)