diff options
author | nyamatongwe <unknown> | 2005-11-10 00:42:42 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2005-11-10 00:42:42 +0000 |
commit | e43a41c0af5188401ee58bf9b996bde893e9ce75 (patch) | |
tree | 16358314342c9485ad63cd5c09f4444830f85bd5 /src | |
parent | 0cc7d068ca8fb110c4de0886225caf5188b582eb (diff) | |
download | scintilla-mirror-e43a41c0af5188401ee58bf9b996bde893e9ce75.tar.gz |
Added selection duplicate command.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 36 | ||||
-rw-r--r-- | src/Editor.h | 2 | ||||
-rw-r--r-- | src/KeyMap.cxx | 2 |
3 files changed, 28 insertions, 12 deletions
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}, |