Commit d525ce65 authored by Kai Willadsen's avatar Kai Willadsen

filediff, ui.statusbar: Make go-to-line happen as you type

parent c435c07c
......@@ -230,7 +230,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.set_file(pane, self.textbuffer[pane].data.gfile, encoding)
def go_to_line(widget, line, pane):
self.move_cursor(pane, line)
self.move_cursor(pane, line, focus=False)
pane = self.statusbar.index(statusbar)
statusbar.connect('encoding-changed', reload_with_encoding, pane)
......@@ -706,9 +706,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
return new_line
def move_cursor(self, pane, line):
def move_cursor(self, pane, line, focus=True):
buf, view = self.textbuffer[pane], self.textview[pane]
view.grab_focus()
if focus:
view.grab_focus()
buf.place_cursor(buf.get_iter_at_line(line))
view.scroll_to_mark(buf.get_insert(), 0.1, True, 0.5, 0.5)
......
......@@ -159,6 +159,13 @@ class MeldStatusBar(Gtk.Statusbar):
# Note that we're receiving one-based line numbers from the
# user and storing and emitting zero-base line numbers.
def go_to_line_text(text):
try:
line = int(text)
except ValueError:
return
self.emit('go-to-line', max(0, line - 1))
def line_entry_mapped(entry):
line, offset = self.props.cursor_position
entry.set_text(str(line + 1))
......@@ -168,12 +175,12 @@ class MeldStatusBar(Gtk.Statusbar):
GObject.signal_stop_emission_by_name(entry, 'insert-text')
return
def line_entry_changed(entry):
go_to_line_text(entry.get_text())
def line_entry_activated(entry):
try:
line = int(entry.get_text())
except ValueError:
return
self.emit('go-to-line', max(0, line - 1))
go_to_line_text(entry.get_text())
pop.popdown()
entry = Gtk.Entry()
entry.set_tooltip_text(_('Line you want to move the cursor to'))
......@@ -183,6 +190,7 @@ class MeldStatusBar(Gtk.Statusbar):
entry.set_input_purpose(Gtk.InputPurpose.DIGITS)
entry.connect('map', line_entry_mapped)
entry.connect('insert-text', line_entry_insert_text)
entry.connect('changed', line_entry_changed)
entry.connect('activate', line_entry_activated)
selector = Gtk.Grid()
......
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