diff options
author | Martijn Laan <1092369+martijnlaan@users.noreply.github.com> | 2024-06-20 08:23:46 +1000 |
---|---|---|
committer | Martijn Laan <1092369+martijnlaan@users.noreply.github.com> | 2024-06-20 08:23:46 +1000 |
commit | 4040c66fc31c7e537d063c65ed1e734e974250c2 (patch) | |
tree | a19d212bcf90ba998d282f047741bc214598c64e /src/Editor.cxx | |
parent | eee34c2c5053450ec48aea8a9cbff4d5dd140b55 (diff) | |
download | scintilla-mirror-4040c66fc31c7e537d063c65ed1e734e974250c2.tar.gz |
Feature [feature-requests:#1518]. Cherry pick SCI_CUTALLOWLINE from isscint.
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r-- | src/Editor.cxx | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 1bcaca2ef..12150dcda 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2267,6 +2267,21 @@ void Editor::CopyAllowLine() { CopyToClipboard(selectedText); } +void Editor::CutAllowLine() { + if (sel.Empty()) { + pdoc->CheckReadOnly(); + if (!pdoc->IsReadOnly()) { + SelectionText selectedText; + if (CopyLineRange(&selectedText, false)) { + CopyToClipboard(selectedText); + LineDelete(); + } + } + } else { + Cut(); + } +} + void Editor::Cut() { pdoc->CheckReadOnly(); if (!pdoc->IsReadOnly() && !SelectionContainsProtected()) { @@ -2959,6 +2974,7 @@ void Editor::NotifyMacroRecord(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::PageDownRectExtend: case Message::SelectionDuplicate: case Message::CopyAllowLine: + case Message::CutAllowLine: case Message::VerticalCentreCaret: case Message::MoveSelectedLinesUp: case Message::MoveSelectedLinesDown: @@ -3081,6 +3097,13 @@ void Editor::ChangeCaseOfSelection(CaseMapping caseMapping) { } } +void Editor::LineDelete() { + const Sci::Line line = pdoc->SciLineFromPosition(sel.MainCaret()); + const Sci::Position start = pdoc->LineStart(line); + const Sci::Position end = pdoc->LineStart(line + 1); + pdoc->DeleteChars(start, end - start); +} + void Editor::LineTranspose() { const Sci::Line line = pdoc->SciLineFromPosition(sel.MainCaret()); if (line > 0) { @@ -3991,12 +4014,8 @@ int Editor::KeyCommand(Message iMessage) { SetLastXChosen(); } break; - case Message::LineDelete: { - const Sci::Line line = pdoc->SciLineFromPosition(sel.MainCaret()); - const Sci::Position start = pdoc->LineStart(line); - const Sci::Position end = pdoc->LineStart(line + 1); - pdoc->DeleteChars(start, end - start); - } + case Message::LineDelete: + LineDelete(); break; case Message::LineTranspose: LineTranspose(); @@ -4316,20 +4335,29 @@ std::string Editor::RangeText(Sci::Position start, Sci::Position end) const { return std::string(); } +bool Editor::CopyLineRange(SelectionText *ss, bool allowProtected) { + const Sci::Line currentLine = pdoc->SciLineFromPosition(sel.MainCaret()); + const Sci::Position start = pdoc->LineStart(currentLine); + const Sci::Position end = pdoc->LineEnd(currentLine); + + if (allowProtected || !RangeContainsProtected(start, end)) { + std::string text = RangeText(start, end); + if (pdoc->eolMode != EndOfLine::Lf) + text.push_back('\r'); + if (pdoc->eolMode != EndOfLine::Cr) + text.push_back('\n'); + ss->Copy(text, pdoc->dbcsCodePage, + vs.styles[StyleDefault].characterSet, false, true); + return true; + } else { + return false; + } +} + void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { if (sel.Empty()) { if (allowLineCopy) { - const Sci::Line currentLine = pdoc->SciLineFromPosition(sel.MainCaret()); - const Sci::Position start = pdoc->LineStart(currentLine); - const Sci::Position end = pdoc->LineEnd(currentLine); - - std::string text = RangeText(start, end); - if (pdoc->eolMode != EndOfLine::Lf) - text.push_back('\r'); - if (pdoc->eolMode != EndOfLine::Cr) - text.push_back('\n'); - ss->Copy(text, pdoc->dbcsCodePage, - vs.styles[StyleDefault].characterSet, false, true); + CopyLineRange(ss); } } else { std::string text; @@ -6183,6 +6211,11 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { CopyAllowLine(); break; + case Message::CutAllowLine: + CutAllowLine(); + SetLastXChosen(); + break; + case Message::VerticalCentreCaret: VerticalCentreCaret(); break; |