From 5f998b68113dd116c1e938028dddcbcc7425a144 Mon Sep 17 00:00:00 2001 From: Mitchell Foral Date: Wed, 9 Jun 2021 10:51:58 +1000 Subject: Add SCI_PASTERECTANGULAR to insert text like a rectangular paste. --- doc/ScintillaDoc.html | 4 ++++ doc/ScintillaHistory.html | 3 +++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ include/ScintillaMessages.h | 1 + src/Editor.cxx | 9 +++++++++ test/simpleTests.py | 6 ++++++ 7 files changed, 27 insertions(+) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index bae44931d..01ec3e3ad 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -1107,6 +1107,7 @@ struct Sci_TextToFind { SCI_COPYALLOWLINE
SCI_SETPASTECONVERTENDINGS(bool convert)
SCI_GETPASTECONVERTENDINGS → bool
+ SCI_PASTERECTANGULAR(position length, const char *text)

SCI_CUT
@@ -1147,6 +1148,9 @@ struct Sci_TextToFind { SCI_SETEOLMODE. Defaults to true.

+

SCI_PASTERECTANGULAR(position length, const char *text)
+ Pastes the given text into the existing rectangular or empty selection, overwriting any selected text.

+

Error handling

SCI_SETSTATUS(int status)
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 30008fc85..39af707b8 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -585,6 +585,9 @@ and support setting a representation for the "\r\n" line end sequence.
  • + Add SCI_PASTERECTANGULAR to insert text like a rectangular paste. +
  • +
  • Fixed bug with SCI_GETLASTCHILD. Bug #2260.
  • diff --git a/include/Scintilla.h b/include/Scintilla.h index 123f1ae96..c74332dc3 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -885,6 +885,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_PASTERECTANGULAR 2771 #define SCI_SELECTIONDUPLICATE 2469 #define SCI_SETCARETLINEBACKALPHA 2470 #define SCI_GETCARETLINEBACKALPHA 2471 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index dd91bf908..d8e8fc21a 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2439,6 +2439,9 @@ set void SetPasteConvertEndings=2467(bool convert,) # Get convert-on-paste setting get bool GetPasteConvertEndings=2468(,) +# Paste into a rectangular selection. +fun void PasteRectangular=2771(position length, string text) + # Duplicate the selection. If selection empty duplicate the line containing the caret. fun void SelectionDuplicate=2469(,) diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index 6cf515df9..b5792d809 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -581,6 +581,7 @@ enum class Message { ToggleCaretSticky = 2459, SetPasteConvertEndings = 2467, GetPasteConvertEndings = 2468, + PasteRectangular = 2771, SelectionDuplicate = 2469, SetCaretLineBackAlpha = 2470, GetCaretLineBackAlpha = 2471, diff --git a/src/Editor.cxx b/src/Editor.cxx index 6860e153f..3ddd9daae 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5940,6 +5940,15 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { EnsureCaretVisible(); break; + case Message::PasteRectangular: { + UndoGroup ug(pdoc); + if (!sel.Empty()) { + ClearSelection(); // want to replace rectangular selection contents + } + InsertPasteShape(CharPtrFromSPtr(lParam), static_cast(wParam), PasteShape::rectangular); + break; + } + case Message::Clear: Clear(); SetLastXChosen(); diff --git a/test/simpleTests.py b/test/simpleTests.py index 63a752da4..82ed84810 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -535,6 +535,12 @@ class TestSimple(unittest.TestCase): self.ed.Clear() self.assertEquals(self.ed.Contents(), b"1c") + def testPasteRectangular(self): + self.ed.AddText(5, b"a\nb\nc") + self.ed.SetSel(0,0) + self.ed.PasteRectangular(3, b"1\n2") + self.assertEquals(self.ed.Contents(), b"1a\n2b\nc") + def testCopyAllowLine(self): lineEndType = self.ed.EOLMode self.ed.EOLMode = self.ed.SC_EOL_LF -- cgit v1.2.3