Patch #2116 2007-07-29 22:22

dmoore

enhanced matching brace and home/end behavior
Download
2116-enhanced_match.patch (6.8 KB)
Category
Application::Refinement
Status
Open
Close date
 
Assigned to
dmoore
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp    (revision 4335)
+++ src/sdk/cbeditor.cpp    (working copy)
@@ -960,6 +960,27 @@
     control->SetTabIndents(mgr->ReadBool(_T("/tab_indents"), true));
     control->SetBackSpaceUnIndents(mgr->ReadBool(_T("/backspace_unindents"), true));
     control->SetWrapMode(mgr->ReadBool(_T("/word_wrap"), false));
+    if(mgr->ReadBool(_T("/word_wrap_style_home_end"), true))
+    {
+        //in word wrap mode, home/end keys goto the wrap point if not already there,
+        //otherwise to the start/end of the entire line.
+        //alt+home/end go to start/end of the entire line.
+        //in unwrapped mode, there is no difference between home/end and alt+home/end
+        control->CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_NULL,wxSCI_CMD_VCHOMEWRAP);
+        control->CmdKeyAssign(wxSCI_KEY_END,wxSCI_SCMOD_NULL,wxSCI_CMD_LINEENDWRAP);
+        control->CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOME);
+        control->CmdKeyAssign(wxSCI_KEY_END,wxSCI_SCMOD_ALT,wxSCI_CMD_LINEEND);
+        control->CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT,wxSCI_CMD_VCHOMEWRAPEXTEND);
+        control->CmdKeyAssign(wxSCI_KEY_END,wxSCI_SCMOD_SHIFT,wxSCI_CMD_LINEENDWRAPEXTEND);
+        control->CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOMEEXTEND);
+        control->CmdKeyAssign(wxSCI_KEY_END,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_LINEENDEXTEND);
+    } else
+    { //in word wrap mode, home/end keys goto start/end of the entire line. alt+home/end goes to wrap points
+        control->CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOMEWRAP);
+        control->CmdKeyAssign(wxSCI_KEY_END,wxSCI_SCMOD_ALT,wxSCI_CMD_LINEENDWRAP);
+        control->CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOMEWRAPEXTEND);
+        control->CmdKeyAssign(wxSCI_KEY_END,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_LINEENDWRAPEXTEND);
+    }
     control->SetViewEOL(mgr->ReadBool(_T("/show_eol"), false));
     control->SetViewWhiteSpace(mgr->ReadInt(_T("/view_whitespace"), 0));
     //gutter
@@ -1860,20 +1881,34 @@
         GetControl()->MarkerAdd(line, marker);
 }
 
-void cbEditor::GotoMatchingBrace()
+void cbEditor::GotoMatchingBrace(bool select)
 {
     cbStyledTextCtrl* control = GetControl();
 
+//    int currentpos=control->GetCurrentPos();
+    int anchorpos=control->GetAnchor();
     // this works only when the caret is *before* the brace
     int matchingBrace = control->BraceMatch(control->GetCurrentPos());
+    int offset=-1;
 
     // if we haven't found it, we 'll search at pos-1 too
     if(matchingBrace == wxSCI_INVALID_POSITION)
+    {
         matchingBrace = control->BraceMatch(control->GetCurrentPos() - 1);
+        offset=0;
+    }
 
     // now, we either found it or not
     if(matchingBrace != wxSCI_INVALID_POSITION)
-        control->GotoPos(matchingBrace);
+    {
+        matchingBrace-=offset; //move to the position either inside or outside the match depending on whether we were inside or outside of the first brace
+        if(select)
+        {
+            control->GotoPos(matchingBrace);
+            control->SetAnchor(anchorpos);
+        } else
+            control->GotoPos(matchingBrace);
+    }
 }
 
 void cbEditor::HighlightBraces()
Index: src/include/cbeditor.h
===================================================================
--- src/include/cbeditor.h    (revision 4335)
+++ src/include/cbeditor.h    (working copy)
@@ -175,7 +175,7 @@
         EditorColourSet* GetColourSet() const { return m_pTheme; }
 
         /** Jumps to the matching brace (if there is one). */
-        void GotoMatchingBrace();
+        void GotoMatchingBrace(bool select=false);
 
         /** Highlights the brace pair (one of the braces must be under the cursor) */
         void HighlightBraces();
Index: src/src/main.cpp
===================================================================
--- src/src/main.cpp    (revision 4335)
+++ src/src/main.cpp    (working copy)
@@ -146,6 +146,7 @@
 int idEditPaste = XRCID("idEditPaste");
 int idEditSwapHeaderSource = XRCID("idEditSwapHeaderSource");
 int idEditGotoMatchingBrace = XRCID("idEditGotoMatchingBrace");
+int idEditSelectMatchingBrace = XRCID("idEditSelectMatchingBrace");
 int idEditHighlightMode = XRCID("idEditHighlightMode");
 int idEditHighlightModeText = XRCID("idEditHighlightModeText");
 int idEditBookmarks = XRCID("idEditBookmarks");
@@ -276,6 +277,7 @@
     EVT_UPDATE_UI(idEditPaste, MainFrame::OnEditMenuUpdateUI)
     EVT_UPDATE_UI(idEditSwapHeaderSource, MainFrame::OnEditMenuUpdateUI)
     EVT_UPDATE_UI(idEditGotoMatchingBrace, MainFrame::OnEditMenuUpdateUI)
+    EVT_UPDATE_UI(idEditSelectMatchingBrace, MainFrame::OnEditMenuUpdateUI)
     EVT_UPDATE_UI(idEditFoldAll, MainFrame::OnEditMenuUpdateUI)
     EVT_UPDATE_UI(idEditUnfoldAll, MainFrame::OnEditMenuUpdateUI)
     EVT_UPDATE_UI(idEdi
download for full patch...
dmoore 2007-07-29 22:22

Notes:

1. updates home/end behavior for wordwrapped text (no impact on unwrapped text)

a. New default behavior

* press home to goto wrap point (start of the current row). if already at wrap point, pressing home goes to first indent of the entire line

* press end to goto wrap point (end of the current row). if already at wrap point, pressing home goes to end of the entire line

* pressing alt+home goes to first indent of entire line

* pressing alt+end goes to end of entire line

* shift modifier will extend the selection in each of these cases

b. Optional legacy behavior

* same as (a) but swap effect of alt modified keystroke with unmodified keystroke

2. update goto matching brace behavior

* default key to goto matching brace is now ctrl+.

* if caret is inside of brace, new caret position will inside of brace.

* if caret is outside of brace, new caret position will outside of brace.

* new support for extending the selection to the matching brace point (also respects inside/outside caret position)

dmoore 2007-07-29 22:43

patch updates 2110

killerbot 2008-06-11 19:57

one remark : ctrl+ is not a good idea. Several programs use it to enlarge the font (Cb does, firefox does, ...)

I myself am used to ctrl-shift-B now, where in the old days I was used to ctl-[ (where could that have come from ;-) )

dmoore 2008-06-11 20:37

i have no attachment to any particular keybinding (I just wanted to use one that wasn't shift modified since that would normally be associated with extending the selection)