simonkrauter / NiGui

Cross-platform desktop GUI toolkit written in Nim
MIT License
718 stars 50 forks source link

Modify textarea's text #72

Closed madprops closed 4 years ago

madprops commented 4 years ago

Hello, I've been having fun with this library. I'm currently trying to modify specific lines in textarea.text. Basically what I'm doing is prepending some lines wtih tabs to simulate that persistent tab effect on Enter. So far so good, I can get the line by counting characters against cursor position, but when I try to textarea.text = "something" I get the following error:

(dirfun:12443): Gtk-WARNING **: 19:03:49.532: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators

So I'm wondering what would be the correct way to do this. I can't find any method in the NiGui source that might handle this, so not sure if it's already implemented. I tried running the text assignment on a thread, but it complained about GC limiations.

madprops commented 4 years ago

Btw, would be great to have methods to get the current line number, and modify a specific line.

madprops commented 4 years ago

Removing this logic from the textarea change callback fixes the gtk error.

simonkrauter commented 4 years ago

@madprops Can you please post minimal example program to reproduce the error message?

madprops commented 4 years ago

Hmm I replaced the code and made a cli version instead. But basically what I was doing was changing the textarea's content inside the text change event. If I did it from other place the error didn't appear. Probably just some GTK limitation.

simonkrauter commented 4 years ago

Closing as not reproducible.