geany-plugins icon indicating copy to clipboard operation
geany-plugins copied to clipboard

Markdown: Update using known GeanyDocument when available

Open codebrainz opened this issue 4 years ago • 4 comments

For whatever reason, in some cases document_get_current() doesn't return a valid document when it seems like it should, so when updating the markdown preview from signals where the related GeanyDocument is available, use that instead of calling document_get_current().

In other cases, continue to use document_get_current() as before.

Closes #1062

codebrainz avatar Feb 09 '21 17:02 codebrainz

Do you have any further information about when/why/how document_get_current() is not returning valid docs? Given its used all through Geany its a bit of a worry if its not right.

elextr avatar Feb 10 '21 02:02 elextr

I do not, I just noticed that it was giving invalid/NULL and that I had a valid document pointer already available. Probably one of the callbacks the plugin uses gets triggered early before the document list is fully initialized or something, but I didn't spend much time trying to understand it.

codebrainz avatar Feb 10 '21 08:02 codebrainz

It can definitely return NULL for lots of reasons, but if it returns a pointer it should be valid since it tests it and returns NULL if not valid.

elextr avatar Feb 10 '21 09:02 elextr

What your change suggests to me is that you'd encounter cases where document_get_current() doesn't return the document for which the signal was fired for. This sounds weird for the activate/new/open/reload/filetype-set signals you're using, and definitely something that should be fixed if it's indeed not in sync (e.g. the signal is fired before the changes that make document_get_current() return the right value happen) -- unless there is an actual reason for that, but still.

I'm sympathetic to the base idea of using the document for which the signal was fired though. But it really seems like it should be strictly equal to document_get_current().

b4n avatar Feb 10 '21 20:02 b4n