Handle tapping when no text yet on this line for checkbox list

pull/13/head
singerdmx 4 years ago
parent 1913136d4f
commit 4f4eea1ef1
  1. 40
      lib/widgets/editor.dart

@ -333,6 +333,10 @@ class _QuillEditorSelectionGestureDetectorBuilder
containerNode.ChildQuery segmentResult = containerNode.ChildQuery segmentResult =
line.queryChild(result.offset, false); line.queryChild(result.offset, false);
if (segmentResult.node == null) { if (segmentResult.node == null) {
if (line.length == 1) {
// tapping when no text yet on this line
_flipListCheckbox(line, segmentResult);
}
return; return;
} }
Leaf segment = segmentResult.node as Leaf; Leaf segment = segmentResult.node as Leaf;
@ -362,25 +366,31 @@ class _QuillEditorSelectionGestureDetectorBuilder
} }
return; return;
} }
if (!getEditor().widget.readOnly && if (_flipListCheckbox(line, segmentResult)) {
segment.parent.style.containsKey(Attribute.list.key) &&
segmentResult.offset == 0) {
// segmentResult.offset == 0 means tap at the beginning of the TextLine
String listVal =
segment.parent.style.attributes[Attribute.list.key].value;
if (listVal == Attribute.unchecked.value) {
segment.parent.style.attributes
.update(Attribute.list.key, (value) => Attribute.checked);
getEditor().widget.controller.notifyChangeListeners();
} else if (listVal == Attribute.checked.value) {
segment.parent.style.attributes
.update(Attribute.list.key, (value) => Attribute.unchecked);
getEditor().widget.controller.notifyChangeListeners();
}
return; return;
} }
} }
bool _flipListCheckbox(Line line, containerNode.ChildQuery segmentResult) {
if (getEditor().widget.readOnly ||
!line.style.containsKey(Attribute.list.key) ||
segmentResult.offset != 0) {
return false;
}
// segmentResult.offset == 0 means tap at the beginning of the TextLine
String listVal = line.style.attributes[Attribute.list.key].value;
if (listVal == Attribute.unchecked.value) {
line.style.attributes
.update(Attribute.list.key, (value) => Attribute.checked);
getEditor().widget.controller.notifyChangeListeners();
} else if (listVal == Attribute.checked.value) {
line.style.attributes
.update(Attribute.list.key, (value) => Attribute.unchecked);
getEditor().widget.controller.notifyChangeListeners();
}
return true;
}
void _launchUrl(String url) async { void _launchUrl(String url) async {
if (!url.startsWith('http')) { if (!url.startsWith('http')) {
url = 'https://$url'; url = 'https://$url';

Loading…
Cancel
Save