diff options
-rw-r--r-- | doc/ScintillaDoc.html | 24 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 17 | ||||
-rw-r--r-- | src/Editor.cxx | 23 | ||||
-rw-r--r-- | test/simpleTests.py | 2 |
4 files changed, 38 insertions, 28 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 77412022a..e54059624 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -128,7 +128,7 @@ <h1>Scintilla Documentation</h1> - <p>Last edited 21 October 2021 ZL</p> + <p>Last edited 12 November 2021 NH</p> <p style="background:#90F0C0">Scintilla 5 has moved the lexers from Scintilla into a new <a href="Lexilla.html">Lexilla</a> project.<br /> @@ -551,12 +551,12 @@ </code> <p><b id="SCI_GETTEXT">SCI_GETTEXT(position length, char *text NUL-terminated) → position</b><br /> - This returns at most <code class="parameter">length</code>-1 characters of text from the start of the document plus one - terminating 0 character. When <code class="parameter">length</code>-1 is beyond document length, it returns document length. + This returns at most <code class="parameter">length</code> characters of text from the start of the document plus one + terminating 0 character. When <code class="parameter">length</code> is beyond document length, it returns document length. To collect all the text in a document, use <code>SCI_GETLENGTH</code> to get the number of characters in the document (<code>nLen</code>), allocate a character - buffer of length <code>nLen+1</code> bytes, then call <code>SCI_GETTEXT(nLen+1, char - *text)</code>. If the text argument is 0 then the length that should be allocated to store the + buffer of length <code>nLen+1</code> bytes, then call <code>SCI_GETTEXT(nLen, char + *text)</code>. If the text argument is NULL(0) then the length that should be allocated to store the entire document is returned. If you then save the text, you should use <code>SCI_SETSAVEPOINT</code> to mark the text as unmodified.</p> @@ -586,7 +586,7 @@ <p><b id="SCI_GETLINE">SCI_GETLINE(line line, char *text) → position</b><br /> This fills the buffer defined by text with the contents of the nominated line (lines start at - 0). The buffer is not terminated by a 0 character. It is up to you to make sure that the buffer + 0). The buffer is not terminated by a NUL(0) character. It is up to you to make sure that the buffer is long enough for the text, use <a class="message" href="#SCI_LINELENGTH"><code>SCI_LINELENGTH(line line)</code></a>. The returned value is the number of characters copied to the buffer. The returned text includes any end of line @@ -1499,9 +1499,9 @@ struct Sci_TextToFind { href="#SCI_POSITIONFROMLINE"><code>SCI_POSITIONFROMLINE(line)</code></a>.</p> <p><b id="SCI_GETSELTEXT">SCI_GETSELTEXT(<unused>, char *text NUL-terminated) → position</b><br /> - This copies the currently selected text and a terminating 0 byte to the <code class="parameter">text</code> - buffer. The buffer size should be determined by calling with a NULL pointer for the <code class="parameter">text</code> argument - <code>SCI_GETSELTEXT(0,0)</code>. + This copies the currently selected text and a terminating NUL(0) byte to the <code class="parameter">text</code> + buffer. The buffer size should be determined by calling with a NULL pointer for the <code class="parameter">text</code> argument: + <code>1 + SCI_GETSELTEXT(0, NULL)</code>. This allows for rectangular and discontiguous selections as well as simple selections. See <a class="toc" href="#MultipleSelectionAndVirtualSpace">Multiple Selection</a> for information on how multiple and rectangular selections and virtual space are copied.</p> @@ -1516,10 +1516,10 @@ struct Sci_TextToFind { <p><b id="SCI_GETCURLINE">SCI_GETCURLINE(position length, char *text NUL-terminated) → position</b><br /> This retrieves the text of the line containing the caret and returns the position within the line of the caret. Pass in <code>char* text</code> pointing at a buffer large enough to hold - the text you wish to retrieve and a terminating 0 character. + the text you wish to retrieve and a terminating NUL(0) character. Set <code class="parameter">length</code> to the - length of the buffer which must be at least 1 to hold the terminating 0 character. - If the text argument is 0 then the length that should be allocated + length of the buffer not including the terminating NUL character. + If the text argument is NULL(0) then the length that should be allocated to store the entire current line is returned.</p> <p>See also: <code><a class="seealso" href="#SCI_GETSELTEXT">SCI_GETSELTEXT</a>, <a diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index fffc70be0..c0d9f4e6b 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -568,6 +568,23 @@ </table> <h2>Releases</h2> <h3> + <a href="https://www.scintilla.org/scintilla515.zip">Release 5.1.5</a> + </h3> + <ul> + <li> + Released 8 November 2021. + </li> + <li> + When calling SCI_GETTEXT, SCI_GETSELTEXT, and SCI_GETCURLINE with a NULL buffer argument + to discover the length that should be allocated, do not include the terminating NUL in the returned value. + The value returned is 1 less than previous versions of Scintilla. + Applications should allocate a buffer 1 more than this to accommodate the NUL. + The wParam (length) argument to SCI_GETTEXT and SCI_GETCURLINE also omits the NUL. + This is more consistent with other APIs. + </li> + <ul> + <h2>Releases</h2> + <h3> <a href="https://www.scintilla.org/scintilla514.zip">Release 5.1.4</a> </h3> <ul> diff --git a/src/Editor.cxx b/src/Editor.cxx index b918f1be3..a47c9ce0d 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5888,11 +5888,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetText: { if (lParam == 0) - return pdoc->Length() + 1; - if (wParam == 0) - return 0; + return pdoc->Length(); char *ptr = CharPtrFromSPtr(lParam); - const Sci_Position len = std::min<Sci_Position>(wParam - 1, pdoc->Length()); + const Sci_Position len = std::min<Sci_Position>(wParam, pdoc->Length()); pdoc->GetCharRange(ptr, 0, len); ptr[len] = '\0'; return len; @@ -6033,20 +6031,16 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetSelText: { SelectionText selectedText; CopySelectionRange(&selectedText); - if (lParam == 0) { - return selectedText.LengthWithTerminator(); - } else { + if (lParam) { char *ptr = CharPtrFromSPtr(lParam); size_t iChar = selectedText.Length(); if (iChar) { memcpy(ptr, selectedText.Data(), iChar); - ptr[iChar++] = '\0'; - } else { - ptr[0] = '\0'; } - return iChar; + ptr[iChar] = '\0'; } - } + return selectedText.Length(); + } case Message::LineFromPosition: if (PositionFromUPtr(wParam) < 0) @@ -6554,11 +6548,10 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { const Sci::Position lineStart = pdoc->LineStart(lineCurrentPos); const Sci::Position lineEnd = pdoc->LineStart(lineCurrentPos + 1); if (lParam == 0) { - return 1 + lineEnd - lineStart; + return lineEnd - lineStart; } - PLATFORM_ASSERT(wParam > 0); char *ptr = CharPtrFromSPtr(lParam); - const Sci::Position len = std::min<uptr_t>(lineEnd - lineStart, wParam - 1); + const Sci::Position len = std::min<uptr_t>(lineEnd - lineStart, wParam); pdoc->GetCharRange(ptr, lineStart, len); ptr[len] = '\0'; return sel.MainCaret() - lineStart; diff --git a/test/simpleTests.py b/test/simpleTests.py index 1761b2e07..71c35e8d0 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -128,7 +128,7 @@ class TestSimple(unittest.TestCase): self.assertEquals(self.ed.SelectionStart, 1) self.assertEquals(self.ed.SelectionEnd, 3) result = self.ed.GetSelText(0) - self.assertEquals(result, b"bc\0") + self.assertEquals(result, b"bc") self.ed.ReplaceSel(0, b"1234") self.assertEquals(self.ed.Length, 6) self.assertEquals(self.ed.Contents(), b"a1234d") |