# Qt migration and other upgrades

This migration was a surprisingly large amount of work.

But upgrade (mostly?) complete.

The latest Peeknext (Build 221) is now running Qt 6.12 with a custom Scintilla based on 5.5.8.

This also pushed the minimum required macOS version to 14.4, up from 13.2.
At least for now.
I hope that doesn't break things for too many people.

It took a while to port all the custom Scintilla changes, but no major blockers.

I also rewrote the Scintilla wrapper and Python bindings, which required minor changes to all Peeknext lexers but nothing significant.
One benefit is that Peeknext can now use Lexilla as a fallback, so there's basic support for many more programming languages out of the box.

The custom Peeknext lexers are still more polished and offer a better editing experience, particularly for syntax-aware folding and navigation.
I've added a *Lexilla* label to distinguish languages using the fallback lexers in the [Roadmap](/#roadmap).

The lexer implementation itself is also simpler now, which should make the custom lexers easier to maintain and extend.

### Rendering improvements

There have also been quite a few other changes during the upgrade.

#### Outer fold guides

Previously, this was essentially a column 0 indent guide, mostly to keep some visible separation between the text and margin.
It now follows foldable code blocks instead.
Same idea, applied slightly differently.

#### Smooth scrolling

Smooth pixel-based scrolling remains the largest modification to Scintilla's source.

It works mostly the same as before, but I've made some adjustments to momentum and decay.
Scrolling should feel a bit smoother and more predictable.

#### Line numbers and margins

Ported the line number margin changes, including fold symbols and Git change markers, directly into Scintilla.

Previously, parts of this were handled separately.
Keeping them inside Scintilla should simplify rendering and avoid some unnecessary synchronization.

#### Carets and selections

Extended carets and the selection outline are now properly implemented in Scintilla as well.
Finally.

This should make them much more reliable, particularly with multiple panes and windows.
No more overlay clipping, or at least significantly less of it.

The scrollbar and minimap remain in Python for now, as I'm still refining their behavior.

### Migration issues

A few issues encountered along the way, for your entertainment.

#### Threading stopped working

Queued method calls and thread shutdown stopped working.
Completely.

Not fun.

This took some time to investigate because the failures weren't particularly obvious, and several unrelated parts of the application depend on these mechanisms.

#### Syntax highlighting timing changed

Upstream Scintilla appears to be stricter about idle colourising.
When opening a file, syntax highlighting now sometimes happens slightly later than before.

This caused issues with autocomplete and file outline styling, both of which depend on information from the lexer.

Basically had to reorder parts of the indexing and painting sequence to account for this.

#### Painting became extremely slow

After porting the outer fold guides, typing near the end of a file containing a million lines or more became practically impossible.

This turned out to be caused by an unnecessary, and almost offensive, number of parent fold lookups during painting.

#### Document handling became confused

I also made some changes to the document manager, the component responsible for tracking open documents and keeping multiple views synchronized.

This introduced some interesting problems with drag and drop between windows.

Moving an unsaved file from one window to another worked, sort of.
The file correctly moved without triggering a save prompt, but somehow arrived in a saved state in the new window.
Not sure where it supposedly saved itself in between.

The Buffer Explorer also initially refused to accept files dropped into the buffer list, and at one point started repainting itself endlessly.

All fixed now, hopefully.

### Final thoughts

Maintaining a custom Scintilla fork is a bit of a tradeoff.
I get to make changes directly to the editing engine, particularly around scrolling, rendering, and document handling.

But every upstream upgrade means carrying those changes forward again.

This migration was probably the largest one so far.
At least the new wrapper and bindings should make the next one easier.
We’ll see.

