Skip to content
Browse files

FS#443 Fix some macro deficiencies

- Add Home/End/PageUp/PageDown macro commands
- Make Return spew InsertNewline
- Add some translations from TextMate macro commands to E macro commands
  • Loading branch information...
1 parent ca94bd1 commit 8dccde033f6724c6f709abb988a4b60eb441b630 @tea tea committed
Showing with 142 additions and 35 deletions.
  1. +13 −13 src/CommandHandler.cpp
  2. +63 −16 src/EditorCtrl.cpp
  3. +4 −2 src/EditorCtrl.h
  4. +62 −4 src/tm_syntaxhandler.cpp
View
26 src/CommandHandler.cpp
@@ -172,13 +172,13 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorRight), EditorCtrl::SEL_IGNORE));
break;
case '0':
- DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineStart), false));
+ DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToHardLineStart), EditorCtrl::SEL_IGNORE));
break;
case '^':
- DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineStart), true));
+ DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToSoftLineStart), EditorCtrl::SEL_IGNORE));
break;
case '$':
- DoMovement(count, mem_fun_ref(&EditorCtrl::CursorToLineEnd));
+ DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineEnd), EditorCtrl::SEL_IGNORE));
break;
case 'G':
if (m_count) DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLine), count));
@@ -186,7 +186,7 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
break;
case '|':
if (m_count) DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToColumn), count));
- else DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineStart), false));
+ else DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToHardLineStart), EditorCtrl::SEL_IGNORE));
break;
case 'f':
m_state = state_findchar;
@@ -198,7 +198,7 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToWordStart), false));
break;
case 'W':
- DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToWordStart), true));
+ DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToWordStart), true));
break;
case 'e':
DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToWordEnd), false));
@@ -367,7 +367,7 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
}
else if (!m_editor.HasSearchRange()) {
// Insert line below current
- m_editor.CursorToLineEnd();
+ m_editor.CursorToLineEnd(EditorCtrl::SEL_IGNORE);
m_editor.InsertNewline();
m_parentFrame.ShowCommandMode(false);
Clear();
@@ -376,7 +376,7 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
case 'O':
if (!selected && !m_editor.HasSearchRange()) {
// Insert line above current
- m_editor.CursorToLineStart();
+ m_editor.CursorToSoftLineStart(EditorCtrl::SEL_IGNORE);
m_editor.InsertNewline();
m_editor.CursorLeft(EditorCtrl::SEL_IGNORE);
m_parentFrame.ShowCommandMode(false);
@@ -412,13 +412,13 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
Clear();
return true;
case 'I':
- DoMovement(1, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineStart), true));
+ DoMovement(1, bind2nd(mem_fun_ref(&EditorCtrl::CursorToSoftLineStart), EditorCtrl::SEL_IGNORE));
m_editor.ClearSearchRange(true);
m_parentFrame.ShowCommandMode(false);
Clear();
return true;
case 'A':
- DoMovement(1, mem_fun_ref(&EditorCtrl::CursorToLineEnd));
+ DoMovement(1, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineEnd), EditorCtrl::SEL_IGNORE));
m_editor.ClearSearchRange(true);
m_parentFrame.ShowCommandMode(false);
Clear();
@@ -427,9 +427,9 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
if (m_state == state_change) {
// Change current line
m_select = false;
- DoMovement(1, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineStart), true), false);
+ DoMovement(1, bind2nd(mem_fun_ref(&EditorCtrl::CursorToSoftLineStart), EditorCtrl::SEL_IGNORE), false);
m_select = true;
- DoMovement(count, mem_fun_ref(&EditorCtrl::CursorToLineEnd), false);
+ DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineEnd), EditorCtrl::SEL_IGNORE), false);
if (m_editor.IsSelected()) m_editor.Delete();
m_editor.ClearSearchRange(true);
m_parentFrame.ShowCommandMode(false);
@@ -443,7 +443,7 @@ bool CommandHandler::ProcessCommand(const wxKeyEvent& evt, bool record) {
break;
case 'C':
m_select = true;
- DoMovement(count, mem_fun_ref(&EditorCtrl::CursorToLineEnd));
+ DoMovement(count, bind2nd(mem_fun_ref(&EditorCtrl::CursorToLineEnd), EditorCtrl::SEL_IGNORE));
if (m_editor.IsSelected()) m_editor.Delete();
m_editor.ClearSearchRange(true);
m_parentFrame.ShowCommandMode(false);
@@ -1485,4 +1485,4 @@ void CommandHandler::EnterSelections(size_t count) {
m_editor.SetSearchRange();
Clear();
-}
+}
View
79 src/EditorCtrl.cpp
@@ -2290,9 +2290,13 @@ unsigned int EditorCtrl::InsertNewline() {
void EditorCtrl::InsertChar(const wxChar& text) {
if (m_macro.IsRecording()) {
- eMacroCmd& cmd = lastaction != ACTION_INSERT || m_macro.IsEmpty() || m_macro.Last().GetName() != wxT("InsertChars")
- ? m_macro.Add(wxT("InsertChars"), wxT("text"), wxT("")) : m_macro.Last();
- cmd.ExtendString(0, text);
+ if (text == '\n')
+ m_macro.Add(wxT("InsertNewline"));
+ else {
+ eMacroCmd& cmd = lastaction != ACTION_INSERT || m_macro.IsEmpty() || m_macro.Last().GetName() != wxT("InsertChars")
+ ? m_macro.Add(wxT("InsertChars"), wxT("text"), wxT("")) : m_macro.Last();
+ cmd.ExtendString(0, text);
+ }
}
if (m_snippetHandler.IsActive()) {
@@ -6414,17 +6418,13 @@ void EditorCtrl::OnChar(wxKeyEvent& event) {
case WXK_HOME:
case WXK_NUMPAD_HOME:
case WXK_NUMPAD_BEGIN:
- CursorToLineStart(true);
- if (event.ShiftDown()) SelectFromMovement(oldpos, GetPos());
- else RemoveAllSelections();
+ CursorToSoftLineStart(event.ShiftDown() ? SEL_SELECT : SEL_REMOVE);
lastaction = ACTION_NONE;
break;
case WXK_END:
case WXK_NUMPAD_END:
- CursorToLineEnd();
- if (event.ShiftDown()) SelectFromMovement(oldpos, GetPos());
- else RemoveAllSelections();
+ CursorToLineEnd(event.ShiftDown() ? SEL_SELECT : SEL_REMOVE);
lastaction = ACTION_NONE;
break;
@@ -6641,6 +6641,10 @@ void EditorCtrl::SetPos(int line, int column) {
}
void EditorCtrl::PageUp(bool select, int WXUNUSED(count)) {
+ if (m_macro.IsRecording()) {
+ m_macro.Add(wxT("PageUp"), wxT("select"), select);
+ }
+
const wxSize size = GetClientSize();
const int oldpos = m_lines.GetPos();
const wxPoint cpos = m_lines.GetCaretPos();
@@ -6659,6 +6663,10 @@ void EditorCtrl::PageUp(bool select, int WXUNUSED(count)) {
}
void EditorCtrl::PageDown(bool select, int WXUNUSED(count)) {
+ if (m_macro.IsRecording()) {
+ m_macro.Add(wxT("PageDown"), wxT("select"), select);
+ }
+
const wxSize size = GetClientSize();
const int oldpos = m_lines.GetPos();
const wxPoint cpos = m_lines.GetCaretPos();
@@ -6939,34 +6947,56 @@ void EditorCtrl::CursorToColumn(unsigned int column) {
m_lines.SetPos(wxMin(newpos, lineEnd));
}
-void EditorCtrl::CursorToLineStart(bool soft) {
+void EditorCtrl::CursorToLineStart(bool soft, SelAction select) {
+ if (m_macro.IsRecording()) {
+ m_macro.Add(wxT("CursorToLineStart"), wxT("soft"), soft)
+ .AddArg(wxT("select"), (select == SEL_SELECT));
+ }
+
const unsigned int oldpos = GetPos();
const unsigned int currentLine = m_lines.GetCurrentLine();
const unsigned int startOfLine = m_lines.GetLineStartpos(currentLine);
- if (!soft) m_lines.SetPos(startOfLine);
+ unsigned int pos;
+
+ if (!soft) pos = startOfLine;
else {
const unsigned int indentPos = m_lines.GetLineIndentPos(currentLine);
if (indentPos < oldpos) {
// Move to first text after indentation
- m_lines.SetPos(indentPos);
+ pos = indentPos;
}
else {
if (oldpos == startOfLine) {
// Move back to text after indentation
- m_lines.SetPos(indentPos);
+ pos = indentPos;
}
else {
// Move to start-of-line
- m_lines.SetPos(startOfLine);
+ pos = startOfLine;
}
}
}
+ m_lines.SetPos(pos);
+
+ // Handle selection
+ if (select == SEL_REMOVE) m_lines.RemoveAllSelections();
+ else if (select == SEL_SELECT) SelectFromMovement(oldpos, pos);
}
-void EditorCtrl::CursorToLineEnd() {
- m_lines.SetPos(m_lines.GetLineEndpos(m_lines.GetCurrentLine()));
+void EditorCtrl::CursorToLineEnd(SelAction select) {
+ if (m_macro.IsRecording()) {
+ m_macro.Add(wxT("CursorToLineEnd"), wxT("select"), (select == SEL_SELECT));
+ }
+
+ const unsigned int oldpos = GetPos();
+ unsigned int pos = m_lines.GetLineEndpos(m_lines.GetCurrentLine());
+ m_lines.SetPos(pos);
+
+ // Handle selection
+ if (select == SEL_REMOVE) m_lines.RemoveAllSelections();
+ else if (select == SEL_SELECT) SelectFromMovement(oldpos, pos);
}
void EditorCtrl::CursorToNextChar(wxChar c) {
@@ -9869,6 +9899,23 @@ wxVariant EditorCtrl::PlayCommand(const eMacroCmd& cmd) {
const SelAction select = cmd.GetArgBool(0) ? SEL_SELECT : SEL_REMOVE;
CursorToEnd(select);
}
+ else if (name == wxT("CursorToLineStart")) {
+ const bool soft = cmd.GetArgBool(0);
+ const SelAction select = cmd.GetArgBool(1) ? SEL_SELECT : SEL_REMOVE;
+ CursorToLineStart(soft, select);
+ }
+ else if (name == wxT("CursorToLineEnd")) {
+ const SelAction select = cmd.GetArgBool(0) ? SEL_SELECT : SEL_REMOVE;
+ CursorToLineEnd(select);
+ }
+ else if (name == wxT("PageUp")) {
+ const bool select = cmd.GetArgBool(0);
+ PageUp(select);
+ }
+ else if (name == wxT("PageDown")) {
+ const bool select = cmd.GetArgBool(0);
+ PageDown(select);
+ }
else if (name == wxT("SetPos")) {
const unsigned int pos = cmd.GetArgInt(0);
if (pos >= 0 && pos <= GetLength()) SetPos(pos);
View
6 src/EditorCtrl.h
@@ -251,8 +251,10 @@ class EditorCtrl : public KeyHookable<wxControl>,
void CursorToEnd(SelAction select);
void CursorToLine(unsigned int line);
void CursorToColumn(unsigned int column);
- void CursorToLineStart(bool soft=true);
- void CursorToLineEnd();
+ void CursorToLineStart(bool soft=true, SelAction select = SEL_REMOVE);
+ void CursorToSoftLineStart(SelAction select) {CursorToLineStart(true, select);};
+ void CursorToHardLineStart(SelAction select) {CursorToLineStart(false, select);};
+ void CursorToLineEnd(SelAction select);
void CursorToNextChar(wxChar c);
void CursorToPrevChar(wxChar c);
void CursorToWordStart(bool bigword);
View
66 src/tm_syntaxhandler.cpp
@@ -842,6 +842,20 @@ bool TmSyntaxHandler::TranslateMacroCmd(const PListDict& macroDict, eMacro& macr
}
+/*
+ * @TODO
+ * Add support for at least the following commands (these are found in textmate's bundles):
+ * - findWithOptions with action replaceAll
+ * - centerSelectionInVisibleArea
+ * - indent
+ * - toggleFolding
+ * - shiftLeft
+ * - insertSnippetWithOptions (with arguments: content, name, tabTrigger, scope, uuid - as in snippets files)
+ * - deleteForward
+ * - selectBlock
+ * - selectHardLine
+ * - deleteToBeginningOfLine
+ */
bool TmSyntaxHandler::TranslateTmMacroCmd(const PListDict& macroDict, eMacro& macro) const {
const wxString cmdStr = macroDict.wxGetString("command");
PListDict argDict;
@@ -850,6 +864,9 @@ bool TmSyntaxHandler::TranslateTmMacroCmd(const PListDict& macroDict, eMacro& ma
if (cmdStr == wxT("selectWord:")) {
macro.Add(wxT("SelectWord"));
}
+ if (cmdStr == wxT("selectAll:")) {
+ macro.Add(wxT("SelectAll"));
+ }
else if (cmdStr == wxT("moveUp:")) {
macro.Add(wxT("CursorUp"), wxT("select"), false);
}
@@ -863,16 +880,57 @@ bool TmSyntaxHandler::TranslateTmMacroCmd(const PListDict& macroDict, eMacro& ma
macro.Add(wxT("CursorRight"), wxT("select"), false);
}
else if (cmdStr == wxT("moveToBeginningOfLine:")) {
- macro.Add(wxT("CursorToLineStart"), wxT("soft"), false);
+ macro.Add(wxT("CursorToLineStart"), wxT("soft"), false)
+ .AddArg(wxT("select"), false);
}
else if (cmdStr == wxT("moveToEndOfLine:")) {
- macro.Add(wxT("CursorToLineEnd"));
+ macro.Add(wxT("CursorToLineEnd"), wxT("select"), false);
+ }
+ else if (cmdStr == wxT("moveToBeginningOfDocument:")) {
+ macro.Add(wxT("CursorToHome"), wxT("select"), false);
+ }
+ else if (cmdStr == wxT("moveToEndOfDocument:")) {
+ macro.Add(wxT("CursorToEnd"), wxT("select"), false);
}
else if (cmdStr == wxT("moveToEndOfParagraph:")) {
- macro.Add(wxT("CursorToLineEnd"));
+ macro.Add(wxT("CursorToLineEnd"), wxT("select"), false);
+ }
+ else if (cmdStr == wxT("pageUp:")) {
+ macro.Add(wxT("PageUp"), wxT("select"), false);
+ }
+ else if (cmdStr == wxT("pageDown:")) {
+ macro.Add(wxT("PageDown"), wxT("select"), false);
+ }
+ else if (cmdStr == wxT("moveUpAndModifySelection:")) {
+ macro.Add(wxT("CursorUp"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("moveDownAndModifySelection:")) {
+ macro.Add(wxT("CursorDown"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("moveLeftAndModifySelection:")) {
+ macro.Add(wxT("CursorLeft"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("moveRightAndModifySelection:")) {
+ macro.Add(wxT("CursorRight"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("moveToBeginningOfLineAndModifySelection:")) {
+ macro.Add(wxT("CursorToLineStart"), wxT("soft"), false)
+ .AddArg(wxT("select"), true);
+ }
+ else if (cmdStr == wxT("moveToEndOfLineAndModifySelection:")) {
+ macro.Add(wxT("CursorToLineEnd"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("moveToBeginningOfDocumentAndModifySelection:")) {
+ macro.Add(wxT("CursorToHome"), wxT("select"), true);
}
else if (cmdStr == wxT("moveToEndOfDocumentAndModifySelection:")) {
- macro.Add(wxT("CursorEnd"), wxT("select"), true);
+ macro.Add(wxT("CursorToEnd"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("pageUpAndModifySelection:")) {
+ macro.Add(wxT("PageUp"), wxT("select"), true);
+ }
+ else if (cmdStr == wxT("pageDownAndModifySelection:")) {
+ macro.Add(wxT("PageDown"), wxT("select"), true);
}
else if (cmdStr == wxT("deleteBackward:")) {
macro.Add(wxT("Backspace"));

0 comments on commit 8dccde0

Please sign in to comment.
Something went wrong with that request. Please try again.