mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-09-22 15:07:21 +00:00
feat: auto calculate the column width when resizing (#7448)
* feat: calculate the column width auto * fix: ai writer table issue
This commit is contained in:
parent
637c043f5b
commit
3bf4f080c5
@ -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()
|
||||
: '',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
@override
|
||||
void 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 desktop
|
||||
child = 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(
|
||||
|
@ -1,6 +1,6 @@
|
||||
class SimpleColumnsBlockConstants {
|
||||
const SimpleColumnsBlockConstants._();
|
||||
|
||||
static const double minimumColumnWidth = 128;
|
||||
static const double minimumColumnWidth = 128.0;
|
||||
static const bool enableDebugBorder = false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user