diff options
-rw-r--r-- | doc/ScintillaDoc.html | 5 | ||||
-rw-r--r-- | include/Scintilla.h | 1 | ||||
-rw-r--r-- | include/Scintilla.iface | 3 | ||||
-rw-r--r-- | src/Editor.cxx | 36 | ||||
-rw-r--r-- | src/Editor.h | 2 | ||||
-rw-r--r-- | src/KeyMap.cxx | 2 |
6 files changed, 37 insertions, 12 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 7bc2d8b25..a5e84ec19 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3463,6 +3463,11 @@ struct TextToFind { <td><code>SCI_BACKTAB</code></td> </tr> + + <tr> + <td><code>SCI_SELECTIONDUPLICATE</code></td> + + </tr> </tbody> </table> diff --git a/include/Scintilla.h b/include/Scintilla.h index a82c00fda..b4ed329f7 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -606,6 +606,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_TOGGLECARETSTICKY 2459 #define SCI_SETPASTECONVERTENDINGS 2467 #define SCI_GETPASTECONVERTENDINGS 2468 +#define SCI_SELECTIONDUPLICATE 2469 #define SCI_STARTRECORD 3001 #define SCI_STOPRECORD 3002 #define SCI_SETLEXER 4001 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 2c2272cd1..d20604819 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1638,6 +1638,9 @@ set void SetPasteConvertEndings=2467(bool convert,) # Get convert-on-paste setting get bool GetPasteConvertEndings=2468(,) +# Duplicate the selection. If selection empty duplicate the line containing the caret. +fun void SelectionDuplicate=2469(,) + # 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 85212aa80..f4ef99b5a 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -3886,6 +3886,7 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lPar case SCI_LINEENDRECTEXTEND: case SCI_PAGEUPRECTEXTEND: case SCI_PAGEDOWNRECTEXTEND: + case SCI_SELECTIONDUPLICATE: break; // Filter out all others like display changes. Also, newlines are redundant @@ -3999,15 +4000,26 @@ void Editor::LineTranspose() { } } -void Editor::LineDuplicate() { - int line = pdoc->LineFromPosition(currentPos); - int start = pdoc->LineStart(line); - int end = pdoc->LineEnd(line); - char *thisLine = CopyRange(start, end); - const char *eol = StringFromEOLMode(pdoc->eolMode); - pdoc->InsertString(end, eol); - pdoc->InsertString(end + istrlen(eol), thisLine, end - start); - delete []thisLine; +void Editor::Duplicate(bool forLine) { + int start = SelectionStart(); + int end = SelectionEnd(); + if (start == end) { + forLine = true; + } + if (forLine) { + int line = pdoc->LineFromPosition(currentPos); + start = pdoc->LineStart(line); + end = pdoc->LineEnd(line); + } + char *text = CopyRange(start, end); + if (forLine) { + const char *eol = StringFromEOLMode(pdoc->eolMode); + pdoc->InsertString(end, eol); + pdoc->InsertString(end + istrlen(eol), text, end - start); + } else { + pdoc->InsertString(end, text, end - start); + } + delete []text; } void Editor::CancelModes() { @@ -4455,7 +4467,10 @@ int Editor::KeyCommand(unsigned int iMessage) { LineTranspose(); break; case SCI_LINEDUPLICATE: - LineDuplicate(); + Duplicate(true); + break; + case SCI_SELECTIONDUPLICATE: + Duplicate(false); break; case SCI_LOWERCASE: ChangeCaseOfSelection(false); @@ -7013,6 +7028,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_LINEENDRECTEXTEND: case SCI_PAGEUPRECTEXTEND: case SCI_PAGEDOWNRECTEXTEND: + case SCI_SELECTIONDUPLICATE: return KeyCommand(iMessage); case SCI_BRACEHIGHLIGHT: diff --git a/src/Editor.h b/src/Editor.h index 6d2cbbdef..0ac6ec917 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -454,7 +454,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void PageMove(int direction, selTypes sel=noSel, bool stuttered = false); void ChangeCaseOfSelection(bool makeUpperCase); void LineTranspose(); - void LineDuplicate(); + void Duplicate(bool forLine); virtual void CancelModes(); void NewLine(); void CursorUpOrDown(int direction, selTypes sel=noSel); diff --git a/src/KeyMap.cxx b/src/KeyMap.cxx index 950916bd0..bfa6e2d78 100644 --- a/src/KeyMap.cxx +++ b/src/KeyMap.cxx @@ -140,7 +140,7 @@ const KeyToCommand KeyMap::MapDefault[] = { {'L', SCI_CSHIFT, SCI_LINEDELETE}, {'T', SCI_CSHIFT, SCI_LINECOPY}, {'T', SCI_CTRL, SCI_LINETRANSPOSE}, - {'D', SCI_CTRL, SCI_LINEDUPLICATE}, + {'D', SCI_CTRL, SCI_SELECTIONDUPLICATE}, {'U', SCI_CTRL, SCI_LOWERCASE}, {'U', SCI_CSHIFT, SCI_UPPERCASE}, {0,0,0}, |