Skip to content

Commit 2bc9470

Browse files
committed
feat: Update version to 9.4.0, enhance CHANGELOG and README, and refactor code for improved performance
1 parent 6fae309 commit 2bc9470

6 files changed

Lines changed: 41 additions & 60 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,9 @@ This release establishes **CodeForge** as a powerful, production-ready code edit
362362

363363
## 9.3.0
364364
- FIX: [#54](https://github.com/heckmon/code_forge/issues/54)
365-
- FEATURE: Multiple highlight grammars for a single editor instance.
365+
- FEATURE: Multiple highlight grammars for a single editor instance.
366+
367+
## 9.4.0
368+
- FIX: [#57](https://github.com/heckmon/code_forge/issues/57)
369+
- FIX: [#58](https://github.com/heckmon/code_forge/issues/58)
370+
- FIX: Anchored gutter for `controller.setGitDiffDecorations`

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
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.3.0
42-
- FIX: [#54](https://github.com/heckmon/code_forge/issues/54)
43-
- FEATURE: Multiple highlight grammars for a single editor instance.
41+
### What's new in 9.4.0
42+
- FIX: [#57](https://github.com/heckmon/code_forge/issues/57)
43+
- FIX: [#58](https://github.com/heckmon/code_forge/issues/58)
44+
- FIX: Anchored gutter for `controller.setGitDiffDecorations`
4445

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

116117
```yaml
117118
dependencies:
118-
code_forge: ^9.3.0
119+
code_forge: ^9.4.0
119120
```
120121
121122
Then run:

example/lib/main.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ class _MyAppState extends State<MyApp> {
3434
return data;
3535
}
3636

37-
@override
38-
void initState() {
39-
super.initState();
40-
}
41-
4237
@override
4338
Widget build(BuildContext context) {
4439
return MaterialApp(

lib/code_forge/code_area.dart

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3983,7 +3983,6 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
39833983
_hasActiveFoldsCache = false;
39843984

39853985
final lineCount = controller.lineCount;
3986-
// Build sorted list directly from fold ranges instead of per-line Set
39873986
final sortedLines = <int>[];
39883987
for (final fold in _foldRanges.values) {
39893988
if (fold != null && fold.isFolded) {
@@ -6248,19 +6247,26 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
62486247
visibleHeight += _getWrappedLineHeight(i);
62496248
}
62506249
} else {
6251-
double cachedHeight = 0;
6252-
int cachedCount = 0;
6253-
for (final entry in _lineHeightCache.entries) {
6254-
if (entry.key < lineCount) {
6255-
cachedHeight += entry.value;
6256-
cachedCount++;
6250+
const int exactWrapHeightThreshold = 512;
6251+
if (lineCount <= exactWrapHeightThreshold) {
6252+
for (int i = 0; i < lineCount; i++) {
6253+
visibleHeight += _getWrappedLineHeight(i);
62576254
}
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);
62586269
}
6259-
final uncachedCount = lineCount - cachedCount;
6260-
final avgHeight = cachedCount > 0
6261-
? cachedHeight / cachedCount
6262-
: _lineHeight;
6263-
visibleHeight = cachedHeight + (uncachedCount * avgHeight);
62646270
}
62656271
} else {
62666272
_wrapWidth = double.infinity;
@@ -7224,38 +7230,10 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
72247230
final errorColor = gutterStyle.errorLineNumberColor;
72257231
final warningColor = gutterStyle.warningLineNumberColor;
72267232

7227-
int firstVisibleLine;
7228-
double firstVisibleLineY;
7229-
7230-
if (!lineWrap && !hasActiveFolds && _virtualRemovedTotalLineCount == 0) {
7231-
firstVisibleLine = (viewTop / _lineHeight).floor().clamp(
7232-
0,
7233-
lineCount - 1,
7234-
);
7235-
firstVisibleLineY = firstVisibleLine * _lineHeight;
7236-
} else {
7237-
double currentY = 0;
7238-
firstVisibleLine = 0;
7239-
firstVisibleLineY = 0;
7240-
final blocks = controller.virtualRemovedBlocks;
7241-
int blockIdx = 0;
7242-
7243-
for (int i = 0; i < lineCount; i++) {
7244-
if (hasActiveFolds && _isLineFolded(i)) continue;
7245-
while (blockIdx < blocks.length &&
7246-
blocks[blockIdx].afterLine == i - 1) {
7247-
currentY += blocks[blockIdx].lineCount * _lineHeight;
7248-
blockIdx++;
7249-
}
7250-
final lineHeight = lineWrap ? _getWrappedLineHeight(i) : _lineHeight;
7251-
if (currentY + lineHeight > viewTop) {
7252-
firstVisibleLine = i;
7253-
firstVisibleLineY = currentY;
7254-
break;
7255-
}
7256-
currentY += lineHeight;
7257-
}
7258-
}
7233+
final firstVisibleLine = _findVisibleLineByYPosition(
7234+
viewTop,
7235+
).clamp(0, lineCount - 1);
7236+
final firstVisibleLineY = _getLineYOffset(firstVisibleLine, hasActiveFolds);
72597237

72607238
_actionBulbRects.clear();
72617239

@@ -8280,6 +8258,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
82808258
}
82818259

82828260
final lineY = _getLineYOffset(lineIndex, hasActiveFolds);
8261+
final visualYOffset = _getTotalVirtualOffset(lineIndex);
82838262

82848263
final colorBoxOffsetStart = _getColorBoxOffsetForLine(
82858264
lineIndex,
@@ -8311,6 +8290,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
83118290
offset.dy +
83128291
(innerPadding?.top ?? 0) +
83138292
lineY +
8293+
visualYOffset +
83148294
box.top -
83158295
vscrollController.offset;
83168296

@@ -8332,6 +8312,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
83328312
offset.dy +
83338313
(innerPadding?.top ?? 0) +
83348314
lineY -
8315+
visualYOffset -
83358316
vscrollController.offset;
83368317

83378318
canvas.drawRect(
@@ -8479,6 +8460,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
84798460
final startCol = start - startLineOffset;
84808461

84818462
final startY = _getLineYOffset(startLine, hasActiveFolds);
8463+
final startVisualYOffset = _getTotalVirtualOffset(startLine);
84828464

84838465
double startX;
84848466
double startYInLine = 0;
@@ -8511,6 +8493,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
85118493
offset.dy +
85128494
(innerPadding?.top ?? 0) +
85138495
startY +
8496+
startVisualYOffset +
85148497
startYInLine -
85158498
vscrollController.offset;
85168499

@@ -8531,6 +8514,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
85318514
final endCol = end - endLineOffset;
85328515

85338516
final endY = _getLineYOffset(endLine, hasActiveFolds);
8517+
final endVisualYOffset = _getTotalVirtualOffset(endLine);
85348518

85358519
double endX;
85368520
double endYInLine = 0;
@@ -8563,6 +8547,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
85638547
offset.dy +
85648548
(innerPadding?.top ?? 0) +
85658549
endY +
8550+
endVisualYOffset +
85668551
endYInLine -
85678552
vscrollController.offset;
85688553

lib/code_forge/syntax_highlighter.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ class SyntaxHighlighter {
372372
final rootStyle = baseTextStyle ?? _resolvedTheme['root'];
373373
final rootColor = rootStyle?.color;
374374

375-
// Preserve grammar styling when it clearly differs from root text style.
376375
if (style.color != null && rootColor != null && style.color != rootColor) {
377376
return true;
378377
}
@@ -683,8 +682,6 @@ class SyntaxHighlighter {
683682
Map<String, TextStyle> _buildResolvedTheme(Map<String, TextStyle> theme) {
684683
final resolved = Map<String, TextStyle>.from(theme);
685684

686-
// XML/HTML grammars commonly emit `tag`; many highlight themes only define
687-
// `selector-tag` or `name`.
688685
if (!resolved.containsKey('tag')) {
689686
final fallbackTagStyle = resolved['selector-tag'] ?? resolved['name'];
690687
if (fallbackTagStyle != null) {
@@ -761,8 +758,6 @@ void _registerLanguageWithAliases(Highlight highlight, Mode language) {
761758
final normalizedName = language.name!.toLowerCase().trim();
762759
highlight.registerLanguage(normalizedName, language);
763760

764-
// Some grammars expose composite names like "HTML, XML" but subLanguage
765-
// lookups request a single token (for example, "xml").
766761
for (final token in normalizedName.split(RegExp(r'[^a-z0-9_+#-]+'))) {
767762
if (token.isNotEmpty) {
768763
highlight.registerLanguage(token, language);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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.3.0
3+
version: 9.4.0
44
homepage: https://github.com/heckmon/code_forge
55

66
environment:

0 commit comments

Comments
 (0)