There is an issue with how the markdown is rendered in the chat labels. The translation to Gtk Pango markup seems to work correctly, but the text_block class does this in the insert_at_end method:
This makes the text block loose any formatting associated with previously inserted text when new text is inserted.
This can be easily fixed by changing the implementation to this, keeping track of markdown and text state in a member variable:
def insert_at_end(self, text:str, markdown:bool):
self.text += text
self.markdown = self.markdown or markdown
if self.markdown:
self.set_markup(self.text)
else:
self.set_text(self.text)
self.update_property([1], [self.text])
I would have turned this into a pull request but I am not sure that this is what was intended with the original code. Also there is an additional issue. The highlighted chat does not render correctly when the application starts even with the above fix. Presumably this text is rendered through some other code path that I have not been able to track down as gnome builder does not seem to support debugging of python code.
In general the pango formatting seems to behave a bit inconsistently but not to the point where it would be impossible to create a solid solution for markup in the Alpaca chat window.
Pango seems to support apply styling to ranges of text through the GtkTextTag class. It works on the text buffers level instead of the widget level. In general it seems like it might be a good idea to work directly with text buffers instead of widgets given the streaming nature of the application. However I have not looked into this in detail.
I can probably look into this and suggest a solution if you can help me with the following:
How is the markdown rendering intended to work?
How is the document loaded on startup? Can you briefly outline the mechanism and classes involved?
What setup do you use to be able to debug the application?
Please keep in mind that I am new to Gtk and Gnome Builder
There is an issue with how the markdown is rendered in the chat labels. The translation to Gtk Pango markup seems to work correctly, but the
text_block
class does this in theinsert_at_end
method:According to the Gtk documentation
label.get_text()
returns the existing text in the widget stripped of any formatting.The returned text is as it appears on screen. This does not include any embedded underlines indicating mnemonics or Pango markup. https://docs.gtk.org/gtk4/method.Label.get_text.html
This makes the text block loose any formatting associated with previously inserted text when new text is inserted.
This can be easily fixed by changing the implementation to this, keeping track of markdown and text state in a member variable:
I would have turned this into a pull request but I am not sure that this is what was intended with the original code. Also there is an additional issue. The highlighted chat does not render correctly when the application starts even with the above fix. Presumably this text is rendered through some other code path that I have not been able to track down as gnome builder does not seem to support debugging of python code.
In general the pango formatting seems to behave a bit inconsistently but not to the point where it would be impossible to create a solid solution for markup in the Alpaca chat window.
Pango seems to support apply styling to ranges of text through the GtkTextTag class. It works on the text buffers level instead of the widget level. In general it seems like it might be a good idea to work directly with text buffers instead of widgets given the streaming nature of the application. However I have not looked into this in detail.
I can probably look into this and suggest a solution if you can help me with the following:
Please keep in mind that I am new to Gtk and Gnome Builder
Thanks!