feat (Editor): Add an option to set the editor font family (#1078)
* feat (Editor): Add an option to set the editor font family Add the `editorFontFamily` property to the settings storage and implement font family selection functionality on editor-related pages. Also, update all pages that use the editor settings to support the newly added font family option. * refactor(editor): Optimize the logic for editor font settings Standardize the method for retrieving font settings on the editor page to avoid redundant calls to the `fetch()` method. Extract the font retrieval logic into variables or anonymous functions to improve code readability and performance.
This commit is contained in:
@@ -5,6 +5,7 @@ extension _Editor on _AppSettingsPageState {
|
||||
return Column(
|
||||
children: [
|
||||
_buildEditorWrap(),
|
||||
_buildEditorFontFamily(),
|
||||
_buildEditorFontSize(),
|
||||
_buildEditorTheme(),
|
||||
_buildEditorDarkTheme(),
|
||||
@@ -96,6 +97,43 @@ extension _Editor on _AppSettingsPageState {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEditorFontFamily() {
|
||||
return ListTile(
|
||||
leading: const Icon(MingCute.font_fill),
|
||||
title: Text(libL10n.font),
|
||||
trailing: ValBuilder(
|
||||
listenable: _setting.editorFontFamily.listenable(),
|
||||
builder: (val) => Text(
|
||||
val.isEmpty ? libL10n.auto.toLowerCase() : val,
|
||||
style: UIs.text15,
|
||||
),
|
||||
),
|
||||
onTap: () => _showFontFamilyDialog(_setting.editorFontFamily),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFontFamilyDialog(HiveProp<String> property) {
|
||||
final ctrl = TextEditingController(text: property.fetch());
|
||||
void onSave() {
|
||||
context.pop();
|
||||
property.put(ctrl.text.trim());
|
||||
}
|
||||
|
||||
context.showRoundDialog(
|
||||
title: libL10n.font,
|
||||
child: Input(
|
||||
controller: ctrl,
|
||||
autoFocus: true,
|
||||
type: TextInputType.text,
|
||||
icon: Icons.font_download,
|
||||
hint: 'monospace / Consolas / Fira Code ...',
|
||||
suggestion: false,
|
||||
onSubmitted: (_) => onSave(),
|
||||
),
|
||||
actions: Btn.ok(onTap: onSave).toList,
|
||||
);
|
||||
}
|
||||
|
||||
void _showFontSizeDialog(HiveProp<double> property) {
|
||||
final ctrl = TextEditingController(text: property.fetch().toString());
|
||||
void onSave() {
|
||||
|
||||
Reference in New Issue
Block a user