Skip to content

Commit

Permalink
Home command goes to start of text first, then start of line.
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed May 26, 2010
1 parent 07f2d74 commit 5801cd0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -10,6 +10,7 @@ Enhancements:
* Word wrap option (Dan Lucraft)
* Toggle line numbers (Dan Lucraft)
* Can put TM themes and bundles into .redcar/{Bundles,Themes} (Dan Lucraft)
* Home command goes to start of text first then start of line. (Dan Lucraft)

New APIs:

Expand Down
11 changes: 11 additions & 0 deletions ROADMAP.md
Expand Up @@ -28,3 +28,14 @@ And then for 1.0...
* Recently opened files
* more ... ?


Notes on features
=================

Macros
------

* Cursor movement keys are not commands:
- alt left/right
- shift alt left/right
- cmd left/right
53 changes: 47 additions & 6 deletions plugins/redcar/redcar.rb
Expand Up @@ -241,13 +241,35 @@ def execute
class MoveHomeCommand < EditTabCommand

def execute
doc = tab.edit_view.document
doc = tab.edit_view.document
line_ix = doc.line_at_offset(doc.cursor_offset)
doc.cursor_offset = doc.offset_at_line(line_ix)
line = doc.get_line(line_ix)
prefix = line[0...doc.cursor_line_offset]

if prefix =~ /^\s*$/
# move to start of line
new_offset = doc.offset_at_line(line_ix)
else
# move to start of text
new_offset = doc.offset_at_line(line_ix)
prefix =~ /^(\s*)[^\s].*$/
whitespace_prefix_length = $1 ? $1.length : 0
new_offset += whitespace_prefix_length
end
doc.cursor_offset = new_offset
doc.ensure_visible(doc.cursor_offset)
end
end

class MoveTopCommand < EditTabCommand

def execute
doc = tab.edit_view.document
doc.cursor_offset = 0
doc.ensure_visible(0)
end
end

class MoveEndCommand < EditTabCommand

def execute
Expand All @@ -262,6 +284,15 @@ def execute
end
end

class MoveBottomCommand < EditTabCommand

def execute
doc = tab.edit_view.document
doc.cursor_offset = doc.length
doc.ensure_visible(doc.length)
end
end

class ChangeIndentCommand < EditTabCommand
def execute
doc = tab.edit_view.document
Expand Down Expand Up @@ -673,8 +704,12 @@ def self.keymaps
link "Cmd+C", CopyCommand
link "Cmd+V", PasteCommand
link "Cmd+D", DuplicateCommand

link "Home", MoveTopCommand
link "Ctrl+A", MoveHomeCommand
link "Ctrl+E", MoveEndCommand
link "End", MoveBottomCommand

link "Cmd+[", DecreaseIndentCommand
link "Cmd+]", IncreaseIndentCommand
link "Cmd+Shift+I", AutoIndenter::IndentCommand
Expand Down Expand Up @@ -725,8 +760,12 @@ def self.keymaps
link "Ctrl+C", CopyCommand
link "Ctrl+V", PasteCommand
link "Ctrl+D", DuplicateCommand
link "Ctrl+A", MoveHomeCommand
link "Ctrl+E", MoveEndCommand

link "Shift+Home", MoveTopCommand
link "Home", MoveHomeCommand
link "End", MoveEndCommand
link "Shift+End", MoveBottomCommand

link "Ctrl+[", DecreaseIndentCommand
link "Ctrl+]", IncreaseIndentCommand
link "Ctrl+Shift+[", AutoIndenter::IndentCommand
Expand Down Expand Up @@ -794,8 +833,10 @@ def self.menus
item "Paste", PasteCommand
item "Duplicate Region", DuplicateCommand
separator
item "Home", MoveHomeCommand
item "End", MoveEndCommand
item "Top", MoveTopCommand
item "Home", MoveHomeCommand
item "End", MoveEndCommand
item "Bottom", MoveBottomCommand
separator
item "Increase Indent", IncreaseIndentCommand
item "Decrease Indent", DecreaseIndentCommand
Expand Down

0 comments on commit 5801cd0

Please sign in to comment.