From 0cc7d068ca8fb110c4de0886225caf5188b582eb Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 9 Nov 2005 12:11:43 +0000 Subject: Patch, mostly from Simon Steele, that converts new lines in pasted text to match document. --- doc/ScintillaDoc.html | 19 ++++++++++++++----- include/Scintilla.h | 2 ++ include/Scintilla.iface | 6 ++++++ src/Editor.cxx | 9 +++++++++ src/Editor.h | 2 ++ win32/ScintillaWin.cxx | 45 ++++++++++++++++++++++++++------------------- 6 files changed, 59 insertions(+), 24 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index fb4ac1420..7bc2d8b25 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -798,6 +798,8 @@ struct TextToFind { SCI_COPYRANGE(int start, int end)
SCI_COPYTEXT(int length, const char *text)
+ SCI_SETPASTECONVERTENDINGS(bool convert)
+ SCI_GETPASTECONVERTENDINGS

SCI_CUT
@@ -825,6 +827,13 @@ struct TextToFind { the system clipboard and SCI_COPYTEXT copies a supplied piece of text to the system clipboard.

+

SCI_SETPASTECONVERTENDINGS(bool convert)
+ SCI_GETPASTECONVERTENDINGS
+ If this property is set then when text is pasted any line ends are converted to match the document's + end of line mode as set with + SCI_SETEOLMODE. + Currently only changeable on Windows. On GTK+ pasted text is always converted.

+

Error handling

SCI_SETSTATUS(int status)
@@ -1727,11 +1736,11 @@ struct TextToFind { this can be changed with the SCI_SETEOLMODE message. You can also convert the entire document to one of these line endings with SCI_CONVERTEOLS. Finally, you can choose to display the line endings with SCI_SETVIEWEOL.

- SCI_SETEOLMODE(int eolMode)
- SCI_GETEOLMODE
- SCI_CONVERTEOLS(int eolMode)
- SCI_SETVIEWEOL(bool visible)
- SCI_GETVIEWEOL
+ SCI_SETEOLMODE(int eolMode)
+ SCI_GETEOLMODE
+ SCI_CONVERTEOLS(int eolMode)
+ SCI_SETVIEWEOL(bool visible)
+ SCI_GETVIEWEOL

SCI_SETEOLMODE(int eolMode)
diff --git a/include/Scintilla.h b/include/Scintilla.h index 1d6588215..a82c00fda 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -604,6 +604,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETCARETSTICKY 2457 #define SCI_SETCARETSTICKY 2458 #define SCI_TOGGLECARETSTICKY 2459 +#define SCI_SETPASTECONVERTENDINGS 2467 +#define SCI_GETPASTECONVERTENDINGS 2468 #define SCI_STARTRECORD 3001 #define SCI_STOPRECORD 3002 #define SCI_SETLEXER 4001 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 41c42a952..2c2272cd1 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1632,6 +1632,12 @@ set void SetCaretSticky=2458(bool useCaretStickyBehaviour,) # Switch between sticky and non-sticky: meant to be bound to a key. fun void ToggleCaretSticky=2459(,) +# Enable/Disable convert-on-paste for line endings +set void SetPasteConvertEndings=2467(bool convert,) + +# Get convert-on-paste setting +get bool GetPasteConvertEndings=2468(,) + # Start notifying the container of all key presses and commands. fun void StartRecord=3001(,) diff --git a/src/Editor.cxx b/src/Editor.cxx index bf94fb8ed..85212aa80 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -424,6 +424,8 @@ Editor::Editor() { wrapVisualStartIndent = 0; actualWrapVisualStartIndent = 0; + convertPastes = true; + hsStart = -1; hsEnd = -1; @@ -7241,6 +7243,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { InvalidateStyleRedraw(); break; + case SCI_SETPASTECONVERTENDINGS: + convertPastes = wParam != 0; + break; + + case SCI_GETPASTECONVERTENDINGS: + return convertPastes ? 1 : 0; + default: return DefWndProc(iMessage, wParam, lParam); } diff --git a/src/Editor.h b/src/Editor.h index 0db5cb1c3..6d2cbbdef 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -312,6 +312,8 @@ protected: // ScintillaBase subclass needs access to much of Editor int wrapVisualStartIndent; int actualWrapVisualStartIndent; + bool convertPastes; + Document *pdoc; Editor(); diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 6d51445e6..a4c09a0fb 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -219,6 +219,8 @@ class ScintillaWin : virtual bool GetScrollInfo(int nBar, LPSCROLLINFO lpsi); void ChangeScrollPos(int barType, int pos); + void InsertPasteText(const char *text, int len, int selStart, bool isRectangular); + public: // Public for benefit of Scintilla_DirectFunction virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam); @@ -1198,6 +1200,25 @@ public: } }; +void ScintillaWin::InsertPasteText(const char *text, int len, int selStart, bool isRectangular) { + if (isRectangular) { + PasteRectangular(selStart, text, len); + } else { + if (convertPastes) { + // Convert line endings of the paste into our local line-endings mode + char *convertedString = Document::TransformLineEnds(&len, text, len, pdoc->eolMode); + if (pdoc->InsertString(currentPos, convertedString, len)) { + SetEmptySelection(currentPos + len); + } + delete []convertedString; + } else { + if (pdoc->InsertString(currentPos, text, len)) { + SetEmptySelection(currentPos + len); + } + } + } +} + void ScintillaWin::Paste() { if (!::OpenClipboard(MainHWND())) return; @@ -1236,13 +1257,7 @@ void ScintillaWin::Paste() { } if (putf) { - if (isRectangular) { - PasteRectangular(selStart, putf, len); - } else { - if (pdoc->InsertString(currentPos, putf, len)) { - SetEmptySelection(currentPos + len); - } - } + InsertPasteText(putf, len, selStart, isRectangular); delete []putf; } } @@ -1276,20 +1291,12 @@ void ScintillaWin::Paste() { delete []uptr; - if (isRectangular) { - PasteRectangular(selStart, putf, mlen); - } else { - pdoc->InsertString(currentPos, putf, mlen); - SetEmptySelection(currentPos + mlen); + if (putf) { + InsertPasteText(putf, mlen, selStart, isRectangular); + delete []putf; } - delete []putf; } else { - if (isRectangular) { - PasteRectangular(selStart, ptr, len); - } else { - pdoc->InsertString(currentPos, ptr, len); - SetEmptySelection(currentPos + len); - } + InsertPasteText(ptr, len, selStart, isRectangular); } } memSelection.Unlock(); -- cgit v1.2.3