Thanks for taking the time to do this! I think the idea is good, but I
feel like this can be simpler. Because we're using GtkSourceView (and
not just plain GtkTextView), we have the
GtkSource.View.get_visual_column() API, which I think does what you
want.

Also, I don't personally see the value in showing both the
expanded-tab and the actual character offset. I checked several other
text editors, and all the ones I looked at showed only the visual
column (i.e., with tabs expanded). This would also neatly avoid the
translation issue you pointed out, since the string doesn't need to
change.

cheers,
Kai

On 10 April 2017 at 08:31, Simon Marchi <[email protected]> wrote:
> This patch adds to the filediff status bar the offset in the current
> line, considering the tab width.  Currently, the offset considers only
> one column for a tab.  The offset with expanded tabs computes how many
> columns each really takes.  For example, with a tab width of 8 and the
> cursor at the end of this line:
>
> <tab><tab>hello
>
> the offset with expanded tabs will be of 22.  The two tabs account for
> 16, "hello" for 5, but since the offset is 1-based, the total is 22.
>
> If the line is:
>
> hello<tab>
>
> the offset with expanded tabs will be of 9.
>
> I would need help with the translations though.  I have updated en_CA
> (the one I'm using), but I think they all need to be updated as well to
> add the additional %i somewhere.  Otherwise, the number of format
> specifiers in the format strings will not match the number of passed
> values, and Python will complain.
> ---
>  meld/filediff.py | 26 ++++++++++++++++++++++++--
>  po/en_CA.po      |  4 ++--
>  2 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/meld/filediff.py b/meld/filediff.py
> index 12a5678c..ef8af6ef 100644
> --- a/meld/filediff.py
> +++ b/meld/filediff.py
> @@ -74,6 +74,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
>
>      __gsettings_bindings__ = (
>          ('ignore-blank-lines', 'ignore-blank-lines'),
> +        ('indent-width', 'tab-width'),
>      )
>
>      ignore_blank_lines = GObject.property(
> @@ -83,6 +84,13 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
>          default=False,
>      )
>
> +    tab_width = GObject.property(
> +        type=int,
> +        nick="Tab width",
> +        blurb="Width of a tab character",
> +        default=8,
> +    )
> +
>      differ = Differ
>
>      keylookup = {
> @@ -310,7 +318,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
>      # Abbreviations for insert and overwrite that fit in the status bar
>      _insert_overwrite_text = (_("INS"), _("OVR"))
>      # Abbreviation for line, column so that it will fit in the status bar
> -    _line_column_text = _("Ln %i, Col %i")
> +    _line_column_text = _("Ln %i, Col %i (%i)")
>
>      def on_cursor_position_changed(self, buf, pspec, force=False):
>          pane = self.textbuffer.index(buf)
> @@ -323,8 +331,22 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
>          offset = cursor_it.get_line_offset()
>          line = cursor_it.get_line()
>
> +        tab_width = self.props.tab_width
> +        offset_tabs_expanded = 0
> +
> +        # Compute the offset with tabs expanded
> +        cursor_it.backward_chars(offset)
> +        for i in range(offset):
> +            if cursor_it.get_char() == '\t':
> +                offset_tabs_expanded += tab_width
> +                offset_tabs_expanded -= offset_tabs_expanded % tab_width
> +            else:
> +                offset_tabs_expanded += 1
> +
> +            cursor_it.forward_char()
> +
>          insert_overwrite = 
> self._insert_overwrite_text[self.textview_overwrite]
> -        line_column = self._line_column_text % (line + 1, offset + 1)
> +        line_column = self._line_column_text % (line + 1, offset + 1, 
> offset_tabs_expanded + 1)
>          self.status_info_labels[0].set_text(insert_overwrite)
>          self.status_info_labels[1].set_text(line_column)
>
> diff --git a/po/en_CA.po b/po/en_CA.po
> index 6327ded1..c7e8e6ac 100644
> --- a/po/en_CA.po
> +++ b/po/en_CA.po
> @@ -151,8 +151,8 @@ msgstr "INS,OVR"
>  #. Abbreviation for line, column so that it will fit in the status bar
>  #: filediff.py:216
>  #, python-format
> -msgid "Ln %i, Col %i"
> -msgstr "Ln %i, Col %i"
> +msgid "Ln %i, Col %i (%i)"
> +msgstr "Ln %i, Col %i (%i)"
>
>  #: filediff.py:274
>  #, python-format
> --
> 2.12.2
>
> _______________________________________________
> meld-list mailing list
> [email protected]
> https://mail.gnome.org/mailman/listinfo/meld-list
_______________________________________________
meld-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/meld-list

Reply via email to