flutter-code-editor
flutter-code-editor copied to clipboard
Draft: Add line wrapping support
This implements the missing "wrap" option in CodeField.
Changes:
- only put code fields into a horizontal scrollview when wrapping is disabled
- calculate line wrap count for each paragraph with a TextPainter when building the CodeField layout, and pass it over to the Gutter so it can skip displaying line numbers for wrapped lines
The second task is tricky. In order to adjust the Gutter correctly, the actual text editor's width needs to be fetched via a LayoutBuilder. Then each line must be rendered in order to compute line metrics. This unfortunately is done for all text lines, so this will get slow with large texts. I also had to substract 3 magic pixels from the width while computing the line metrics, in order to fit the computed vs real drawn output. Not sure where this difference comes from, but it doesn't seem to be affected by the used font or font size.
This does the job for my project, but there might be a better way to do all this. So feel free to merge, ignore, or use this as an inspiration :)
PS: if this isn't merged then the wrap option should be removed from CodeField to avoid confusion, as it right now does nothing.