Skip to content

Commit 1b65399

Browse files
committed
feat: Update version to 9.5.0, enhance CHANGELOG and README, and improve code performance and functionality
1 parent 2bc9470 commit 1b65399

8 files changed

Lines changed: 71 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,9 @@ This release establishes **CodeForge** as a powerful, production-ready code edit
367367
## 9.4.0
368368
- FIX: [#57](https://github.com/heckmon/code_forge/issues/57)
369369
- FIX: [#58](https://github.com/heckmon/code_forge/issues/58)
370-
- FIX: Anchored gutter for `controller.setGitDiffDecorations`
370+
- FIX: Anchored gutter for `controller.setGitDiffDecorations`
371+
372+
## 9.5.0
373+
- FIX: [#57](https://github.com/heckmon/code_forge/issues/57)
374+
- FIX: [#58](https://github.com/heckmon/code_forge/issues/58)
375+

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
> code_forge does **not** support Flutter web, as it relies on `dart:io` for core functionality. Use [code_forge_web](https://pub.dev/packages/code_forge_web) for web support.
3939
4040

41-
### What's new in 9.4.0
41+
### What's new in 9.5.0
4242
- FIX: [#57](https://github.com/heckmon/code_forge/issues/57)
4343
- FIX: [#58](https://github.com/heckmon/code_forge/issues/58)
44-
- FIX: Anchored gutter for `controller.setGitDiffDecorations`
4544

4645
## Why CodeForge?
4746
**Feature demos:** [CodeForge Features Showcase](https://heckmon.github.io/code_forge_demo/)
@@ -116,7 +115,7 @@ Add CodeForge to your `pubspec.yaml`:
116115

117116
```yaml
118117
dependencies:
119-
code_forge: ^9.4.0
118+
code_forge: ^9.5.0
120119
```
121120
122121
Then run:

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ packages:
4747
path: ".."
4848
relative: true
4949
source: path
50-
version: "9.2.0"
50+
version: "9.5.0"
5151
collection:
5252
dependency: transitive
5353
description:
@@ -501,5 +501,5 @@ packages:
501501
source: hosted
502502
version: "1.1.0"
503503
sdks:
504-
dart: ">=3.11.3 <4.0.0"
504+
dart: ">=3.11.4 <4.0.0"
505505
flutter: ">=3.35.0"

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ publish_to: 'none'
55
version: 1.0.0+1
66

77
environment:
8-
sdk: ^3.11.3
8+
sdk: ^3.11.4
99

1010
dependencies:
1111
flutter:

lib/code_forge/code_area.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,6 +3918,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
39183918
bool _draggingStartHandle = false, _draggingEndHandle = false;
39193919
bool _showBubble = false, _draggingCHandle = false, _readOnly;
39203920
bool _isDeferringLayout = false, _hasCachedHeight = false;
3921+
bool _isCachedHeightExact = false;
39213922
TextDirection _textDirection;
39223923
Map<int, FoldRange>? _lastLspFoldRanges;
39233924
Rect? _startHandleRect, _endHandleRect, _normalHandle;
@@ -4708,6 +4709,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
47084709
if (_hasCachedHeight) {
47094710
final lineDelta = _cachedLineCount - _previousLineCount;
47104711
_cachedTotalHeight += lineDelta * _lineHeight;
4712+
_isCachedHeightExact = false;
47114713
}
47124714
_previousLineCount = _cachedLineCount;
47134715

@@ -6247,25 +6249,18 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
62476249
visibleHeight += _getWrappedLineHeight(i);
62486250
}
62496251
} else {
6250-
const int exactWrapHeightThreshold = 512;
6251-
if (lineCount <= exactWrapHeightThreshold) {
6252+
final canReuseExactWrappedHeight =
6253+
_hasCachedHeight &&
6254+
_isCachedHeightExact &&
6255+
_previousLineCount == lineCount &&
6256+
_lineHeightCache.length >= lineCount;
6257+
6258+
if (canReuseExactWrappedHeight) {
6259+
visibleHeight = _cachedTotalHeight;
6260+
} else {
62526261
for (int i = 0; i < lineCount; i++) {
62536262
visibleHeight += _getWrappedLineHeight(i);
62546263
}
6255-
} else {
6256-
double cachedHeight = 0;
6257-
int cachedCount = 0;
6258-
for (final entry in _lineHeightCache.entries) {
6259-
if (entry.key < lineCount) {
6260-
cachedHeight += entry.value;
6261-
cachedCount++;
6262-
}
6263-
}
6264-
final uncachedCount = lineCount - cachedCount;
6265-
final avgHeight = cachedCount > 0
6266-
? cachedHeight / cachedCount
6267-
: _lineHeight;
6268-
visibleHeight = cachedHeight + (uncachedCount * avgHeight);
62696264
}
62706265
}
62716266
} else {
@@ -6312,6 +6307,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
63126307
_longLineWidth = maxLineWidth;
63136308
_cachedTotalHeight = visibleHeight;
63146309
_hasCachedHeight = true;
6310+
_isCachedHeightExact = true;
63156311
_previousLineCount = lineCount;
63166312

63176313
final contentHeight =

lib/code_forge/controller.dart

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -813,18 +813,11 @@ class CodeForgeController implements DeltaTextInputClient {
813813
if (suggestions == null || suggestions.isEmpty) return;
814814

815815
final isMobile = Platform.isAndroid || Platform.isIOS;
816-
final selected = isMobile
817-
? suggestions[currentlySelectedSuggestion!]
818-
: suggestions[selectedIndex];
819-
String insertText = '';
820-
821-
if (selected is LspCompletion) {
822-
insertText = selected.label;
823-
} else if (selected is Map) {
824-
insertText = selected['insertText'] ?? selected['label'] ?? '';
825-
} else if (selected is String) {
826-
insertText = selected;
827-
}
816+
final safeSelectedIndex = isMobile
817+
? (currentlySelectedSuggestion ?? 0).clamp(0, suggestions.length - 1)
818+
: selectedIndex.clamp(0, suggestions.length - 1);
819+
final selected = suggestions[safeSelectedIndex];
820+
final insertText = _extractSuggestionText(selected);
828821

829822
if (insertText.isNotEmpty) {
830823
insertAtCurrentCursor(insertText, replaceTypedChar: true);
@@ -834,6 +827,37 @@ class CodeForgeController implements DeltaTextInputClient {
834827
currentlySelectedSuggestion = 0;
835828
}
836829

830+
String _extractSuggestionText(dynamic suggestion) {
831+
if (suggestion is LspCompletion) {
832+
return suggestion.label;
833+
}
834+
if (suggestion is Map) {
835+
final dynamic insertText =
836+
suggestion['insertText'] ??
837+
suggestion['value'] ??
838+
suggestion['label'];
839+
return insertText is String ? insertText : '';
840+
}
841+
if (suggestion is String) {
842+
return suggestion;
843+
}
844+
845+
final dynamic dynamicSuggestion = suggestion;
846+
try {
847+
final dynamic insertText = dynamicSuggestion.insertText;
848+
if (insertText is String && insertText.isNotEmpty) return insertText;
849+
} catch (_) {}
850+
try {
851+
final dynamic value = dynamicSuggestion.value;
852+
if (value is String && value.isNotEmpty) return value;
853+
} catch (_) {}
854+
try {
855+
final dynamic label = dynamicSuggestion.label;
856+
if (label is String) return label;
857+
} catch (_) {}
858+
return '';
859+
}
860+
837861
/// Adds a line decoration to the editor.
838862
///
839863
/// Line decorations can highlight code ranges with background colors,
@@ -2075,7 +2099,7 @@ class CodeForgeController implements DeltaTextInputClient {
20752099
_isMobile &&
20762100
currentlySelectedSuggestion != null) {
20772101
final sugg = suggestionsNotifier.value![currentlySelectedSuggestion!];
2078-
final text = sugg is LspCompletion ? sugg.label : sugg as String;
2102+
final text = _extractSuggestionText(sugg);
20792103
insertAtCurrentCursor(text, replaceTypedChar: true);
20802104
suggestionsNotifier.value = null;
20812105
currentlySelectedSuggestion = null;

lib/code_forge/find_controller.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,20 @@ class FindController extends ChangeNotifier {
291291
void _scrollToCurrentMatch() {
292292
if (_currentMatchIndex >= 0 && _currentMatchIndex < _matches.length) {
293293
final match = _matches[_currentMatchIndex];
294+
final matchLine = _codeController.getLineAtOffset(match.start);
294295
_codeController.setSelectionSilently(
295296
TextSelection(baseOffset: match.start, extentOffset: match.end),
296297
);
297298
_codeController.selectionOnly = true;
298299
_codeController.notifyListeners();
299300

301+
// Ensure find navigation keeps the active result centered in view.
302+
try {
303+
_codeController.scrollToLine(matchLine);
304+
} on StateError {
305+
// Ignore when editor is not attached yet.
306+
}
307+
300308
// removes selection
301309
_codeController.setSelectionSilently(TextSelection.collapsed(offset: 0));
302310
}

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: code_forge
22
description: "A sophisticated code editor package with AI completion, LSP support, syntax highlighting, and advanced editing capabilities."
3-
version: 9.4.0
3+
version: 9.5.0
44
homepage: https://github.com/heckmon/code_forge
55

66
environment:
7-
sdk: ^3.11.3
7+
sdk: ^3.11.4
88
flutter: ">=1.17.0"
99

1010
dependencies:
@@ -14,7 +14,7 @@ dependencies:
1414
re_highlight: ^0.0.3
1515
web_socket_channel: ^3.0.3
1616
flutter_colorpicker: ^1.1.0
17-
vector_math: ^2.1.4
17+
vector_math: ^2.2.0
1818

1919
dev_dependencies:
2020
flutter_test:

0 commit comments

Comments
 (0)