Browse Source

剩余中文输入的问题了

master
hejl 2 months ago
parent
commit
3fa2d5a8cb
  1. 24
      win_text_editor/lib/app/components/text_editor.dart
  2. 2
      win_text_editor/lib/app/core/tab_manager.dart
  3. 23
      win_text_editor/lib/app/core/tab_view.dart
  4. 9
      win_text_editor/lib/app/modules/content_search/content_search_controller.dart
  5. 12
      win_text_editor/lib/app/modules/content_search/search_settings.dart

24
win_text_editor/lib/app/components/text_editor.dart

@ -11,23 +11,33 @@ class TextEditor extends StatefulWidget { @@ -11,23 +11,33 @@ class TextEditor extends StatefulWidget {
final String tabId;
final String? initialContent;
final String title;
final ValueChanged<String>? onContentChanged;
const TextEditor({super.key, required this.tabId, this.initialContent, this.title = '未命名'});
const TextEditor({
super.key,
required this.tabId,
this.initialContent,
this.title = '未命名',
this.onContentChanged,
});
@override
State<TextEditor> createState() => TextEditorState();
}
class TextEditorState extends State<TextEditor> {
class TextEditorState extends State<TextEditor> with AutomaticKeepAliveClientMixin {
final TextEditingController _textController = TextEditingController();
final FocusNode _focusNode = FocusNode();
bool _isLoading = false;
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
_textController.text = widget.initialContent ?? '';
//
_textController.addListener(_handleTextChanged);
}
@override
@ -38,12 +48,15 @@ class TextEditorState extends State<TextEditor> { @@ -38,12 +48,15 @@ class TextEditorState extends State<TextEditor> {
}
}
String getContent() {
return _textController.text;
void _handleTextChanged() {
if (widget.onContentChanged != null) {
widget.onContentChanged!(_textController.text);
}
}
@override
void dispose() {
_textController.removeListener(_handleTextChanged);
_textController.dispose();
_focusNode.dispose();
super.dispose();
@ -51,6 +64,7 @@ class TextEditorState extends State<TextEditor> { @@ -51,6 +64,7 @@ class TextEditorState extends State<TextEditor> {
@override
Widget build(BuildContext context) {
super.build(context);
return Column(
children: [
EditorToolbar(

2
win_text_editor/lib/app/core/tab_manager.dart

@ -63,6 +63,8 @@ class TabManager with ChangeNotifier { @@ -63,6 +63,8 @@ class TabManager with ChangeNotifier {
}
void setActiveTab(String tabId) {
if (_activeTabId == tabId) return; // Tab则不通知
Logger().info('设置活动选项卡: $tabId');
_activeTabId = tabId;
notifyListeners();

23
win_text_editor/lib/app/core/tab_view.dart

@ -54,15 +54,20 @@ class TabView extends StatelessWidget { @@ -54,15 +54,20 @@ class TabView extends StatelessWidget {
}
Widget _buildTabContent(AppTab tab) {
switch (tab.type) {
case 'template_parser':
return TemplateParserView(tabId: tab.id); // 使ID而不是新生成
case 'content_search':
// return const ContentSearchView();
return ContentSearchView(tabId: tab.id); //
default:
return TextEditor(tabId: tab.id, initialContent: tab.content);
}
return IndexedStack(
index: tabs.indexWhere((tab) => tab.id == currentTabId).clamp(0, tabs.length - 1),
children:
tabs.map((tab) {
switch (tab.type) {
case 'template_parser':
return TemplateParserView(tabId: tab.id);
case 'content_search':
return ContentSearchView(tabId: tab.id);
default:
return TextEditor(tabId: tab.id, initialContent: tab.content);
}
}).toList(),
);
}
}

9
win_text_editor/lib/app/modules/content_search/content_search_controller.dart

@ -45,6 +45,13 @@ class ContentSearchController with ChangeNotifier { @@ -45,6 +45,13 @@ class ContentSearchController with ChangeNotifier {
notifyListeners();
}
void setInitialSearchQuery(String query) {
if (_searchQuery != query) {
_searchQuery = query;
notifyListeners();
}
}
// Setters with notifyListeners
set searchQuery(String value) {
if (_searchQuery == value) return;
@ -156,6 +163,8 @@ class ContentSearchController with ChangeNotifier { @@ -156,6 +163,8 @@ class ContentSearchController with ChangeNotifier {
Logger().info("搜索内容不能为空");
return;
}
String first50Chars = searchQuery.length > 50 ? searchQuery.substring(0, 50) : searchQuery;
Logger().debug("搜索内容: $first50Chars");
if (searchDirectory.isEmpty || !Directory(searchDirectory).existsSync()) {
Logger().info("搜索目录不能为空");

12
win_text_editor/lib/app/modules/content_search/search_settings.dart

@ -4,8 +4,6 @@ import 'package:win_text_editor/app/components/text_editor.dart'; @@ -4,8 +4,6 @@ import 'package:win_text_editor/app/components/text_editor.dart';
import 'package:win_text_editor/app/modules/content_search/content_search_controller.dart';
class SearchSettings extends StatelessWidget {
final GlobalKey<TextEditorState> _searchEditorKey = GlobalKey();
SearchSettings({super.key});
@override
@ -23,9 +21,12 @@ class SearchSettings extends StatelessWidget { @@ -23,9 +21,12 @@ class SearchSettings extends StatelessWidget {
width: MediaQuery.of(context).size.width * 0.5,
height: 300,
child: TextEditor(
key: _searchEditorKey,
tabId: 'search_content',
tabId: 'search_content_${controller.hashCode}',
title: '搜索内容[列表以半角逗号分隔]',
initialContent: controller.searchQuery, //
onContentChanged: (content) {
controller.searchQuery = content; //
},
),
),
const SizedBox(width: 8),
@ -194,9 +195,6 @@ class SearchSettings extends StatelessWidget { @@ -194,9 +195,6 @@ class SearchSettings extends StatelessWidget {
icon: const Icon(Icons.search, size: 20),
label: const Text('开始搜索'),
onPressed: () {
//
final content = _searchEditorKey.currentState?.getContent() ?? '';
controller.searchQuery = content;
controller.startSearch();
},
),

Loading…
Cancel
Save