mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: fix checklist potential panic (#5561)
* chore: fix checklist * chore: fix checklist
This commit is contained in:
@ -70,10 +70,11 @@ class _ChecklistItemsState extends State<ChecklistItems> {
|
|||||||
key: ValueKey(task.data.id),
|
key: ValueKey(task.data.id),
|
||||||
task: task,
|
task: task,
|
||||||
autofocus: widget.state.newTask && index == tasks.length - 1,
|
autofocus: widget.state.newTask && index == tasks.length - 1,
|
||||||
onSubmitted: index == tasks.length - 1
|
onSubmitted: () {
|
||||||
? () => widget.bloc
|
if (index == tasks.length - 1) {
|
||||||
.add(const ChecklistCellEvent.createNewTask(""))
|
widget.bloc.add(const ChecklistCellEvent.createNewTask(""));
|
||||||
: null,
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -187,8 +187,12 @@ class _ChecklistItemState extends State<ChecklistItem> {
|
|||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (widget.task.data.name != oldWidget.task.data.name) {
|
if (widget.task.data.name != oldWidget.task.data.name) {
|
||||||
final selection = _textController.selection;
|
final selection = _textController.selection;
|
||||||
_textController.text = widget.task.data.name;
|
// Ensure the selection offset is within the new text bounds
|
||||||
_textController.selection = selection;
|
int offset = selection.start;
|
||||||
|
if (offset > widget.task.data.name.length) {
|
||||||
|
offset = widget.task.data.name.length;
|
||||||
|
}
|
||||||
|
_textController.selection = TextSelection.collapsed(offset: offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +208,20 @@ class _ChecklistItemState extends State<ChecklistItem> {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
_SelectTaskIntent: CallbackAction<_SelectTaskIntent>(
|
_SelectTaskIntent: CallbackAction<_SelectTaskIntent>(
|
||||||
onInvoke: (_SelectTaskIntent intent) => context
|
onInvoke: (_SelectTaskIntent intent) {
|
||||||
|
// Log.debug("checklist widget on enter");
|
||||||
|
context
|
||||||
.read<ChecklistCellBloc>()
|
.read<ChecklistCellBloc>()
|
||||||
.add(ChecklistCellEvent.selectTask(widget.task.data.id)),
|
.add(ChecklistCellEvent.selectTask(widget.task.data.id));
|
||||||
|
return;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
_EndEditingTaskIntent: CallbackAction<_EndEditingTaskIntent>(
|
_EndEditingTaskIntent: CallbackAction<_EndEditingTaskIntent>(
|
||||||
onInvoke: (_EndEditingTaskIntent intent) =>
|
onInvoke: (_EndEditingTaskIntent intent) {
|
||||||
_textFieldFocusNode.unfocus(),
|
// Log.debug("checklist widget on escape");
|
||||||
|
_textFieldFocusNode.unfocus();
|
||||||
|
return;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
shortcuts: {
|
shortcuts: {
|
||||||
@ -278,12 +289,14 @@ class _ChecklistItemState extends State<ChecklistItem> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSubmitted: (description) {
|
onSubmitted: (description) {
|
||||||
_submitUpdateTaskDescription(description);
|
|
||||||
if (widget.onSubmitted != null) {
|
if (widget.onSubmitted != null) {
|
||||||
|
// Log.debug("checklist widget on submitted");
|
||||||
widget.onSubmitted?.call();
|
widget.onSubmitted?.call();
|
||||||
} else {
|
} else {
|
||||||
|
// Log.debug("checklist widget Focus next task");
|
||||||
Actions.invoke(context, const NextFocusIntent());
|
Actions.invoke(context, const NextFocusIntent());
|
||||||
}
|
}
|
||||||
|
_submitUpdateTaskDescription(description);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -454,8 +467,7 @@ class _DeleteTaskButtonState extends State<_DeleteTaskButton> {
|
|||||||
statesController: _materialStatesController,
|
statesController: _materialStatesController,
|
||||||
child: FlowySvg(
|
child: FlowySvg(
|
||||||
FlowySvgs.delete_s,
|
FlowySvgs.delete_s,
|
||||||
color: _materialStatesController.value
|
color: _materialStatesController.value.contains(WidgetState.hovered) ||
|
||||||
.contains(WidgetState.hovered) ||
|
|
||||||
_materialStatesController.value.contains(WidgetState.focused)
|
_materialStatesController.value.contains(WidgetState.focused)
|
||||||
? Theme.of(context).colorScheme.error
|
? Theme.of(context).colorScheme.error
|
||||||
: null,
|
: null,
|
||||||
|
@ -34,7 +34,8 @@ impl TaskQueue {
|
|||||||
match self.index_tasks.entry(task.handler_id.clone()) {
|
match self.index_tasks.entry(task.handler_id.clone()) {
|
||||||
Entry::Occupied(entry) => {
|
Entry::Occupied(entry) => {
|
||||||
let mut list = entry.get().borrow_mut();
|
let mut list = entry.get().borrow_mut();
|
||||||
assert!(list
|
|
||||||
|
debug_assert!(list
|
||||||
.peek()
|
.peek()
|
||||||
.map(|old_id| pending_task.id >= old_id.id)
|
.map(|old_id| pending_task.id >= old_id.id)
|
||||||
.unwrap_or(true));
|
.unwrap_or(true));
|
||||||
|
@ -45,7 +45,7 @@ impl TaskStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn next_task_id(&self) -> TaskId {
|
pub(crate) fn next_task_id(&self) -> TaskId {
|
||||||
let _ = self.task_id_counter.fetch_add(1, SeqCst);
|
let old = self.task_id_counter.fetch_add(1, SeqCst);
|
||||||
self.task_id_counter.load(SeqCst)
|
old + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user