diff options
author | nyamatongwe <devnull@localhost> | 2008-01-19 04:19:36 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2008-01-19 04:19:36 +0000 |
commit | 4663b7ffe215ea47902a467e26f4e6b40435f58d (patch) | |
tree | fd44fd40feef2aa1412b06a3832af8212ba6f252 /src | |
parent | 541f13e28956050f2111c873dc7afeeaed981ef9 (diff) | |
download | scintilla-mirror-4663b7ffe215ea47902a467e26f4e6b40435f58d.tar.gz |
CopyAllowLine from 280Z28 / Sam Harwell that reproduces Visual Studio's
behaviour when performing copy on an empty selection copies the current
line.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 52 | ||||
-rw-r--r-- | src/Editor.h | 20 |
2 files changed, 56 insertions, 16 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 02ca0058f..1eaf8f92e 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1400,7 +1400,7 @@ void Editor::LinesJoin() { } } -const char *StringFromEOLMode(int eolMode) { +const char *Editor::StringFromEOLMode(int eolMode) { if (eolMode == SC_EOL_CRLF) { return "\r\n"; } else if (eolMode == SC_EOL_CR) { @@ -3494,6 +3494,12 @@ void Editor::ClearDocumentStyle() { pdoc->ClearLevels(); } +void Editor::CopyAllowLine() { + SelectionText selectedText; + CopySelectionRange(&selectedText, true); + CopyToClipboard(selectedText); +} + void Editor::Cut() { pdoc->CheckReadOnly(); if (!pdoc->IsReadOnly() && !SelectionContainsProtected()) { @@ -4044,6 +4050,7 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lPar case SCI_PAGEUPRECTEXTEND: case SCI_PAGEDOWNRECTEXTEND: case SCI_SELECTIONDUPLICATE: + case SCI_COPYALLOWLINE: break; // Filter out all others like display changes. Also, newlines are redundant @@ -4910,14 +4917,37 @@ char *Editor::CopyRange(int start, int end) { return text; } -void Editor::CopySelectionFromRange(SelectionText *ss, int start, int end) { - ss->Set(CopyRange(start, end), end - start + 1, - pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false); +void Editor::CopySelectionFromRange(SelectionText *ss, bool allowLineCopy, int start, int end) { + bool isLine = allowLineCopy && (start == end); + if (isLine) { + int currentLine = pdoc->LineFromPosition(currentPos); + start = pdoc->LineStart(currentLine); + end = pdoc->LineEnd(currentLine); + + char *text = CopyRange(start, end); + int textLen = text ? strlen(text) : 0; + // include room for \r\n\0 + textLen += 3; + char *textWithEndl = new char[textLen]; + textWithEndl[0] = '\0'; + if (text) + strncat(textWithEndl, text, textLen); + if (pdoc->eolMode != SC_EOL_LF) + strncat(textWithEndl, "\r", textLen); + if (pdoc->eolMode != SC_EOL_CR) + strncat(textWithEndl, "\n", textLen); + ss->Set(textWithEndl, strlen(textWithEndl), + pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, true); + delete []text; + } else { + ss->Set(CopyRange(start, end), end - start + 1, + pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, false); + } } -void Editor::CopySelectionRange(SelectionText *ss) { +void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { if (selType == selStream) { - CopySelectionFromRange(ss, SelectionStart(), SelectionEnd()); + CopySelectionFromRange(ss, allowLineCopy, SelectionStart(), SelectionEnd()); } else { char *text = 0; int size = 0; @@ -4955,7 +4985,7 @@ void Editor::CopySelectionRange(SelectionText *ss) { } } ss->Set(text, size + 1, pdoc->dbcsCodePage, - vs.styles[STYLE_DEFAULT].characterSet, selType == selRectangle); + vs.styles[STYLE_DEFAULT].characterSet, selType == selRectangle, selType == selLines); } } @@ -4964,14 +4994,14 @@ void Editor::CopyRangeToClipboard(int start, int end) { end = pdoc->ClampPositionIntoDocument(end); SelectionText selectedText; selectedText.Set(CopyRange(start, end), end - start + 1, - pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false); + pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, false); CopyToClipboard(selectedText); } void Editor::CopyText(int length, const char *text) { SelectionText selectedText; selectedText.Copy(text, length + 1, - pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false); + pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, false); CopyToClipboard(selectedText); } @@ -5948,6 +5978,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { Copy(); break; + case SCI_COPYALLOWLINE: + CopyAllowLine(); + break; + case SCI_COPYRANGE: CopyRangeToClipboard(wParam, lParam); break; diff --git a/src/Editor.h b/src/Editor.h index 049cc373f..ee3db99b3 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -54,16 +54,17 @@ public: char *s; int len; bool rectangular; + bool lineCopy; int codePage; int characterSet; - SelectionText() : s(0), len(0), rectangular(false), codePage(0), characterSet(0) {} + SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {} ~SelectionText() { Free(); } void Free() { - Set(0, 0, 0, 0, false); + Set(0, 0, 0, 0, false, false); } - void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_) { + void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { delete []s; s = s_; if (s) @@ -73,8 +74,9 @@ public: codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; + lineCopy = lineCopy_; } - void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_) { + void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { delete []s; s = new char[len_]; if (s) { @@ -88,9 +90,10 @@ public: codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; + lineCopy = lineCopy_; } void Copy(const SelectionText &other) { - Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular); + Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy); } }; @@ -342,6 +345,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void Cut(); void PasteRectangular(int pos, const char *ptr, int len); virtual void Copy() = 0; + virtual void CopyAllowLine(); virtual bool CanPaste(); virtual void Paste() = 0; void Clear(); @@ -406,8 +410,8 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual void CopyToClipboard(const SelectionText &selectedText) = 0; char *CopyRange(int start, int end); - void CopySelectionFromRange(SelectionText *ss, int start, int end); - void CopySelectionRange(SelectionText *ss); + void CopySelectionFromRange(SelectionText *ss, bool allowLineCopy, int start, int end); + void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false); void CopyRangeToClipboard(int start, int end); void CopyText(int length, const char *text); void SetDragPosition(int newPos); @@ -460,6 +464,8 @@ protected: // ScintillaBase subclass needs access to much of Editor void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); + static const char *StringFromEOLMode(int eolMode); + public: // Public so the COM thunks can access it. bool IsUnicodeMode() const; |