#include Once "window9.bi"

Function Lineindexeditor(Byval gadget As Long, Byval NumberLine As Integer=-1) As Integer
	
	Dim As GtkTextBuffer Ptr  buffer
	
	Dim As GtkTextIter  iterindex , iter1, iter2 , itersel1 , itersel2  , iterstarttext, iterendtext
	
	Dim As gint char_offset1
	'
	Dim As gint char_offset2
	
	Dim As gint iLineCount , iLenStr , iLenSelect , iLenAllText
	
	Dim As GtkTextMark Ptr mark
	
	Dim As gint iLine = NumberLine
	
	Dim As Any Ptr edit = Gadgetid(gadget)

	buffer = gtk_text_view_get_buffer(edit)
	
	iLineCount = gtk_text_buffer_get_line_count (buffer)
	
	If NumberLine + 1 > iLineCount Then Return 0
	
	If NumberLine = -1 Then
		
		mark = gtk_text_buffer_get_insert(buffer)
		
		gtk_text_buffer_get_iter_at_mark(buffer , @iter1 , mark)
		
		iLine = gtk_text_iter_get_line(@iter1)
		
	Endif
	
	gtk_text_buffer_get_iter_at_line(buffer , @iter2, iLine)
	
	Return gtk_text_iter_get_offset(@iter2)

End Function