diff --git a/win_text_editor/lib/app/app.dart b/win_text_editor/lib/app/app.dart index d044354..fe18da7 100644 --- a/win_text_editor/lib/app/app.dart +++ b/win_text_editor/lib/app/app.dart @@ -57,8 +57,17 @@ class _ResizablePanelState extends State<_ResizablePanel> { Expanded( child: Row( children: [ - // 左侧文件资源管理器 - SizedBox(width: leftPanelWidth, child: const FileExplorer()), + // 左侧文件资源管理器 - 添加Material小部件包裹 + Material( + elevation: 1, // 轻微阴影分隔 + child: SizedBox( + width: leftPanelWidth, + child: const ClipRect( + // 确保内容被裁剪 + child: FileExplorer(), + ), + ), + ), // 拖拽手柄 GestureDetector( behavior: HitTestBehavior.translucent, @@ -75,8 +84,13 @@ class _ResizablePanelState extends State<_ResizablePanel> { child: Container(width: 4, color: Colors.grey[300]), ), ), - // 右侧编辑器区域 - const Expanded(child: Column(children: [Expanded(child: EditorPane())])), + // 右侧编辑器区域 - 添加Material背景 + Expanded( + child: Material( + color: Theme.of(context).colorScheme.surface, + child: const Column(children: [Expanded(child: EditorPane())]), + ), + ), ], ), ), diff --git a/win_text_editor/lib/app/providers/editor_provider.dart b/win_text_editor/lib/app/providers/editor_provider.dart index 00bb593..7488489 100644 --- a/win_text_editor/lib/app/providers/editor_provider.dart +++ b/win_text_editor/lib/app/providers/editor_provider.dart @@ -8,6 +8,8 @@ class EditorProvider with ChangeNotifier { List get tabs => _tabs; String? get activeTabId => _activeTabId; + int _templateTabCounter = 1; + EditorTab? get activeTab { if (_activeTabId == null) return null; try { @@ -20,7 +22,8 @@ class EditorProvider with ChangeNotifier { void addTab() { final tabId = DateTime.now().millisecondsSinceEpoch.toString(); - _tabs.add(EditorTab(id: tabId, title: '文档 ${_tabs.length + 1}', content: '')); + _tabs.add(EditorTab(id: tabId, title: '模板解析[$_templateTabCounter]', content: '')); + _templateTabCounter++; _activeTabId = tabId; notifyListeners(); } @@ -40,12 +43,15 @@ class EditorProvider with ChangeNotifier { notifyListeners(); } - void updateContent(String tabId, String content) { - Logger().debug("更新选项卡内容: $tabId, 长度: ${content.length}"); + void updateContent(String tabId, String content, String? name) { try { final tab = _tabs.firstWhere((t) => t.id == tabId); tab.content = content; - Logger().debug("内容更新成功,新长度: ${tab.content.length}"); + + if (name != null) { + tab.fileName = name; + } + Logger().debug("内容更新成功,文件:${tab.fileName}, ${tab.content.length}"); notifyListeners(); } catch (e) { Logger().error("更新内容失败: ${e.toString()}", source: 'EditorProvider'); @@ -57,6 +63,7 @@ class EditorTab { final String id; String title; String content; + String? fileName; - EditorTab({required this.id, required this.title, required this.content}); + EditorTab({required this.id, required this.title, required this.content, this.fileName}); } diff --git a/win_text_editor/lib/app/widgets/file_explorer.dart b/win_text_editor/lib/app/widgets/file_explorer.dart index 8a7966e..14fa021 100644 --- a/win_text_editor/lib/app/widgets/file_explorer.dart +++ b/win_text_editor/lib/app/widgets/file_explorer.dart @@ -79,18 +79,9 @@ class _FileExplorerState extends State { Logger().info('没有活动选项卡,创建新选项卡'); editorProvider.addTab(); } - // 更新内容 Logger().info('准备更新选项卡内容'); - editorProvider.updateContent(editorProvider.activeTabId!, content); - - // 更新标题为文件名 - final activeTab = editorProvider.activeTab; - if (activeTab != null) { - activeTab.title = node.name; - Logger().debug('更新选项卡标题为: ${node.name}'); - editorProvider.notifyListeners(); - } + editorProvider.updateContent(editorProvider.activeTabId!, content, node.name); if (context.mounted) { Logger().debug('已加载: ${node.name}'); @@ -146,44 +137,47 @@ class _FileExplorerState extends State { child: Column( children: [ Expanded( - child: - fileProvider.isLoading - ? const Center(child: CircularProgressIndicator()) - : fileProvider.fileNodes.isEmpty - ? Center(child: _buildEmptyPrompt(context)) - : Scrollbar( - // 外层:垂直滚动条 - controller: _verticalScrollController, - thumbVisibility: true, - child: SingleChildScrollView( - // 中层:水平滚动 - scrollDirection: Axis.horizontal, - controller: _horizontalScrollController, - child: Scrollbar( - // 内层:水平滚动条(横向) + child: ClipRect( + // 添加ClipRect防止视觉效果溢出 + child: + fileProvider.isLoading + ? const Center(child: CircularProgressIndicator()) + : fileProvider.fileNodes.isEmpty + ? Center(child: _buildEmptyPrompt(context)) + : Scrollbar( + // 外层:垂直滚动条 + controller: _verticalScrollController, + thumbVisibility: true, + child: SingleChildScrollView( + // 中层:水平滚动 + scrollDirection: Axis.horizontal, controller: _horizontalScrollController, - thumbVisibility: true, - scrollbarOrientation: ScrollbarOrientation.bottom, // 横向滚动条在底部 - child: SizedBox( - width: calculateTotalWidth(context, fileProvider), // 动态计算总宽度 - child: ListView.builder( - // 内层:垂直列表 - controller: _verticalScrollController, - itemCount: _countVisibleNodes(fileProvider.fileNodes), - itemBuilder: (context, index) { - final node = _getVisibleNode(fileProvider.fileNodes, index); - return _FileNodeWidget( - key: ValueKey(node.path), - node: node, - onTap: () => _handleNodeTap(context, node), - onDoubleTap: () => _handleNodeDoubleTap(context, node), - ); - }, + child: Scrollbar( + // 内层:水平滚动条(横向) + controller: _horizontalScrollController, + thumbVisibility: true, + scrollbarOrientation: ScrollbarOrientation.bottom, + child: SizedBox( + width: calculateTotalWidth(context, fileProvider), + child: ListView.builder( + // 内层:垂直列表 + controller: _verticalScrollController, + itemCount: _countVisibleNodes(fileProvider.fileNodes), + itemBuilder: (context, index) { + final node = _getVisibleNode(fileProvider.fileNodes, index); + return _FileNodeWidget( + key: ValueKey(node.path), + node: node, + onTap: () => _handleNodeTap(context, node), + onDoubleTap: () => _handleNodeDoubleTap(context, node), + ); + }, + ), ), ), ), ), - ), + ), ), ], ), @@ -238,7 +232,9 @@ class _FileNodeWidget extends StatelessWidget { return InkWell( onTap: onTap, - onDoubleTap: onDoubleTap, // 添加双击事件 + onDoubleTap: onDoubleTap, + splashColor: Colors.transparent, // 移除水波纹效果 + highlightColor: Colors.grey.withOpacity(0.1), // 使用更柔和的悬停颜色 child: Container( padding: const EdgeInsets.symmetric(vertical: 0), child: ListTile(