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> { @@ -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> { @@ -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())]),
),
),
],
),
),

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

@ -8,6 +8,8 @@ class EditorProvider with ChangeNotifier { @@ -8,6 +8,8 @@ class EditorProvider with ChangeNotifier {
List<EditorTab> 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 { @@ -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 { @@ -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 { @@ -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});
}

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

@ -79,18 +79,9 @@ class _FileExplorerState extends State<FileExplorer> { @@ -79,18 +79,9 @@ class _FileExplorerState extends State<FileExplorer> {
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<FileExplorer> { @@ -146,44 +137,47 @@ class _FileExplorerState extends State<FileExplorer> {
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 { @@ -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(

Loading…
Cancel
Save