From 7c5bcba42eef259d40cc68542d9f671201cb5f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D9=8F=D8=AD=D9=8E=D9=85=D9=91=D8=AF=20=D8=B3=D9=90?= =?UTF-8?q?=D9=8A=D9=91=D8=AF?= <94808133+iskepr@users.noreply.github.com> Date: Sat, 25 Apr 2026 18:22:06 +0300 Subject: [PATCH] fix arabic and rtl support --- lib/src/code/reg_exp.dart | 3 ++- lib/src/code_field/code_field.dart | 36 +++++++++++++++++------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/src/code/reg_exp.dart b/lib/src/code/reg_exp.dart index 698ed128..6022caf7 100644 --- a/lib/src/code/reg_exp.dart +++ b/lib/src/code/reg_exp.dart @@ -1,3 +1,4 @@ class RegExps { - static final wordSplit = RegExp('[^_a-zA-Z0-9]+'); + static final wordSplit = + RegExp(r'[^_a-zA-Z0-9\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF]+'); } diff --git a/lib/src/code_field/code_field.dart b/lib/src/code_field/code_field.dart index 8e40fd85..6be14108 100644 --- a/lib/src/code_field/code_field.dart +++ b/lib/src/code_field/code_field.dart @@ -173,6 +173,7 @@ class CodeField extends StatefulWidget { final Color? background; final EdgeInsets padding; final Decoration? decoration; + final TextDirection? textDirection; final TextSelectionThemeData? textSelectionTheme; final FocusNode? focusNode; @@ -196,6 +197,7 @@ class CodeField extends StatefulWidget { this.smartQuotesType = SmartQuotesType.disabled, this.padding = EdgeInsets.zero, GutterStyle? gutterStyle, + this.textDirection, this.enabled, this.readOnly = false, this.cursorColor, @@ -234,7 +236,7 @@ class _CodeFieldState extends State { FocusNode? _focusNode; String? lines; - String longestLine = ''; + var longestLine = ''; Size? windowSize; late TextStyle textStyle; Color? _backgroundCol; @@ -434,6 +436,7 @@ class _CodeFieldState extends State { maxLines: widget.maxLines, expands: widget.expands, scrollController: _codeScroll, + textDirection: widget.textDirection ?? Directionality.of(context), decoration: const InputDecoration( isCollapsed: true, contentPadding: EdgeInsets.symmetric(vertical: 16), @@ -464,17 +467,20 @@ class _CodeFieldState extends State { return FocusableActionDetector( actions: widget.controller.actions, shortcuts: _shortcuts, - child: Container( - decoration: widget.decoration, - color: _backgroundCol, - key: _codeFieldKey, - padding: const EdgeInsets.only(left: 8), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (widget.gutterStyle.showGutter) _buildGutter(), - Expanded(key: _editorKey, child: editingField), - ], + child: Directionality( + textDirection: widget.textDirection ?? Directionality.of(context), + child: Container( + padding: const EdgeInsetsDirectional.only(start: 8), + decoration: widget.decoration, + color: _backgroundCol, + key: _codeFieldKey, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.gutterStyle.showGutter) _buildGutter(), + Expanded(key: _editorKey, child: editingField), + ], + ), ), ), ); @@ -540,11 +546,11 @@ class _CodeFieldState extends State { } double _getCaretHeight(TextPainter textPainter) { - final double? caretFullHeight = textPainter.getFullHeightForCaret( + final double caretFullHeight = textPainter.getFullHeightForCaret( widget.controller.selection.base, Rect.zero, ); - return caretFullHeight ?? 0; + return caretFullHeight; } double _getPopupLeftOffset(TextPainter textPainter) { @@ -603,7 +609,7 @@ class _CodeFieldState extends State { OverlayEntry _buildSearchOverlay() { final colorScheme = Theme.of(context).colorScheme; - final borderColor = _getTextColorFromTheme() ?? colorScheme.onBackground; + final borderColor = _getTextColorFromTheme() ?? colorScheme.onSurface; return OverlayEntry( builder: (context) { return Positioned(