2
This commit is contained in:
1 parent
973d4a6020
commit
ce598b2d86
11 files changed
+631
-46
No files matched your search
@@ -108,6 +108,10 @@
|
||||
},
|
||||
"wordWrap": "Word Wrap",
|
||||
"wordWrapSubtitle": "Wrap long lines to fit the editor width",
|
||||
"showLineNumbers": "Show Line Numbers",
|
||||
"showLineNumbersSubtitle": "Display line numbers and code folding markers on the left",
|
||||
"pinLineNumbers": "Pin Line Numbers",
|
||||
"pinLineNumbersSubtitle": "Keep line numbers pinned to the left during horizontal scroll",
|
||||
"virtualKeyboard": "Accessory Keyboard",
|
||||
"virtualKeyboardSubtitle": "Show accessory symbols and shortcuts below the code editor",
|
||||
"editVirtualKeyboardConfig": "Edit Keyboard Config",
|
||||
|
||||
@@ -656,6 +656,30 @@ abstract class AppLocalizations {
|
||||
/// **'长代码行超出边界时自动折行'**
|
||||
String get wordWrapSubtitle;
|
||||
|
||||
/// No description provided for @showLineNumbers.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'显示行号'**
|
||||
String get showLineNumbers;
|
||||
|
||||
/// No description provided for @showLineNumbersSubtitle.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'在代码左侧显示行号与折叠标记'**
|
||||
String get showLineNumbersSubtitle;
|
||||
|
||||
/// No description provided for @pinLineNumbers.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'固定行号'**
|
||||
String get pinLineNumbers;
|
||||
|
||||
/// No description provided for @pinLineNumbersSubtitle.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
/// **'水平滚动代码时行号固定在左侧'**
|
||||
String get pinLineNumbersSubtitle;
|
||||
|
||||
/// No description provided for @virtualKeyboard.
|
||||
///
|
||||
/// In zh, this message translates to:
|
||||
|
||||
@@ -323,6 +323,20 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get wordWrapSubtitle => 'Wrap long lines to fit the editor width';
|
||||
|
||||
@override
|
||||
String get showLineNumbers => 'Show Line Numbers';
|
||||
|
||||
@override
|
||||
String get showLineNumbersSubtitle =>
|
||||
'Display line numbers and code folding markers on the left';
|
||||
|
||||
@override
|
||||
String get pinLineNumbers => 'Pin Line Numbers';
|
||||
|
||||
@override
|
||||
String get pinLineNumbersSubtitle =>
|
||||
'Keep line numbers pinned to the left during horizontal scroll';
|
||||
|
||||
@override
|
||||
String get virtualKeyboard => 'Accessory Keyboard';
|
||||
|
||||
|
||||
@@ -319,6 +319,18 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get wordWrapSubtitle => '长代码行超出边界时自动折行';
|
||||
|
||||
@override
|
||||
String get showLineNumbers => '显示行号';
|
||||
|
||||
@override
|
||||
String get showLineNumbersSubtitle => '在代码左侧显示行号与折叠标记';
|
||||
|
||||
@override
|
||||
String get pinLineNumbers => '固定行号';
|
||||
|
||||
@override
|
||||
String get pinLineNumbersSubtitle => '水平滚动代码时行号固定在左侧';
|
||||
|
||||
@override
|
||||
String get virtualKeyboard => '辅助小键盘';
|
||||
|
||||
|
||||
@@ -108,6 +108,10 @@
|
||||
},
|
||||
"wordWrap": "自动换行",
|
||||
"wordWrapSubtitle": "长代码行超出边界时自动折行",
|
||||
"showLineNumbers": "显示行号",
|
||||
"showLineNumbersSubtitle": "在代码左侧显示行号与折叠标记",
|
||||
"pinLineNumbers": "固定行号",
|
||||
"pinLineNumbersSubtitle": "水平滚动代码时行号固定在左侧",
|
||||
"virtualKeyboard": "辅助小键盘",
|
||||
"virtualKeyboardSubtitle": "在代码编辑区底部显示辅助符号与快捷键",
|
||||
"editVirtualKeyboardConfig": "编辑键盘配置",
|
||||
|
||||
@@ -18,6 +18,8 @@ class SettingsProvider extends ChangeNotifier {
|
||||
static const String _keyEditorFontSize = 'editor_font_size'; //代码字体大小
|
||||
static const String _keyEditorIndentSize = 'editor_indent_size'; //缩进大小
|
||||
static const String _keyWordWrap = 'editor_word_wrap'; //自动换行
|
||||
static const String _keyShowLineNumbers = 'editor_show_line_numbers'; //显示行号
|
||||
static const String _keyPinLineNumbers = 'editor_pin_line_numbers'; //固定行号
|
||||
static const String _keyEnableVirtualKeyboard = 'enable_virtual_keyboard'; //小键盘启用
|
||||
static const String _keyVirtualKeyboardConfig = 'virtual_keyboard_config'; //小键盘配置JSON
|
||||
static const String _keyEditorFont = 'editor_font_family'; //代码字体
|
||||
@@ -47,6 +49,8 @@ class SettingsProvider extends ChangeNotifier {
|
||||
double _fontSize = 14.0;
|
||||
int _indentSize = 4;
|
||||
bool _wordWrap = false;
|
||||
bool _showLineNumbers = true;
|
||||
bool _pinLineNumbers = true;
|
||||
bool _enableVirtualKeyboard = defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS;
|
||||
String _virtualKeyboardConfigJson = VirtualKeyboardConfig.defaultJsonPretty();
|
||||
VirtualKeyboardConfig _virtualKeyboardConfig = VirtualKeyboardConfig.defaultConfiguration();
|
||||
@@ -77,6 +81,8 @@ class SettingsProvider extends ChangeNotifier {
|
||||
double get fontSize => _fontSize;
|
||||
int get indentSize => _indentSize;
|
||||
bool get wordWrap => _wordWrap;
|
||||
bool get showLineNumbers => _showLineNumbers;
|
||||
bool get pinLineNumbers => _pinLineNumbers;
|
||||
bool get enableVirtualKeyboard => _enableVirtualKeyboard;
|
||||
String get virtualKeyboardConfigJson => _virtualKeyboardConfigJson;
|
||||
VirtualKeyboardConfig get virtualKeyboardConfig => _virtualKeyboardConfig;
|
||||
@@ -205,6 +211,16 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_wordWrap = savedWordWrap;
|
||||
}
|
||||
|
||||
final savedShowLineNumbers = prefs.getBool(_keyShowLineNumbers);
|
||||
if (savedShowLineNumbers != null) {
|
||||
_showLineNumbers = savedShowLineNumbers;
|
||||
}
|
||||
|
||||
final savedPinLineNumbers = prefs.getBool(_keyPinLineNumbers);
|
||||
if (savedPinLineNumbers != null) {
|
||||
_pinLineNumbers = savedPinLineNumbers;
|
||||
}
|
||||
|
||||
final savedEnableVirtualKeyboard = prefs.getBool(_keyEnableVirtualKeyboard);
|
||||
if (savedEnableVirtualKeyboard != null) {
|
||||
_enableVirtualKeyboard = savedEnableVirtualKeyboard;
|
||||
@@ -348,6 +364,26 @@ class SettingsProvider extends ChangeNotifier {
|
||||
}catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> setShowLineNumbers(bool show) async {
|
||||
if (_showLineNumbers == show) return;
|
||||
_showLineNumbers = show;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_keyShowLineNumbers, show);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> setPinLineNumbers(bool pin) async {
|
||||
if (_pinLineNumbers == pin) return;
|
||||
_pinLineNumbers = pin;
|
||||
notifyListeners();
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_keyPinLineNumbers, pin);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 编辑区小键盘开关(等价于 `setKeyboardEnabled(KeyboardScope.editor, ...)`)
|
||||
Future<void> setEnableVirtualKeyboard(bool enable) =>
|
||||
setKeyboardEnabled(KeyboardScope.editor, enable);
|
||||
|
||||
@@ -54,6 +54,8 @@ class SettingsView extends StatelessWidget {
|
||||
_buildEditorFontTile(context, provider),
|
||||
_buildIndentSizeTile(context, provider, l10n),
|
||||
_buildWordWrapTile(context, provider, l10n),
|
||||
_buildShowLineNumbersTile(context, provider, l10n),
|
||||
_buildPinLineNumbersTile(context, provider, l10n),
|
||||
_buildVirtualKeyboardTile(context, provider, l10n),
|
||||
_buildVirtualKeyboardConfigTile(context, provider, l10n),
|
||||
|
||||
@@ -754,6 +756,54 @@ class SettingsView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 编辑区:显示行号条目
|
||||
Widget _buildShowLineNumbersTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return SwitchListTile(
|
||||
secondary: Icon(Icons.format_list_numbered, color: theme.colorScheme.primary),
|
||||
title: Text(l10n.showLineNumbers),
|
||||
subtitle: Text(l10n.showLineNumbersSubtitle),
|
||||
value: provider.showLineNumbers,
|
||||
onChanged: (val) => provider.setShowLineNumbers(val),
|
||||
);
|
||||
}
|
||||
|
||||
/// 编辑区:固定行号条目(当显示行号开启时才可调整)
|
||||
Widget _buildPinLineNumbersTile(
|
||||
BuildContext context,
|
||||
SettingsProvider provider,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final isEnabled = provider.showLineNumbers;
|
||||
|
||||
return SwitchListTile(
|
||||
secondary: Icon(
|
||||
Icons.push_pin_outlined,
|
||||
color: isEnabled ? theme.colorScheme.primary : theme.disabledColor,
|
||||
),
|
||||
title: Text(
|
||||
l10n.pinLineNumbers,
|
||||
style: TextStyle(
|
||||
color: isEnabled ? null : theme.disabledColor,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
l10n.pinLineNumbersSubtitle,
|
||||
style: TextStyle(
|
||||
color: isEnabled ? null : theme.disabledColor,
|
||||
),
|
||||
),
|
||||
value: provider.pinLineNumbers,
|
||||
onChanged: isEnabled ? (val) => provider.setPinLineNumbers(val) : null,
|
||||
);
|
||||
}
|
||||
|
||||
/// 编辑区:虚拟小键盘开关条目
|
||||
Widget _buildVirtualKeyboardTile(
|
||||
BuildContext context,
|
||||
|
||||
@@ -420,11 +420,15 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
bool enableVirtualKeyboard = false;
|
||||
VirtualKeyboardConfig? keyboardConfig;
|
||||
AppFontItem activeEditorFont = AppFonts.editorJetBrainsMono;
|
||||
bool showLineNumbers = true;
|
||||
bool pinLineNumbers = true;
|
||||
try {
|
||||
final settings = _getSettingsProvider(context, listen: true);
|
||||
activeTheme = settings.editorTheme;
|
||||
activeFontSize = settings.fontSize;
|
||||
activeWordWrap = settings.wordWrap;
|
||||
showLineNumbers = settings.showLineNumbers;
|
||||
pinLineNumbers = settings.pinLineNumbers;
|
||||
enableVirtualKeyboard = settings.enableVirtualKeyboard;
|
||||
keyboardConfig = settings.virtualKeyboardConfig;
|
||||
activeEditorFont = settings.editorFont;
|
||||
@@ -458,13 +462,16 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
focusNode: _focusNode,
|
||||
scrollController: _scrollController,
|
||||
wordWrap: activeWordWrap,
|
||||
pinLineNumbers: pinLineNumbers,
|
||||
toolbarController: _toolbarController,
|
||||
margin: const EdgeInsets.only(left: 2.0, top: 4.0, right: 8, bottom: 8.0),
|
||||
padding: const EdgeInsets.fromLTRB(6.0, 0.0, 0.0, 0.0),
|
||||
leadingDivider: Container(
|
||||
width: 1.0,
|
||||
color: activeTheme.gutterTextColor.withValues(alpha: 0.25),
|
||||
),
|
||||
leadingDivider: showLineNumbers
|
||||
? Container(
|
||||
width: 1.0,
|
||||
color: activeTheme.gutterTextColor.withValues(alpha: 0.25),
|
||||
)
|
||||
: null,
|
||||
style: CodeEditorStyle(
|
||||
fontSize: displayFontSize,
|
||||
textColor: activeTheme.textColor,
|
||||
@@ -479,37 +486,39 @@ class _CodeEditorWidgetState extends State<CodeEditorWidget> {
|
||||
theme: activeTheme.highlightTheme,
|
||||
),
|
||||
),
|
||||
indicatorBuilder: (context, editingController, chunkController, notifier) {
|
||||
return Row(
|
||||
children: [
|
||||
DefaultCodeLineNumber(
|
||||
controller: editingController,
|
||||
notifier: notifier,
|
||||
textStyle: TextStyle(
|
||||
color: activeTheme.gutterTextColor,
|
||||
fontSize: (displayFontSize - 1).clamp(9.0, 30.0),
|
||||
fontFamily: activeEditorFont.fontFamily,
|
||||
fontFamilyFallback: activeEditorFont.fallback,
|
||||
),
|
||||
focusedTextStyle: TextStyle(
|
||||
color: activeTheme.focusedGutterTextColor,
|
||||
fontSize: (displayFontSize - 1).clamp(9.0, 30.0),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: activeEditorFont.fontFamily,
|
||||
fontFamilyFallback: activeEditorFont.fallback,
|
||||
),
|
||||
),
|
||||
DefaultCodeChunkIndicator(
|
||||
width: 20,
|
||||
controller: chunkController,
|
||||
notifier: notifier,
|
||||
painter: DefaultCodeChunkIndicatorPainter(
|
||||
color: activeTheme.gutterTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
indicatorBuilder: showLineNumbers
|
||||
? (context, editingController, chunkController, notifier) {
|
||||
return Row(
|
||||
children: [
|
||||
DefaultCodeLineNumber(
|
||||
controller: editingController,
|
||||
notifier: notifier,
|
||||
textStyle: TextStyle(
|
||||
color: activeTheme.gutterTextColor,
|
||||
fontSize: (displayFontSize - 1).clamp(9.0, 30.0),
|
||||
fontFamily: activeEditorFont.fontFamily,
|
||||
fontFamilyFallback: activeEditorFont.fallback,
|
||||
),
|
||||
focusedTextStyle: TextStyle(
|
||||
color: activeTheme.focusedGutterTextColor,
|
||||
fontSize: (displayFontSize - 1).clamp(9.0, 30.0),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: activeEditorFont.fontFamily,
|
||||
fontFamilyFallback: activeEditorFont.fallback,
|
||||
),
|
||||
),
|
||||
DefaultCodeChunkIndicator(
|
||||
width: 20,
|
||||
controller: chunkController,
|
||||
notifier: notifier,
|
||||
painter: DefaultCodeChunkIndicatorPainter(
|
||||
color: activeTheme.gutterTextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user