Commit 5c82d129 authored by Kai Willadsen's avatar Kai Willadsen

filediff: Add highlight to chunk-based navigation

When the user moves between chunks with next/previous actions, we now
add a fading highlight to indicate the destination chunk, as another
way to help orientate the user in cases of sudden movement.
parent fecf0e63
......@@ -9,7 +9,7 @@
<style name="meld:delete" background="#ffffff" foreground="#880000" line-background="#cccccc"/>
<style name="meld:error" background="#fce94f" foreground="#faad3d" line-background="#fade0a"/>
<style name="meld:inline" background="#8ac2ff"/>
<style name="meld:current-line-highlight" background="#ffff00"/>
<style name="meld:current-line-highlight" foreground="#333333" background="#ffff00"/>
<style name="meld:unknown-text" foreground="#888888"/>
<style name="meld:syncpoint-outline" foreground="#555555"/>
<style name="meld:current-chunk-highlight" background="#rgba(255, 255, 255, 0.5)"/>
......@@ -40,7 +40,8 @@ from meld.matchers.merge import Merger
from meld.patchdialog import PatchDialog
from meld.recent import RecentType
from meld.settings import bind_settings, meldsettings
from meld.sourceview import LanguageManager, get_custom_encoding_candidates
from meld.sourceview import (
LanguageManager, TextviewLineAnimationType, get_custom_encoding_candidates)
from meld.ui.findbar import FindBar
......@@ -498,6 +499,16 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
buf.get_insert(), tolerance, True, 0.5, 0.5)
# If we've moved to a valid chunk (or stayed in the first/last chunk)
# then briefly highlight the chunk for better visual orientation.
chunk_start = buf.get_iter_at_line_or_eof(chunk[1])
chunk_end = buf.get_iter_at_line_or_eof(chunk[2])
mark0 = buf.create_mark(None, chunk_start, True)
mark1 = buf.create_mark(None, chunk_end, True)
mark0, mark1, 'focus-highlight', 400000, starting_alpha=0.3,
def on_linkmap_scroll_event(self, linkmap, event):
......@@ -219,6 +219,7 @@ def get_common_theme():
"conflict": lookup("meld:conflict", "background"),
"replace": lookup("meld:replace", "background"),
"error": lookup("meld:error", "background"),
"focus-highlight": lookup("meld:current-line-highlight", "foreground"),
"current-chunk-highlight": lookup(
"meld:current-chunk-highlight", "background")
......@@ -15,6 +15,7 @@
# along with this program. If not, see <>.
import logging
from enum import Enum
from gi.repository import Gdk
from gi.repository import Gio
......@@ -70,17 +71,23 @@ class LanguageManager(object):
return cls.manager.guess_language(None, content_type)
class TextviewLineAnimationType(Enum):
fill = 'fill'
stroke = 'stroke'
class TextviewLineAnimation(object):
__slots__ = ("start_mark", "end_mark", "start_rgba", "end_rgba",
"start_time", "duration")
"start_time", "duration", "anim_type")
def __init__(self, mark0, mark1, rgba0, rgba1, duration):
def __init__(self, mark0, mark1, rgba0, rgba1, duration, anim_type):
self.start_mark = mark0
self.end_mark = mark1
self.start_rgba = rgba0
self.end_rgba = rgba1
self.start_time = GLib.get_monotonic_time()
self.duration = duration
self.anim_type = anim_type
class MeldSourceView(GtkSource.View):
......@@ -164,12 +171,15 @@ class MeldSourceView(GtkSource.View):
def get_line_num_for_y(self, y):
return self.get_line_at_y(y)[0].get_line()
def add_fading_highlight(self, mark0, mark1, colour_name, duration):
def add_fading_highlight(
self, mark0, mark1, colour_name, duration,
anim_type=TextviewLineAnimationType.fill, starting_alpha=1.0):
rgba0 = self.fill_colors[colour_name].copy()
rgba1 = self.fill_colors[colour_name].copy()
rgba0.alpha = 1.0
rgba0.alpha = starting_alpha
rgba1.alpha = 0.0
anim = TextviewLineAnimation(mark0, mark1, rgba0, rgba1, duration)
anim = TextviewLineAnimation(
mark0, mark1, rgba0, rgba1, duration, anim_type)
def on_setting_changed(self, settings, key):
......@@ -274,7 +284,10 @@ class MeldSourceView(GtkSource.View):
context.rectangle(x, ystart - visible.y, width, yend - ystart)
if c.anim_type == TextviewLineAnimationType.stroke:
if current_time <= c.start_time + c.duration:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment