Hi, I'm building a code-editor (to support syntax ...
# compose
d
Hi, I'm building a code-editor (to support syntax colouring, code completion etc.). see [https://github.com/dhakehurst/net.akehurst.kotlin.compose.code-editor] I want to use 2 BasicTextField components, perfectly overlapping. Top one, transparent, to contain whole text and used as input. Bottom one to display, coloured text (annotated), for just the lines that are visible (to improve performance). I have come across several issues, and I wondered if there are know workarounds: 1. No access to the build in text scrolling. I need to know which lines of text are visible and update when ever text is scrolled. I found this code editor (https://github.com/n34t0/compose-code-editor), where the author duplicates much of the CoreTextField code and surrounding other code. just to add an 'onScroll'. I have done similar, but I want to know if there is a better/official/public way to react to scrolling in a text field. (adding a second scroller around the outside would not work I think). 2. Seems to be a bug in MultiParagraph.getLineForVerticalPosition I had to copy and rewrite its code. 3. Also seems to be bugs in MultiParagraph code when executed on Javascript platform. To do with lineMetrics inside
SkiaParagraph
. I'm accessing it via the TextLayoutResult passed into my onScroll function that is called from the
textFieldScroll.textLayoutResultProvider
argument inside my copy of
CoreTextField
. (Note: to others, very useful to add
@file:Suppress("UNUSED", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "EQUALS_MISSING")
at the top of classes you copy, allows them to access internal other classed they use, saves you having to clone masses of stuff.) Does anyone else know of these bugs or know workarounds. or any other thoughts ? many thanks
z
• BasicTextField2 gives you access to internal scrolling. • What’s the getLineForVerticalPosition bug? Please file
d
Hi @Zach Klippenstein (he/him) [MOD], thanks for the tip re BasicTextField2. It allows one to pass in and access a scrollState, which is great. How do I hook into doing something when the TextField is scrolled. I.e. I was expecting an 'onScroll' lambda argument or something similar. ?
also I get this error "Compose Multiplatform doesn't support BasicTextField2 yet" which kind of defeats me totally. 😉 any idea when it will be supported?
z
Scroll state is snapshot state, you observe it the same as any other state in compose
👍 1
I don’t know when non-Android platforms will support it unfortunately
b
damn just hit this too 😢 time to see if I can expect/actual something to keep things sane