Skip to content

Commit 4a59108

Browse files
committed
feat: Update version to 9.7.0, enhance CHANGELOG and README, and improve large text handling
1 parent 76ee007 commit 4a59108

5 files changed

Lines changed: 230 additions & 130 deletions

File tree

CHANGELOG.md

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

376376
## 9.6.0
377377
- FIX: [#60](https://github.com/heckmon/code_forge/issues/60)
378-
- FEATURE: Empty `Mode` as default highlight grammar instead of dart grammar as requested in [#59](https://github.com/heckmon/code_forge/discussions/59)
378+
- FEATURE: Empty `Mode` as default highlight grammar instead of dart grammar as requested in [#59](https://github.com/heckmon/code_forge/discussions/59)
379+
380+
## 9.7.0
381+
- Enhanced large text handling.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
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.6.0
42-
- FIX: [#60](https://github.com/heckmon/code_forge/issues/60)
43-
- FEATURE: Empty `Mode` as default highlight grammar instead of dart grammar as requested in [#59](https://github.com/heckmon/code_forge/discussions/59)
41+
### What's new in 9.7.0
42+
- Enhanced large text handling.
4443

4544
## Why CodeForge?
4645
**Feature demos:** [CodeForge Features Showcase](https://heckmon.github.io/code_forge_demo/)

lib/code_forge/code_area.dart

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,7 +3958,12 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
39583958
if (startLine <= 0) {
39593959
_foldRanges.clear();
39603960
} else {
3961-
_foldRanges.removeWhere((key, _) => key >= startLine);
3961+
final maxFoldKey = _foldRanges.keys.isEmpty
3962+
? 0
3963+
: _foldRanges.keys.reduce((a, b) => a > b ? a : b);
3964+
for (int i = startLine; i <= maxFoldKey; i++) {
3965+
_foldRanges.remove(i);
3966+
}
39623967
}
39633968
_foldedLineCacheDirty = true;
39643969
if (enableFolding && controller.lineCount > 10000) {
@@ -4093,11 +4098,7 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
40934098

40944099
_asyncFoldComputationPending = true;
40954100

4096-
final lineCount = controller.lineCount;
4097-
final lines = List<String>.generate(
4098-
lineCount,
4099-
(i) => controller.getLineText(i),
4100-
);
4101+
final lines = List<String>.from(controller.lines);
41014102

41024103
try {
41034104
final computed = await compute(_computeAllFoldsInBackground, {
@@ -4953,18 +4954,13 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
49534954
_cachedLineCount = newLineCount;
49544955

49554956
final startInvalidation = insertionLine > 0 ? insertionLine - 1 : 0;
4956-
_lineTextCache.removeWhere((key, _) => key >= startInvalidation);
4957-
_lineWidthCache.removeWhere((key, _) => key >= startInvalidation);
4958-
_paragraphCache.removeWhere((key, _) => key >= startInvalidation);
4959-
_lineHeightCache.removeWhere((key, _) => key >= startInvalidation);
4960-
_syntaxHighlighter.invalidateLines(
4961-
Set.from(
4962-
List.generate(
4963-
newLineCount - startInvalidation,
4964-
(i) => startInvalidation + i,
4965-
),
4966-
),
4967-
);
4957+
for (int i = startInvalidation; i <= newLineCount; i++) {
4958+
_lineTextCache.remove(i);
4959+
_lineWidthCache.remove(i);
4960+
_paragraphCache.remove(i);
4961+
_lineHeightCache.remove(i);
4962+
}
4963+
_syntaxHighlighter.invalidateRange(startInvalidation, newLineCount);
49684964

49694965
if (enableGutter && gutterStyle.gutterWidth == null) {
49704966
final fontSize = textStyle?.fontSize ?? 14.0;
@@ -6173,9 +6169,14 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
61736169
final lineCount = controller.lineCount;
61746170

61756171
if (lineCount != _cachedLineCount) {
6176-
_lineWidthCache.removeWhere((key, _) => key >= lineCount);
6177-
_lineTextCache.removeWhere((key, _) => key >= lineCount);
6178-
_lineHeightCache.removeWhere((key, _) => key >= lineCount);
6172+
final maxKey = _lineTextCache.keys.isEmpty
6173+
? 0
6174+
: _lineTextCache.keys.reduce((a, b) => a > b ? a : b);
6175+
for (int i = lineCount; i <= maxKey; i++) {
6176+
_lineWidthCache.remove(i);
6177+
_lineTextCache.remove(i);
6178+
_lineHeightCache.remove(i);
6179+
}
61796180
}
61806181

61816182
if (isRTL && !lineWrap) {
@@ -10388,16 +10389,14 @@ class _CodeFieldRenderer extends RenderBox implements MouseTrackerAnnotation {
1038810389
}
1038910390

1039010391
Map<String, int> _offsetToLineChar(int offset) {
10391-
int accum = 0;
10392-
for (int i = 0; i < controller.lineCount; i++) {
10393-
final lineLen = controller.getLineText(i).length;
10394-
if (offset >= accum && offset <= accum + lineLen) {
10395-
return {'line': i, 'character': offset - accum};
10396-
}
10397-
accum += lineLen + 1;
10398-
}
10399-
final last = controller.lineCount - 1;
10400-
return {'line': last, 'character': controller.getLineText(last).length};
10392+
if (offset < 0) return {'line': 0, 'character': 0};
10393+
if (offset >= controller.length) {
10394+
final last = controller.lineCount - 1;
10395+
return {'line': last, 'character': controller.getLineText(last).length};
10396+
}
10397+
final line = controller.getLineAtOffset(offset);
10398+
final startOffset = controller.getLineStartOffset(line);
10399+
return {'line': line, 'character': offset - startOffset};
1040110400
}
1040210401

1040310402
@override

0 commit comments

Comments
 (0)