From 4211b1982d752b37abf8c4549d46399b330faa59 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 26 Sep 2013 14:07:33 +1000 Subject: Enhance stability by defining GetLineEndPosition for lines beyond end of document to return document size. --- doc/ScintillaDoc.html | 6 +++--- src/Document.cxx | 2 +- test/simpleTests.py | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 8c7499ed9..f408dafad 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -1306,9 +1306,9 @@ struct Sci_TextToFind {

SCI_GETLINEENDPOSITION(int line)
This returns the position at the end of the line, before any line end characters. If line - is the last line in the document (which does not have any end of line characters), the result is the size of the - document. If line is negative or line >= SCI_GETLINECOUNT(), the result is undefined.

+ is the last line in the document (which does not have any end of line characters) or greater, + the result is the size of the document. + If line is negative the result is undefined.

SCI_LINELENGTH(int line)
This returns the length of the line, including any line end characters. If line diff --git a/src/Document.cxx b/src/Document.cxx index b8ab420fd..78aa22794 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -279,7 +279,7 @@ int SCI_METHOD Document::LineStart(int line) const { } int SCI_METHOD Document::LineEnd(int line) const { - if (line == LinesTotal() - 1) { + if (line >= LinesTotal() - 1) { return LineStart(line + 1); } else { int position = LineStart(line + 1); diff --git a/test/simpleTests.py b/test/simpleTests.py index e814f45ca..03deb566d 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -86,6 +86,12 @@ class TestSimple(unittest.TestCase): self.assertEquals(self.ed.Anchor, 0) self.assertEquals(self.ed.CurrentPos, 1) + def testBeyonEnd(self): + self.ed.AddText(1, b"x") + self.assertEquals(self.ed.GetLineEndPosition(0), 1) + self.assertEquals(self.ed.GetLineEndPosition(1), 1) + self.assertEquals(self.ed.GetLineEndPosition(2), 1) + def testSelection(self): self.assertEquals(self.ed.CurrentPos, 0) self.assertEquals(self.ed.Anchor, 0) -- cgit v1.2.3