From 5801cd0960da962ec8626afe9d1c5012bf454247 Mon Sep 17 00:00:00 2001 From: Daniel Lucraft Date: Wed, 26 May 2010 05:58:26 +0100 Subject: [PATCH] Home command goes to start of text first, then start of line. --- CHANGES | 1 + ROADMAP.md | 11 +++++++++ plugins/redcar/redcar.rb | 53 +++++++++++++++++++++++++++++++++++----- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 74ebdc47a..89b9f58bc 100644 --- a/CHANGES +++ b/CHANGES @@ -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: diff --git a/ROADMAP.md b/ROADMAP.md index 2c2ebc8df..5eac079eb 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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 \ No newline at end of file diff --git a/plugins/redcar/redcar.rb b/plugins/redcar/redcar.rb index 6dc6d7640..ec671898c 100644 --- a/plugins/redcar/redcar.rb +++ b/plugins/redcar/redcar.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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