Skip to content

Instantly share code, notes, and snippets.

@jaap-karssenberg
Created April 9, 2019 19:13
Show Gist options
  • Save jaap-karssenberg/b40ef92149b86f3e0bc273369f4caa90 to your computer and use it in GitHub Desktop.
Save jaap-karssenberg/b40ef92149b86f3e0bc273369f4caa90 to your computer and use it in GitHub Desktop.
textview_allocation_hack.patch
diff --git a/zim/gui/insertedobjects.py b/zim/gui/insertedobjects.py
index 0d2dbb6d..f15e04c4 100644
--- a/zim/gui/insertedobjects.py
+++ b/zim/gui/insertedobjects.py
@@ -80,15 +80,8 @@ class InsertedObjectWidget(Gtk.EventBox):
window.set_cursor(Gdk.Cursor.new(Gdk.CursorType.ARROW))
def set_textview_wrap_width(self, width):
- if not self.expand:
- return
-
- def callback(width):
- minimum, natural = self._vbox.get_preferred_width()
- width = natural if width == -1 else max(width, minimum)
+ if self.expand:
self.set_size_request(width, -1)
- return False # delete signal
- GObject.idle_add(callback, width)
def has_cursor(self):
'''Returns True if this object has an internal cursor. Will be
diff --git a/zim/gui/pageview.py b/zim/gui/pageview.py
index f07e7f21..3a903254 100644
--- a/zim/gui/pageview.py
+++ b/zim/gui/pageview.py
@@ -18,6 +18,7 @@ L{TextView}.
import logging
from gi.repository import GObject
+from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
@@ -5151,7 +5152,11 @@ class PageView(GSignalEmitterMixin, Gtk.VBox):
self.textview = TextView(preferences=self.preferences)
self.swindow = ScrolledWindow(self.textview)
- self.add(self.swindow)
+ self._hack_hbox = Gtk.HBox()
+ self._hack_hbox.add(self.swindow)
+ self._hack_label = Gtk.Label() # any widget would do I guess
+ self._hack_hbox.pack_end(self._hack_label, False, True, 1)
+ self.add(self._hack_hbox)
self.textview.connect_object('link-clicked', PageView.activate_link, self)
self.textview.connect_object('populate-popup', PageView.do_populate_popup, self)
@@ -5518,6 +5523,20 @@ class PageView(GSignalEmitterMixin, Gtk.VBox):
self._parsetree = tree
self._showing_template = istemplate
+ if self.textview._object_widgets:
+ # Force resize of the scroll window, forcing a redraw to fix
+ # glitch in allocation of embedded obejcts, see isse #642
+ # Will add another timeout to rendering the page, increasing the
+ # priority breaks the hack though. Which shows the glitch is
+ # probably also happening in a drawing or resizing idle event
+ self._hack_label.show_all()
+ def hide_hack():
+ self._hack_label.hide()
+ return False
+ GLib.idle_add(hide_hack)
+ else:
+ self._hack_label.hide()
+
def on_insertedobjecttypemap_changed(self, *a):
self.save_changes()
buffer = self.textview.get_buffer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment