|
|
|
@ -1,3 +1,5 @@
@@ -1,3 +1,5 @@
|
|
|
|
|
import 'dart:ui'; |
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:provider/provider.dart'; |
|
|
|
|
import 'package:flutter/services.dart'; // 复制功能需要 |
|
|
|
@ -21,6 +23,7 @@ class _TextTabState extends State<TextTab> {
@@ -21,6 +23,7 @@ class _TextTabState extends State<TextTab> {
|
|
|
|
|
late TextEditingController _controller; |
|
|
|
|
late EditorProvider _provider; |
|
|
|
|
late FocusNode _focusNode; |
|
|
|
|
late ScrollController _scrollController; |
|
|
|
|
String _language = 'plaintext'; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@ -29,6 +32,7 @@ class _TextTabState extends State<TextTab> {
@@ -29,6 +32,7 @@ class _TextTabState extends State<TextTab> {
|
|
|
|
|
_provider = Provider.of<EditorProvider>(context, listen: false); |
|
|
|
|
_controller = TextEditingController(text: _getCurrentContent()); |
|
|
|
|
_focusNode = FocusNode(); |
|
|
|
|
_scrollController = ScrollController(); // 添加这行 |
|
|
|
|
_detectLanguage(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -95,6 +99,7 @@ class _TextTabState extends State<TextTab> {
@@ -95,6 +99,7 @@ class _TextTabState extends State<TextTab> {
|
|
|
|
|
void dispose() { |
|
|
|
|
_controller.dispose(); |
|
|
|
|
_focusNode.dispose(); |
|
|
|
|
_scrollController.dispose(); // 添加这行 |
|
|
|
|
super.dispose(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -148,6 +153,7 @@ class _TextTabState extends State<TextTab> {
@@ -148,6 +153,7 @@ class _TextTabState extends State<TextTab> {
|
|
|
|
|
}, |
|
|
|
|
items: |
|
|
|
|
<String>[ |
|
|
|
|
'xml', |
|
|
|
|
'plaintext', |
|
|
|
|
'dart', |
|
|
|
|
'java', |
|
|
|
@ -167,34 +173,44 @@ class _TextTabState extends State<TextTab> {
@@ -167,34 +173,44 @@ class _TextTabState extends State<TextTab> {
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Stack( |
|
|
|
|
children: [ |
|
|
|
|
// 高亮显示的背景文本 |
|
|
|
|
HighlightView( |
|
|
|
|
tab.content, |
|
|
|
|
language: _language, |
|
|
|
|
theme: isDarkMode ? monokaiSublimeTheme : githubTheme, |
|
|
|
|
padding: const EdgeInsets.all(16), |
|
|
|
|
textStyle: const TextStyle(fontFamily: 'monospace', fontSize: 14), |
|
|
|
|
), |
|
|
|
|
// 实际可编辑的TextField |
|
|
|
|
TextField( |
|
|
|
|
controller: _controller, |
|
|
|
|
focusNode: _focusNode, |
|
|
|
|
maxLines: null, |
|
|
|
|
onChanged: (text) => _provider.updateContent(widget.tabId, text), |
|
|
|
|
decoration: const InputDecoration( |
|
|
|
|
border: InputBorder.none, |
|
|
|
|
contentPadding: EdgeInsets.all(16), |
|
|
|
|
), |
|
|
|
|
style: const TextStyle( |
|
|
|
|
fontFamily: 'monospace', |
|
|
|
|
fontSize: 14, |
|
|
|
|
color: Colors.transparent, // 使文本透明,只显示高亮背景 |
|
|
|
|
), |
|
|
|
|
cursorColor: Colors.black, // 光标颜色 |
|
|
|
|
child: ScrollConfiguration( |
|
|
|
|
behavior: ScrollConfiguration.of(context).copyWith( |
|
|
|
|
scrollbars: true, |
|
|
|
|
dragDevices: {PointerDeviceKind.touch, PointerDeviceKind.mouse}, |
|
|
|
|
), |
|
|
|
|
child: SingleChildScrollView( |
|
|
|
|
controller: _scrollController, // 添加滚动控制器 |
|
|
|
|
child: Stack( |
|
|
|
|
children: [ |
|
|
|
|
// 高亮显示的背景文本 |
|
|
|
|
HighlightView( |
|
|
|
|
tab.content, |
|
|
|
|
language: _language, |
|
|
|
|
theme: isDarkMode ? monokaiSublimeTheme : githubTheme, |
|
|
|
|
padding: const EdgeInsets.all(16), |
|
|
|
|
textStyle: const TextStyle(fontFamily: 'monospace', fontSize: 14), |
|
|
|
|
), |
|
|
|
|
// 实际可编辑的TextField |
|
|
|
|
TextField( |
|
|
|
|
controller: _controller, |
|
|
|
|
focusNode: _focusNode, |
|
|
|
|
maxLines: null, |
|
|
|
|
scrollController: _scrollController, // 使用同一个滚动控制器 |
|
|
|
|
onChanged: (text) => _provider.updateContent(widget.tabId, text), |
|
|
|
|
decoration: const InputDecoration( |
|
|
|
|
border: InputBorder.none, |
|
|
|
|
contentPadding: EdgeInsets.all(16), |
|
|
|
|
), |
|
|
|
|
style: const TextStyle( |
|
|
|
|
fontFamily: 'monospace', |
|
|
|
|
fontSize: 14, |
|
|
|
|
color: Colors.transparent, |
|
|
|
|
), |
|
|
|
|
cursorColor: Colors.black, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|