aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx67
-rw-r--r--src/Editor.h3
2 files changed, 53 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;
diff --git a/src/Editor.h b/src/Editor.h
index dfc25d72d..50aa9a660 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -436,6 +436,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void PasteRectangular(SelectionPosition pos, const char *ptr, Sci::Position len);
virtual void Copy() = 0;
void CopyAllowLine();
+ void CutAllowLine();
virtual bool CanPaste();
virtual void Paste() = 0;
void Clear();
@@ -481,6 +482,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
enum class CaseMapping { same, upper, lower };
virtual std::string CaseMapString(const std::string &s, CaseMapping caseMapping);
void ChangeCaseOfSelection(CaseMapping caseMapping);
+ void LineDelete();
void LineTranspose();
void LineReverse();
void Duplicate(bool forLine);
@@ -515,6 +517,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
std::string RangeText(Sci::Position start, Sci::Position end) const;
+ bool CopyLineRange(SelectionText *ss, bool allowProtected=true);
void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
void CopyRangeToClipboard(Sci::Position start, Sci::Position end);
void CopyText(size_t length, const char *text);