Skip to content

Commit

Permalink
Fix crasher when pressing delete at end of doc
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed Feb 17, 2010
1 parent 662011b commit ae585d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion plugins/edit_view/features/soft_tabs.feature
Expand Up @@ -281,4 +281,13 @@ Feature: Soft and hard tabs
And I replace the contents with "Hi\nHo"
And I move the cursor to 3
And I press the Left key in the edit tab
Then the contents should be "Hi<c>\nHo"
Then the contents should be "Hi<c>\nHo"

Scenario: Shouldn't die if the cursor is at the end of the document
When I open a new edit tab
And tabs are soft, 4 spaces
And I replace the contents with ""
And I move the cursor to 0
And I press the Delete key in the edit tab
Then the cursor should be at 0

8 changes: 7 additions & 1 deletion plugins/edit_view/lib/edit_view/actions/arrow_keys.rb
Expand Up @@ -78,6 +78,7 @@ def self.handle(edit_view, modifiers)
return if (modifiers & %w(Alt Cmd Ctrl)).any?
return if edit_view.document.block_selection_mode?
doc = edit_view.document

if modifiers.include?("Shift")
old_selection_offset = doc.selection_offset
doc.set_selection_range(move_right_offset(edit_view), old_selection_offset)
Expand All @@ -88,7 +89,12 @@ def self.handle(edit_view, modifiers)

def self.move_right_offset(edit_view)
doc = edit_view.document
return doc.length - 1 if doc.cursor_offset == doc.length - 1
[move_right_offset1(edit_view), doc.length].min
end

def self.move_right_offset1(edit_view)
doc = edit_view.document
return doc.length if doc.cursor_offset == doc.length - 1
if edit_view.soft_tabs?
line = doc.get_line(doc.cursor_line)
width = edit_view.tab_width
Expand Down

0 comments on commit ae585d6

Please sign in to comment.