Skip to content

Commit d525ce6

Browse files
committed
filediff, ui.statusbar: Make go-to-line happen as you type
1 parent c435c07 commit d525ce6

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

meld/filediff.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def reload_with_encoding(widget, encoding, pane):
230230
self.set_file(pane, self.textbuffer[pane].data.gfile, encoding)
231231

232232
def go_to_line(widget, line, pane):
233-
self.move_cursor(pane, line)
233+
self.move_cursor(pane, line, focus=False)
234234

235235
pane = self.statusbar.index(statusbar)
236236
statusbar.connect('encoding-changed', reload_with_encoding, pane)
@@ -706,9 +706,10 @@ def _corresponding_chunk_line(self, chunk, line, pane, new_pane):
706706

707707
return new_line
708708

709-
def move_cursor(self, pane, line):
709+
def move_cursor(self, pane, line, focus=True):
710710
buf, view = self.textbuffer[pane], self.textview[pane]
711-
view.grab_focus()
711+
if focus:
712+
view.grab_focus()
712713
buf.place_cursor(buf.get_iter_at_line(line))
713714
view.scroll_to_mark(buf.get_insert(), 0.1, True, 0.5, 0.5)
714715

meld/ui/statusbar.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def construct_line_display(self):
159159
# Note that we're receiving one-based line numbers from the
160160
# user and storing and emitting zero-base line numbers.
161161

162+
def go_to_line_text(text):
163+
try:
164+
line = int(text)
165+
except ValueError:
166+
return
167+
self.emit('go-to-line', max(0, line - 1))
168+
162169
def line_entry_mapped(entry):
163170
line, offset = self.props.cursor_position
164171
entry.set_text(str(line + 1))
@@ -168,12 +175,12 @@ def line_entry_insert_text(entry, new_text, length, position):
168175
GObject.signal_stop_emission_by_name(entry, 'insert-text')
169176
return
170177

178+
def line_entry_changed(entry):
179+
go_to_line_text(entry.get_text())
180+
171181
def line_entry_activated(entry):
172-
try:
173-
line = int(entry.get_text())
174-
except ValueError:
175-
return
176-
self.emit('go-to-line', max(0, line - 1))
182+
go_to_line_text(entry.get_text())
183+
pop.popdown()
177184

178185
entry = Gtk.Entry()
179186
entry.set_tooltip_text(_('Line you want to move the cursor to'))
@@ -183,6 +190,7 @@ def line_entry_activated(entry):
183190
entry.set_input_purpose(Gtk.InputPurpose.DIGITS)
184191
entry.connect('map', line_entry_mapped)
185192
entry.connect('insert-text', line_entry_insert_text)
193+
entry.connect('changed', line_entry_changed)
186194
entry.connect('activate', line_entry_activated)
187195

188196
selector = Gtk.Grid()

0 commit comments

Comments
 (0)