How can I get a line number from GtkTextBuffer based on the current cursor position?
Let us assume that wrap-mode is set and I am in some where in middle of the 3rd line. But how can I get the program to tell me that I am in the 3rd line ?
Getting GtkTextView line number
1.6k Views Asked by user1109856 At
2
You can't, because the text buffer doesn't know how big the user has resized the window. The best you can do is to use
gtk_text_view_get_iter_location()which gives you a rectangle of the pixel coordinates of an iterator.You can divide the y coordinate by the height of the rectangle to estimate the line number, but of course that only works if all your lines are the same height.