so this is what I came up with with an explanation and it even works
lua Code:
local eframe = 0
local oldpos = -1
local oldLinePixels= -1
me2:SetScript("OnUpdate", function(self, elapsed)
eframe = eframe + 1
if eframe < 2 then return end
eframe = 0
local cursorPos = me.CodeFrameEBox:GetCursorPosition()
if oldpos ~= cursorPos then
local pos = cursorPos
local linewidth = me.CodeFrameEBox:GetWidth()
local CRs
local code = { string.split("\n\r",me.CodeFrameEBox:GetText()) }
local ccode = { string.split("\n\r",coloredGetText(me.CodeFrameEBox)) }
local linestring = ""
local line = false
local currentLinePixels = 0
-- Line Numbers section
for x = 1, #code do
StrLen:SetText( code[x]:len() >0 and code[x] or "X")
CRs = math.floor(StrLen:GetStringHeight() / 12)
linestring = linestring..x..":"..string.rep("\r", CRs)
if not(line) and pos - ccode[x]:len() <= 0 then
line = x
elseif not( line ) then
currentLinePixels = currentLinePixels + (CRs * 12)
pos = -1 + pos - (ccode[x] and ccode[x]:len() or 0)
end
end
linestring = string.gsub( linestring, ("%d:"):format(line), ("|cFF00FF00%d:|r"):format(line), 1)
me.LineNumbers:SetText(linestring.."\n\n\nEOF\r")
oldpos = cursorPos
-- line / col section
if pos == 0 then
me.pos:SetText( ("line: %d char: %d"):format(line, 0))
else
local tempString = ccode[line] and ccode[line]:sub(1,pos) or ""
tempString = tempString:gsub("|c%x%x%x%x%x%x%x%x", "")
tempString = tempString:gsub("|r", "")
me.pos:SetText( ("line: %d char: %d"):format(line, tempString:len()))
end
-- scroll frame adjust section
if oldLinePixels ~= currentLinePixels and not( IsMouseButtonDown("LeftButton") ) then
local displayPixels = me.EBoxOverlay:GetHeight() --
local displayTop = me.ScrollFrame:GetVerticalScroll()
local displayBottom = displayTop + displayPixels
local edge = 48
if currentLinePixels > displayTop + edge and currentLinePixels < displayBottom - edge then
-- within viewing window so do nothing
elseif currentLinePixels < displayTop + edge and displayTop > 1 and currentLinePixels < oldLinePixels then
me.ScrollFrame:SetVerticalScroll( currentLinePixels - edge )
elseif currentLinePixels > displayBottom - edge then
me.ScrollFrame:SetVerticalScroll( currentLinePixels - displayPixels + edge)
end
oldLinePixels = currentLinePixels
end
end
end)
the editbox has a fonstring running down the left side of it and they are both attached to the scroll frame.
no messing with history lines for the editbox or any scrollingmessageframe there is a frame overlaying the editbox's visible area with the backdrop set to it so that the backdrop doesn't go scrolling around the screen.
it is in an OnUpdate as the the editing windows just about fills the screen (80% each direction) and it shows no real drop in fps when editing the code. when the cursor position changes in the me.CodeFrameEBox it then pulls both the text formatted by FAIAP and the un-keyword colored text and splits it by lf/cr into a table.
it then does a loop sending the uncolored text to a fontstring set the same width as the editbox, grabs its height and divides by the font height. (I tried just doing it by length of the string but that could not properly predict wordwrap)
it then increments the line number string adding blank lines if the code wraps across lines
it then checks if the cursor position is in the current line by comparing to the colored text
if not it increments the pixel count by the height of the code if it is it sets the line
finished with the loop it changes the current line number on the side to green to distinguish it from the other lines
it sets the line number string
it then takes the position within the colored text sting left from the loop and if it is 0 it knows you are at the start of the string, if not it has to split the string at pos, strip the FAIAP code coloring then get the length of the left over string to figure the position of the cursor in the edit box
then to adjust the scrolling frame by the active line being editied I use the height of the overlay which is set where the "window" of the editbox on the scroll frame is. (there is no predetermined size... all points are relative by screen size)
and yes the mouse check is important as if you don't check for the mouse being down you end up doing all sorts of text selection in the editbox.
figuring out the math for the scroll frame was a bit of a pain but it all works now