[meld: 1/5] sourceview: Add support for having an overscroll margin
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 1/5] sourceview: Add support for having an overscroll margin
- Date: Sat, 2 Nov 2019 20:14:12 +0000 (UTC)
commit d407933e80ba5409b707a515e4a907de001406d2
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Nov 2 10:34:54 2019 +1000
sourceview: Add support for having an overscroll margin
This makes it a lot easier to deal with the ends of files. It may also
make it slightly easier to show some kind of newline-at-EOF indications
in the future, but for now it's really just to make it possible to
scroll past the last line in the file.
meld/sourceview.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/meld/sourceview.py b/meld/sourceview.py
index f3cca30f..a762018a 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -17,7 +17,7 @@
import logging
from enum import Enum
-from gi.repository import Gdk, Gio, GLib, GObject, Gtk, GtkSource
+from gi.repository import Gdk, Gio, GLib, GObject, Gtk, GtkSource, Pango
from meld.meldbuffer import MeldBuffer
from meld.settings import bind_settings, get_meld_settings, settings
@@ -149,6 +149,15 @@ class MeldSourceView(GtkSource.View, SourceViewHelperMixin):
),
)
+ overscroll_num_lines = GObject.Property(
+ type=int, default=5, minimum=0, maximum=100,
+ nick="Overscroll line count",
+ flags=(
+ GObject.ParamFlags.READWRITE |
+ GObject.ParamFlags.CONSTRUCT
+ ),
+ )
+
replaced_entries = (
# We replace the default GtkSourceView undo mechanism
(Gdk.KEY_z, Gdk.ModifierType.CONTROL_MASK),
@@ -200,6 +209,20 @@ class MeldSourceView(GtkSource.View, SourceViewHelperMixin):
buf.get_tag_table().add(inline_tag)
buf.create_tag("dimmed")
self.set_buffer(buf)
+ self.connect('notify::overscroll-num-lines', self.notify_overscroll)
+
+ @property
+ def line_height(self) -> int:
+ if not getattr(self, '_approx_line_height', None):
+ context = self.get_pango_context()
+ layout = Pango.Layout(context)
+ layout.set_text('X')
+ _width, self._approx_line_height = layout.get_pixel_size()
+
+ return self._approx_line_height
+
+ def notify_overscroll(self, view, param):
+ self.props.bottom_margin = self.overscroll_num_lines * self.line_height
def do_paste_clipboard(self, *args):
# This is an awful hack to replace another awful hack. The idea
@@ -235,6 +258,7 @@ class MeldSourceView(GtkSource.View, SourceViewHelperMixin):
def on_setting_changed(self, settings, key):
if key == 'font':
self.override_font(settings.font)
+ self._approx_line_height = None
elif key == 'style-scheme':
self.highlight_color = colour_lookup_with_fallback(
"meld:current-line-highlight", "background")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]