On windows it is possible to determine the first and last visible line with some afford. (I have posted these functions somewhere in the module tweaks forum)
I looked at that but it doesn't update the first visible line when you scroll up or down.
I'm fine with making a canvas-based codearea if that's whats needed.