Skip to content

Commit

Permalink
Fix selection
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Dec 15, 2024
1 parent 591f55d commit be13d38
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
15 changes: 5 additions & 10 deletions app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
if (!(current.embedding?.editable ?? true)) return;
final cubit = current.currentIndexCubit;
final renderers = <Renderer<PadElement>>[];
var selection = cubit.state.selection;
final selected = cubit.state.selection?.selected.toList();
final page = current.page;
final oldRenderers = current.renderers;
final elements = event.elements.map((key, value) => MapEntry(
Expand All @@ -218,14 +218,9 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
Renderer.fromInstance(element, current.currentLayer);
renderers.add(newRenderer);
updatedRenderers.add(newRenderer);
var newSelection = selection?.remove(renderer);
if (newSelection != selection && selection != null) {
if (newSelection == null) {
newSelection = Selection.from(newRenderer);
} else {
newSelection.insert(newRenderer);
}
selection = newSelection;
final exists = selected?.remove(renderer);
if (exists == true) {
selected?.add(newRenderer);
}
}
replacedRenderers[renderer] = updatedRenderers;
Expand All @@ -242,7 +237,7 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
return [e];
}).toList(),
));
cubit.changeSelection(selection, false);
cubit.changeSelection(Selection.fromList(selected), false);
_saveState(
emit,
state: current.copyWith(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/dialogs/background/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BackgroundDialog extends StatelessWidget {
tabAlignment: TabAlignment.fill,
tabs: [
(
PhosphorIconsLight.globe,
PhosphorIconsLight.gridFour,
AppLocalizations.of(context).general,
),
(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/selections/properties/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mixin PathPropertySelection<T extends PathProperty> on PropertySelection<T> {
ExactSlider(
header: Text(AppLocalizations.of(context).strokeWidth),
value: property.strokeWidth,
min: 0,
min: 0.1,
max: 70,
defaultValue: 25,
onChangeEnd: (value) => onChanged(
Expand Down
11 changes: 11 additions & 0 deletions app/lib/selections/selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ abstract class Selection<T> {
throw UnsupportedError('Unsupported selection type: $T');
}

static Selection? fromList(List? selected) {
if (selected == null || selected.isEmpty) {
return null;
}
var current = Selection.from(selected.first);
for (final element in selected.sublist(1)) {
current = current.insert(element);
}
return current;
}

String getLocalizedName(BuildContext context);

IconGetter get icon;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/selections/tools/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LabelToolSelection extends ToolSelection<LabelTool> {
return [
...super.buildProperties(context),
ColorField(
value: Color(selected.first.foreground),
value: Color(selected.first.foreground).withAlpha(255),
onChanged: (value) => update(
context,
selected
Expand Down
8 changes: 4 additions & 4 deletions app/lib/selections/tools/shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ShapeToolSelection extends ToolSelection<ShapeTool> {
.toList())),
const SizedBox(height: 50),
ColorField(
value: Color(property.color),
value: Color(property.color).withAlpha(255),
onChanged: (color) => update(
context,
selected
Expand Down Expand Up @@ -237,7 +237,7 @@ class _CircleShapeView extends StatelessWidget {
Widget build(BuildContext context) {
return Column(children: [
ColorField(
value: Color(shape.fillColor),
value: Color(shape.fillColor).withAlpha(255),
title: Text(AppLocalizations.of(context).fill),
leading: const PhosphorIcon(PhosphorIconsLight.paintBucket),
defaultColor: Colors.transparent,
Expand Down Expand Up @@ -269,7 +269,7 @@ class _TriangleShapeView extends StatelessWidget {
Widget build(BuildContext context) {
return Column(children: [
ColorField(
value: Color(shape.fillColor),
value: Color(shape.fillColor).withAlpha(255),
title: Text(AppLocalizations.of(context).fill),
leading: const PhosphorIcon(PhosphorIconsLight.paintBucket),
defaultColor: Colors.transparent,
Expand Down Expand Up @@ -310,7 +310,7 @@ class _RectangleShapeViewState extends State<_RectangleShapeView> {
ColorField(
title: Text(AppLocalizations.of(context).fill),
leading: const PhosphorIcon(PhosphorIconsLight.paintBucket),
value: Color(widget.shape.fillColor),
value: Color(widget.shape.fillColor).withAlpha(255),
defaultColor: Colors.transparent,
onChanged: (color) => widget.onChanged(widget.shape.copyWith(
fillColor:
Expand Down
3 changes: 2 additions & 1 deletion app/lib/selections/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ class _UtilitiesViewState extends State<_UtilitiesView>
const SizedBox(height: 8),
ColorField(
title: Text(AppLocalizations.of(context).color),
value: Color(widget.option.gridColor),
value:
Color(widget.option.gridColor).withAlpha(255),
onChanged: (value) => widget.onToolChanged(
widget.option.copyWith(
gridColor: convertOldColor(
Expand Down
3 changes: 3 additions & 0 deletions metadata/en-US/changelogs/124.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
* Fix stamp don't use unique element ids
* Fix render order when creating multiple elements when baking
* Fix some color fields don't keep alpha value
* FIx color fields preview shows alpha value
* Fix min slider value of stroke width
* Fix selection not working correctly when editing multiple elements
* Show git hash instead of version in web version
* Upgrade to flutter 3.27

Expand Down

0 comments on commit be13d38

Please sign in to comment.