Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: auto calculate the column width when resizing (#7448)
Lucas3bf4f080c526
diff --git a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart b/frontend/appflowy_flutter/lib/plugins/document/document_page.dartindex 83fc24c204..5c695fa508 100644--- a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart@@ -190,9 +190,10 @@ class _DocumentPageState extends State<DocumentPage>),header: buildCoverAndIcon(context, state),initialSelection: initialSelection,- placeholderText: (node) => node.type == ParagraphBlockKeys.type- ? LocaleKeys.editor_slashPlaceHolder.tr()- : '',+ placeholderText: (node) =>+ node.type == ParagraphBlockKeys.type && !node.isInTable+ ? LocaleKeys.editor_slashPlaceHolder.tr()+ : '',),);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dartindex 20bba4f083..d2716fd716 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart@@ -162,13 +162,12 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>editorLaunchUrl = (url) {if (url != null) {- afLaunchUrlString(url);+ afLaunchUrlString(url, addingHttpSchemeWhenFailed: true);}return Future.value(true);};-effectiveScrollController = widget.scrollController ?? ScrollController();// disable the color parse in the HTML decoder.DocumentHTMLDecoder.enableColorParse = false;diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dartindex bf9b1bdc7a..f38d1d7257 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart@@ -1,3 +1,4 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/columns/simple_columns_block_constant.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';import 'package:appflowy_backend/log.dart';import 'package:appflowy_editor/appflowy_editor.dart';@@ -51,17 +52,36 @@ Future<void> dragToMoveNode(final transaction = editorState.transaction;final targetNodeParent = targetNode.parentColumnsBlock;if (targetNodeParent != null) {+ final length = targetNodeParent.children.length;final columnNode = simpleColumnNode(children: [node.deepCopy()],+ width: (node.rect.width * 1 / (length + 1)).clamp(+ SimpleColumnsBlockConstants.minimumColumnWidth,+ double.infinity,+ ),);+ for (final column in targetNodeParent.children) {+ final width =+ column.attributes[SimpleColumnBlockKeys.width]?.toDouble() ??+ SimpleColumnsBlockConstants.minimumColumnWidth;+ transaction.updateNode(column, {+ ...column.attributes,+ SimpleColumnBlockKeys.width: (width * length / (length + 1)).clamp(+ SimpleColumnsBlockConstants.minimumColumnWidth,+ double.infinity,+ ),+ });+ }+transaction.insertNode(targetNode.path.next, columnNode);transaction.deleteNode(node);} else {+ final width = targetNode.rect.width / 2 - 16;final columnsNode = simpleColumnsNode(children: [- simpleColumnNode(children: [targetNode.deepCopy()]),- simpleColumnNode(children: [node.deepCopy()]),+ simpleColumnNode(children: [targetNode.deepCopy()], width: width),+ simpleColumnNode(children: [node.deepCopy()], width: width),],);@@ -82,14 +102,28 @@ Future<void> dragToMoveNode(final targetNodeParent = targetNode.parentColumnsBlock;if (targetNodeParent != null) {// find the previous sibling node of the target node- final width = (node.rect.width /- (targetNode.parentColumnsBlock?.children.length ?? 2)) -- 16;+ final length = targetNodeParent.children.length;final columnNode = simpleColumnNode(children: [node.deepCopy()],- width: width,+ width: (node.rect.width * 1 / (length + 1)).clamp(+ SimpleColumnsBlockConstants.minimumColumnWidth,+ double.infinity,+ ),);+ for (final column in targetNodeParent.children) {+ final width =+ column.attributes[SimpleColumnBlockKeys.width]?.toDouble() ??+ SimpleColumnsBlockConstants.minimumColumnWidth;+ transaction.updateNode(column, {+ ...column.attributes,+ SimpleColumnBlockKeys.width: (width * length / (length + 1)).clamp(+ SimpleColumnsBlockConstants.minimumColumnWidth,+ double.infinity,+ ),+ });+ }+transaction.insertNode(targetNode.path.previous, columnNode);transaction.deleteNode(node);} else {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dartindex 36936f36a9..e818e9437b 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart@@ -235,7 +235,7 @@ class MarkdownTextRobot {List<Node>? children;if (node.children.isNotEmpty) {children = node.children- .map((child) => _styleDelta(node: node, attributes: attributes))+ .map((child) => _styleDelta(node: child, attributes: attributes)).toList();}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_component.dartindex 849d5afd4c..43fd779d33 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_component.dart@@ -88,13 +88,12 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>late final EditorState editorState = context.read<EditorState>();- @override- void initState() {- super.initState();- }+ final ScrollController scrollController = ScrollController();@overridevoid dispose() {+ scrollController.dispose();+super.dispose();}@@ -102,6 +101,7 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>Widget build(BuildContext context) {Widget child = SingleChildScrollView(scrollDirection: Axis.horizontal,+ controller: scrollController,child: Row(crossAxisAlignment: CrossAxisAlignment.stretch,children: _buildChildren(),@@ -111,6 +111,7 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>if (UniversalPlatform.isDesktop) {// only show the scrollbar on desktopchild = Scrollbar(+ controller: scrollController,child: child,);}@@ -149,8 +150,9 @@ class ColumnsBlockComponentState extends State<ColumnsBlockComponent>final children = <Widget>[];for (var i = 0; i < node.children.length; i++) {final childNode = node.children[i];- final width = childNode.attributes[SimpleColumnBlockKeys.width] ??- SimpleColumnsBlockConstants.minimumColumnWidth;+ final width =+ childNode.attributes[SimpleColumnBlockKeys.width]?.toDouble() ??+ SimpleColumnsBlockConstants.minimumColumnWidth;Widget child = editorState.renderer.build(context, childNode);child = SizedBox(diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_constant.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_constant.dartindex 977974a32e..d8820f8613 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_constant.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/columns/simple_columns_block_constant.dart@@ -1,6 +1,6 @@class SimpleColumnsBlockConstants {const SimpleColumnsBlockConstants._();- static const double minimumColumnWidth = 128;+ static const double minimumColumnWidth = 128.0;static const bool enableDebugBorder = false;}