Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing go to line function to highlight the correct lines (corresponding to their line numbers). #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions lios/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,22 +730,20 @@ def close(*data):
window1.show_all()


def go_to_line(self,*data):
current_line = self.get_cursor_line_number()
maximum_line = self.get_line_count()
spinbutton_line = widget.SpinButton(current_line,0,maximum_line,1,5,0)

dlg = dialog.Dialog(_("Go To Line"),(_("Go"), dialog.Dialog.BUTTON_ID_1,_("Close!"), dialog.Dialog.BUTTON_ID_2))
#spinbutton_line.connect("activate",lambda x : dialog.response(Gtk.ResponseType.ACCEPT))
dlg.add_widget_with_label(spinbutton_line,_("Line Number: "))
def go_to_line(self, *data):
current_line = self.count_non_empty_lines()
spinbutton_line = widget.SpinButton(1, 1, current_line, 1, 5, 0)

dlg = dialog.Dialog(_("Go To Line"), (_("Go"), dialog.Dialog.BUTTON_ID_1, _("Close!"), dialog.Dialog.BUTTON_ID_2))
dlg.add_widget_with_label(spinbutton_line, _("Line Number: "))
spinbutton_line.grab_focus()
dlg.show_all()
response = dlg.run()

if response == dialog.Dialog.BUTTON_ID_1:
to = spinbutton_line.get_value()
self.move_cursor_to_line(to)
self.highlights_cursor_line()
to = int(spinbutton_line.get_value())
if self.move_cursor_to_non_empty_line(to):
self.highlights_cursor_line()
dlg.destroy()
else:
dlg.destroy()
Expand Down
37 changes: 31 additions & 6 deletions lios/ui/gtk/text_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,42 @@ def get_current_line_text(self):
start_iter.backward_sentence_start()
end_iter.forward_to_line_end()
return buffer.get_text(start_iter,end_iter,True)

def count_non_empty_lines(self, up_to_line=None):
buffer = self.get_buffer()
count = 0
for line in range(buffer.get_line_count()):
if up_to_line is not None and line > up_to_line:
break
iter = buffer.get_iter_at_line(line)
if not iter.ends_line() or iter.get_char() != '\n':
count += 1
return count
def move_cursor_to_non_empty_line(self, target_line):
buffer = self.get_buffer()
current_non_empty = 0
for line in range(buffer.get_line_count()):
iter = buffer.get_iter_at_line(line)
if not iter.ends_line() or iter.get_char() != '\n':
current_non_empty += 1
if current_non_empty == target_line:
buffer.place_cursor(iter)
self.scroll_to_iter(iter, 0.0, False, 0.0, 0.0)
return True
return False
# For highlighting bookmark position and go-to-line
def highlights_cursor_line(self):
buffer = self.get_buffer()
self.remove_all_highlights()
mark = buffer.get_insert()
start_iter = buffer.get_iter_at_mark(mark)
end_iter = start_iter.copy()
end_iter.forward_to_line_end()
self.scroll_to_iter(start_iter, 0.0,False,0.0,0.0)
buffer.apply_tag(self.highlight_tag, start_iter, end_iter)
iter = buffer.get_iter_at_mark(mark)
line = iter.get_line()

start = buffer.get_iter_at_line(line)
end = start.copy()
end.forward_to_line_end()

self.scroll_to_iter(start, 0.0, False, 0.0, 0.0)
buffer.apply_tag(self.highlight_tag, start, end)

#Find , Find and Replace , Spell check , TextReader

Expand Down