Browse Source

修改显示问题

master
hejl 2 months ago
parent
commit
63de095e70
  1. 22
      win_text_editor/lib/app/app.dart
  2. 17
      win_text_editor/lib/app/providers/editor_provider.dart
  3. 84
      win_text_editor/lib/app/widgets/file_explorer.dart

22
win_text_editor/lib/app/app.dart

@ -57,8 +57,17 @@ class _ResizablePanelState extends State<_ResizablePanel> {
Expanded( Expanded(
child: Row( child: Row(
children: [ children: [
// // - Material小部件包裹
SizedBox(width: leftPanelWidth, child: const FileExplorer()), Material(
elevation: 1, //
child: SizedBox(
width: leftPanelWidth,
child: const ClipRect(
//
child: FileExplorer(),
),
),
),
// //
GestureDetector( GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
@ -75,8 +84,13 @@ class _ResizablePanelState extends State<_ResizablePanel> {
child: Container(width: 4, color: Colors.grey[300]), child: Container(width: 4, color: Colors.grey[300]),
), ),
), ),
// // - Material背景
const Expanded(child: Column(children: [Expanded(child: EditorPane())])), Expanded(
child: Material(
color: Theme.of(context).colorScheme.surface,
child: const Column(children: [Expanded(child: EditorPane())]),
),
),
], ],
), ),
), ),

17
win_text_editor/lib/app/providers/editor_provider.dart

@ -8,6 +8,8 @@ class EditorProvider with ChangeNotifier {
List<EditorTab> get tabs => _tabs; List<EditorTab> get tabs => _tabs;
String? get activeTabId => _activeTabId; String? get activeTabId => _activeTabId;
int _templateTabCounter = 1;
EditorTab? get activeTab { EditorTab? get activeTab {
if (_activeTabId == null) return null; if (_activeTabId == null) return null;
try { try {
@ -20,7 +22,8 @@ class EditorProvider with ChangeNotifier {
void addTab() { void addTab() {
final tabId = DateTime.now().millisecondsSinceEpoch.toString(); 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; _activeTabId = tabId;
notifyListeners(); notifyListeners();
} }
@ -40,12 +43,15 @@ class EditorProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
void updateContent(String tabId, String content) { void updateContent(String tabId, String content, String? name) {
Logger().debug("更新选项卡内容: $tabId, 长度: ${content.length}");
try { try {
final tab = _tabs.firstWhere((t) => t.id == tabId); final tab = _tabs.firstWhere((t) => t.id == tabId);
tab.content = content; tab.content = content;
Logger().debug("内容更新成功,新长度: ${tab.content.length}");
if (name != null) {
tab.fileName = name;
}
Logger().debug("内容更新成功,文件:${tab.fileName}, ${tab.content.length}");
notifyListeners(); notifyListeners();
} catch (e) { } catch (e) {
Logger().error("更新内容失败: ${e.toString()}", source: 'EditorProvider'); Logger().error("更新内容失败: ${e.toString()}", source: 'EditorProvider');
@ -57,6 +63,7 @@ class EditorTab {
final String id; final String id;
String title; String title;
String content; 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});
} }

84
win_text_editor/lib/app/widgets/file_explorer.dart

@ -79,18 +79,9 @@ class _FileExplorerState extends State<FileExplorer> {
Logger().info('没有活动选项卡,创建新选项卡'); Logger().info('没有活动选项卡,创建新选项卡');
editorProvider.addTab(); editorProvider.addTab();
} }
// //
Logger().info('准备更新选项卡内容'); Logger().info('准备更新选项卡内容');
editorProvider.updateContent(editorProvider.activeTabId!, content); editorProvider.updateContent(editorProvider.activeTabId!, content, node.name);
//
final activeTab = editorProvider.activeTab;
if (activeTab != null) {
activeTab.title = node.name;
Logger().debug('更新选项卡标题为: ${node.name}');
editorProvider.notifyListeners();
}
if (context.mounted) { if (context.mounted) {
Logger().debug('已加载: ${node.name}'); Logger().debug('已加载: ${node.name}');
@ -146,44 +137,47 @@ class _FileExplorerState extends State<FileExplorer> {
child: Column( child: Column(
children: [ children: [
Expanded( Expanded(
child: child: ClipRect(
fileProvider.isLoading // ClipRect防止视觉效果溢出
? const Center(child: CircularProgressIndicator()) child:
: fileProvider.fileNodes.isEmpty fileProvider.isLoading
? Center(child: _buildEmptyPrompt(context)) ? const Center(child: CircularProgressIndicator())
: Scrollbar( : fileProvider.fileNodes.isEmpty
// ? Center(child: _buildEmptyPrompt(context))
controller: _verticalScrollController, : Scrollbar(
thumbVisibility: true, //
child: SingleChildScrollView( controller: _verticalScrollController,
// thumbVisibility: true,
scrollDirection: Axis.horizontal, child: SingleChildScrollView(
controller: _horizontalScrollController, //
child: Scrollbar( scrollDirection: Axis.horizontal,
//
controller: _horizontalScrollController, controller: _horizontalScrollController,
thumbVisibility: true, child: Scrollbar(
scrollbarOrientation: ScrollbarOrientation.bottom, // //
child: SizedBox( controller: _horizontalScrollController,
width: calculateTotalWidth(context, fileProvider), // thumbVisibility: true,
child: ListView.builder( scrollbarOrientation: ScrollbarOrientation.bottom,
// child: SizedBox(
controller: _verticalScrollController, width: calculateTotalWidth(context, fileProvider),
itemCount: _countVisibleNodes(fileProvider.fileNodes), child: ListView.builder(
itemBuilder: (context, index) { //
final node = _getVisibleNode(fileProvider.fileNodes, index); controller: _verticalScrollController,
return _FileNodeWidget( itemCount: _countVisibleNodes(fileProvider.fileNodes),
key: ValueKey(node.path), itemBuilder: (context, index) {
node: node, final node = _getVisibleNode(fileProvider.fileNodes, index);
onTap: () => _handleNodeTap(context, node), return _FileNodeWidget(
onDoubleTap: () => _handleNodeDoubleTap(context, node), key: ValueKey(node.path),
); node: node,
}, onTap: () => _handleNodeTap(context, node),
onDoubleTap: () => _handleNodeDoubleTap(context, node),
);
},
),
), ),
), ),
), ),
), ),
), ),
), ),
], ],
), ),
@ -238,7 +232,9 @@ class _FileNodeWidget extends StatelessWidget {
return InkWell( return InkWell(
onTap: onTap, onTap: onTap,
onDoubleTap: onDoubleTap, // onDoubleTap: onDoubleTap,
splashColor: Colors.transparent, //
highlightColor: Colors.grey.withOpacity(0.1), // 使
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 0), padding: const EdgeInsets.symmetric(vertical: 0),
child: ListTile( child: ListTile(

Loading…
Cancel
Save