[meld/ui-next] filediff: Bind our statusbar cursor position with an adapter
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/ui-next] filediff: Bind our statusbar cursor position with an adapter
- Date: Sun, 24 Mar 2019 00:03:25 +0000 (UTC)
commit e0639dea0421e1366405281626a2fab4e8e2dfb8
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Mar 24 08:59:22 2019 +1000
filediff: Bind our statusbar cursor position with an adapter
This is being moved partly for consistency with our other statusbar-
displayed properties, but more importantly because we weren't always
setting the cursor position on the statusbar.
The `on_cursor_position_changed()` callback tries not to do a bunch of
recalculation when the cursor doesn't change, but this was biting us on
initial load. If the cursor didn't get moved due to a change being found
(for example, if you're diffing blank files...) then we didn't
initialise the line/column display _at all_ until the cursor changed
again.
meld/filediff.py | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index bbb5ea78..18a4f78d 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -396,6 +396,12 @@ class FileDiff(Gtk.VBox, MeldDoc):
self.set_action_enabled('undo', self.undosequence.can_undo())
for statusbar, buf in zip(self.statusbar, self.textbuffer):
+ buf.bind_property(
+ 'cursor-position', statusbar, 'cursor_position',
+ GObject.BindingFlags.DEFAULT,
+ self.bind_adapt_cursor_position,
+ )
+
buf.bind_property(
'language', statusbar, 'source-language',
GObject.BindingFlags.BIDIRECTIONAL)
@@ -530,6 +536,16 @@ class FileDiff(Gtk.VBox, MeldDoc):
"notify::cursor-position", self.on_cursor_position_changed)
buf.handlers = id0, id1, id2, id3, id4
+ def bind_adapt_cursor_position(self, binding, from_value):
+ buf = binding.get_source()
+ textview = self.textview[self.textbuffer.index(buf)]
+
+ cursor_it = buf.get_iter_at_offset(from_value)
+ offset = textview.get_visual_column(cursor_it)
+ line = cursor_it.get_line()
+
+ return (line, offset)
+
def on_cursor_position_changed(self, buf, pspec, force=False):
pane = self.textbuffer.index(buf)
pos = buf.props.cursor_position
@@ -538,11 +554,8 @@ class FileDiff(Gtk.VBox, MeldDoc):
self.cursor.pane, self.cursor.pos = pane, pos
cursor_it = buf.get_iter_at_offset(pos)
- offset = self.textview[pane].get_visual_column(cursor_it)
line = cursor_it.get_line()
- self.statusbar[pane].props.cursor_position = (line, offset)
-
if line != self.cursor.line or force:
chunk, prev, next_ = self.linediffer.locate_chunk(pane, line)
if chunk != self.cursor.chunk or force:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]