Ensure that line endings stay consistent when editing in styled text controls.
authordpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Fri, 20 Jun 2008 09:37:49 +0000 (09:37 +0000)
committerdpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Fri, 20 Jun 2008 09:37:49 +0000 (09:37 +0000)
git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@7378 a7884b65-44f6-0310-8a51-81a127f17b15

CHANGELOG
pgadmin/ctl/ctlSQLBox.cpp
pgadmin/frm/frmQuery.cpp

index 9e3915919d4a73ca6ecdac824ea97b353de9ae96..3593ab948d27741e93140c5a51c2db42e0d18333 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -36,7 +36,9 @@ Changes
 \r
 Date       Dev Ver    Change details\r
 ---------- --- -----  --------------\r
-2008-06-11 DP  1.8.5  Fix listing of group roles in the combo box on privilege \r
+2008-06-20 DP  1.8.5  Ensure that line endings stay consistent when editing in\r
+                      styled text controls.\r
+2008-06-11 DP  1.8.5  Fix listing of group roles in the combo box on privilege\r
                       panels.\r
 2008-06-10 DP  1.8.5  Reverse engineer multi-word type names correctly when\r
                       quoting.\r
index 07f27fe43aaaa7c38bcae246d18b6f2cdc58de32..2d22ffbb38746fdf9cc6241c38d785b830c31619 100644 (file)
@@ -308,6 +308,21 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent& event)
        event.m_metaDown=false;
 #endif
 
+       // Get the line ending type
+       wxString lineEnd;
+       switch (GetEOLMode())
+       {
+               case wxSTC_EOL_LF:
+                       lineEnd = wxT("\n");
+                       break;
+               case wxSTC_EOL_CRLF:
+                       lineEnd = wxT("\r\n");
+                       break;
+               case wxSTC_EOL_CR:
+                       lineEnd = wxT("\r");
+                       break;
+       }
+
        if (!AutoCompActive() &&
                 ( settings->GetTabForCompletion() && /* autocomplete on tab only if specifically configured */
                  !event.AltDown() && !event.CmdDown() && !event.ControlDown() && event.GetKeyCode() == '\t'
@@ -322,9 +337,13 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent& event)
         line = GetLine(GetCurrentLine());
 
         // Get the offset for the current line - basically, whether
-        // or not it ends with a \n
+        // or not it ends with a \r\n, \n or \r, and if so, the length
         int offset =  0;
-        if (line.EndsWith(wxT("\n")))
+        if (line.EndsWith(wxT("\r\n")))
+            offset = 2;
+        else if (line.EndsWith(wxT("\n")))
+            offset = 1;
+        else if (line.EndsWith(wxT("\r")))
             offset = 1;
 
         // Get the indent. This is every leading space or tab on the
@@ -346,11 +365,11 @@ void ctlSQLBox::OnKeyDown(wxKeyEvent& event)
         // Lose any selected text.
         ReplaceSelection(wxEmptyString);
 
-        // Insert a replacement \n, and the indent at the insertion point.
-        InsertText(GetCurrentPos(), wxT("\n") + indent);
+        // Insert a replacement \n (or whatever), and the indent at the insertion point.
+        InsertText(GetCurrentPos(), lineEnd + indent);
 
         // Now, reset the position, and clear the selection
-        SetCurrentPos(GetCurrentPos() + indent.Length() + 1);
+        SetCurrentPos(GetCurrentPos() + indent.Length() + lineEnd.Length());
         SetSelection(GetCurrentPos(), GetCurrentPos());
     }
     else if (m_dlgFindReplace && event.GetKeyCode() == WXK_F3)
index c308cd0e39d3b5232cef39ff0d60bdad477b3881..e4a05181dc3a6b6c9c07ba2b824cb2fa5dd074fc 100644 (file)
@@ -1382,6 +1382,7 @@ void frmQuery::OnSetEOLMode(wxCommandEvent& event)
 {
     int mode = GetLineEndingStyle();
     sqlQuery->ConvertEOLs(mode);
+       sqlQuery->SetEOLMode(mode);
 
     switch(mode)
     {