From a853c343312194be75db279d304f87a5e6530d15 Mon Sep 17 00:00:00 2001 From: Daniel Lucraft Date: Sun, 24 Oct 2010 20:08:43 +0100 Subject: [PATCH] Fix the Goto line command. --- CHANGES | 1 + .../redcar/features/goto_line_command.feature | 20 +++++++++++++++++++ plugins/redcar/redcar.rb | 17 ++++++++-------- 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 plugins/redcar/features/goto_line_command.feature diff --git a/CHANGES b/CHANGES index 81c1084bb..8a77d6912 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Bugfixes: * Can load files with multi-byte characters and see them in the tree (Dan Lucraft) * Open in command line now works correctly with Terminal.app (Delisa Mason, Mat Schaffer) * Search-and-replace won't loop forever over a document anymore if it still finds the search string (Tim Felgentreff) + * Goto line command works again (Dan Lucraft) New APIs: * after_save can be implemented by plugins to run code after an edit view was saved (Tim Felgentreff) diff --git a/plugins/redcar/features/goto_line_command.feature b/plugins/redcar/features/goto_line_command.feature new file mode 100644 index 000000000..86c22ad6b --- /dev/null +++ b/plugins/redcar/features/goto_line_command.feature @@ -0,0 +1,20 @@ + +@speedbar +Feature: Goto line command + + Background: + Given I open a new edit tab + + Scenario: Open goto line speedbar + When I replace the contents with "Foo\nBar\nBaz" + And I move the cursor to 0 + And I run the command Redcar::Top::GotoLineCommand + Then the Redcar::Top::GotoLineCommand::Speedbar speedbar should be open + + Scenario: Search for a word should select next occurrence + When I replace the contents with "Foo\nBar\nBaz" + And I move the cursor to 0 + And I run the command Redcar::Top::GotoLineCommand + And I type "2" into the "line" field in the speedbar + And I press "Go" in the speedbar + Then the cursor should be on line 1 diff --git a/plugins/redcar/redcar.rb b/plugins/redcar/redcar.rb index a4744db24..a99f83264 100644 --- a/plugins/redcar/redcar.rb +++ b/plugins/redcar/redcar.rb @@ -660,23 +660,22 @@ class Speedbar < Redcar::Speedbar button :go, "Go", "Return" do new_line_ix = line.value.to_i - 1 - if new_line_ix < doc.line_count and new_line_ix >= 0 - doc.cursor_offset = doc.offset_at_line(new_line_ix) - doc.scroll_to_line(new_line_ix) - win.close_speedbar + if new_line_ix < @doc.line_count and new_line_ix >= 0 + @doc.cursor_offset = @doc.offset_at_line(new_line_ix) + @doc.scroll_to_line(new_line_ix) + @win.close_speedbar end end - def initialize(command) + def initialize(command, win) @command = command + @doc = command.doc + @win = win end - - def doc; @command.doc; end - def win; @command.send(:win); end end def execute - @speedbar = GotoLineCommand::Speedbar.new(self) + @speedbar = GotoLineCommand::Speedbar.new(self, win) win.open_speedbar(@speedbar) end end