diff options
author | nyamatongwe <unknown> | 2005-11-09 12:11:43 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2005-11-09 12:11:43 +0000 |
commit | 0cc7d068ca8fb110c4de0886225caf5188b582eb (patch) | |
tree | c60b50aab2db215503b64e655f47270a3a9428c6 | |
parent | 3ac5c3a6ad55a035df336103693631ae15c9387a (diff) | |
download | scintilla-mirror-0cc7d068ca8fb110c4de0886225caf5188b582eb.tar.gz |
Patch, mostly from Simon Steele, that converts new lines in
pasted text to match document.
-rw-r--r-- | doc/ScintillaDoc.html | 19 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | include/Scintilla.iface | 6 | ||||
-rw-r--r-- | src/Editor.cxx | 9 | ||||
-rw-r--r-- | src/Editor.h | 2 | ||||
-rw-r--r-- | 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 { <a class="message" href="#SCI_COPYRANGE">SCI_COPYRANGE(int start, int end)</a><br /> <a class="message" href="#SCI_COPYTEXT">SCI_COPYTEXT(int length, const char *text)</a><br /> + <a class="message" href="#SCI_SETPASTECONVERTENDINGS">SCI_SETPASTECONVERTENDINGS(bool convert)</a><br /> + <a class="message" href="#SCI_GETPASTECONVERTENDINGS">SCI_GETPASTECONVERTENDINGS</a><br /> </code> <p><b id="SCI_CUT">SCI_CUT</b><br /> @@ -825,6 +827,13 @@ struct TextToFind { the system clipboard and <code>SCI_COPYTEXT</code> copies a supplied piece of text to the system clipboard.</p> + <p><b id="SCI_SETPASTECONVERTENDINGS">SCI_SETPASTECONVERTENDINGS(bool convert)</b><br /> + <b id="SCI_GETPASTECONVERTENDINGS">SCI_GETPASTECONVERTENDINGS</b><br /> + 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 + <a class="message" href="#SCI_SETEOLMODE">SCI_SETEOLMODE</a>. + Currently only changeable on Windows. On GTK+ pasted text is always converted.</p> + <h2 id="ErrorHandling">Error handling</h2> <p><b id="SCI_SETSTATUS">SCI_SETSTATUS(int status)</b><br /> @@ -1727,11 +1736,11 @@ struct TextToFind { this can be changed with the <code>SCI_SETEOLMODE</code> message. You can also convert the entire document to one of these line endings with <code>SCI_CONVERTEOLS</code>. Finally, you can choose to display the line endings with <code>SCI_SETVIEWEOL</code>.</p> - <code><a class="message" href="#">SCI_SETEOLMODE(int eolMode)</a><br /> - <a class="message" href="#">SCI_GETEOLMODE</a><br /> - <a class="message" href="#">SCI_CONVERTEOLS(int eolMode)</a><br /> - <a class="message" href="#">SCI_SETVIEWEOL(bool visible)</a><br /> - <a class="message" href="#">SCI_GETVIEWEOL</a><br /> + <code><a class="message" href="#SCI_SETEOLMODE">SCI_SETEOLMODE(int eolMode)</a><br /> + <a class="message" href="#SCI_GETEOLMODE">SCI_GETEOLMODE</a><br /> + <a class="message" href="#SCI_CONVERTEOLS">SCI_CONVERTEOLS(int eolMode)</a><br /> + <a class="message" href="#SCI_SETVIEWEOL">SCI_SETVIEWEOL(bool visible)</a><br /> + <a class="message" href="#SCI_GETVIEWEOL">SCI_GETVIEWEOL</a><br /> </code> <p><b id="SCI_SETEOLMODE">SCI_SETEOLMODE(int eolMode)</b><br /> 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(); |