[haiku-commits] haiku: hrev46745 - src/apps/haiku-depot/textview

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 22 Jan 2014 23:19:45 +0100 (CET)

hrev46745 adds 2 changesets to branch 'master'
old head: 433f08a481572e1bfaccc01dc6ecd34733c2f185
new head: 000c26330bf4ec8be161a7dc2433981efd3d3e01
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=000c263+%5E433f08a

----------------------------------------------------------------------------

937ad5c: ParagraphLayout: Off-by-one error in LastOffsetOnLine()

000c263: TextDocumentLayout: First/LastOffsetOnLine() forgot to convert...
  
  ... back from paragraph local offsets to document global offsets.

                                      [ Stephan Aßmus <superstippi@xxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 16 insertions(+), 8 deletions(-)
src/apps/haiku-depot/textview/ParagraphLayout.cpp  |  3 ++-
.../haiku-depot/textview/TextDocumentLayout.cpp    | 18 ++++++++++++------
src/apps/haiku-depot/textview/TextDocumentLayout.h |  3 ++-

############################################################################

Commit:      937ad5c6b87c3c8f3008781471a6dbc6d815aa34
URL:         http://cgit.haiku-os.org/haiku/commit/?id=937ad5c
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Wed Jan 22 22:17:48 2014 UTC

ParagraphLayout: Off-by-one error in LastOffsetOnLine()

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/textview/ParagraphLayout.cpp 
b/src/apps/haiku-depot/textview/ParagraphLayout.cpp
index 4d49ba6..107a606 100644
--- a/src/apps/haiku-depot/textview/ParagraphLayout.cpp
+++ b/src/apps/haiku-depot/textview/ParagraphLayout.cpp
@@ -328,8 +328,9 @@ ParagraphLayout::LastOffsetOnLine(int32 lineIndex)
 
        if (lineIndex < 0)
                lineIndex = 0;
+
        if (lineIndex >= fLineInfos.CountItems() - 1)
-               return CountGlyphs();
+               return CountGlyphs() - 1;
 
        return fLineInfos.ItemAt(lineIndex + 1).textOffset - 1;
 }

############################################################################

Revision:    hrev46745
Commit:      000c26330bf4ec8be161a7dc2433981efd3d3e01
URL:         http://cgit.haiku-os.org/haiku/commit/?id=000c263
Author:      Stephan Aßmus <superstippi@xxxxxx>
Date:        Wed Jan 22 22:18:26 2014 UTC

TextDocumentLayout: First/LastOffsetOnLine() forgot to convert...

... back from paragraph local offsets to document global offsets.

----------------------------------------------------------------------------

diff --git a/src/apps/haiku-depot/textview/TextDocumentLayout.cpp 
b/src/apps/haiku-depot/textview/TextDocumentLayout.cpp
index fc60ac0..93bee56 100644
--- a/src/apps/haiku-depot/textview/TextDocumentLayout.cpp
+++ b/src/apps/haiku-depot/textview/TextDocumentLayout.cpp
@@ -169,10 +169,11 @@ TextDocumentLayout::LineIndexForOffset(int32 textOffset)
 int32
 TextDocumentLayout::FirstOffsetOnLine(int32 lineIndex)
 {
-       int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex);
+       int32 paragraphOffset;
+       int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex, 
paragraphOffset);
        if (index >= 0) {
                const ParagraphLayoutInfo& info = 
fParagraphLayouts.ItemAtFast(index);
-               return info.layout->FirstOffsetOnLine(lineIndex);
+               return info.layout->FirstOffsetOnLine(lineIndex) + 
paragraphOffset;
        }
 
        return 0;
@@ -182,10 +183,11 @@ TextDocumentLayout::FirstOffsetOnLine(int32 lineIndex)
 int32
 TextDocumentLayout::LastOffsetOnLine(int32 lineIndex)
 {
-       int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex);
+       int32 paragraphOffset;
+       int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex, 
paragraphOffset);
        if (index >= 0) {
                const ParagraphLayoutInfo& info = 
fParagraphLayouts.ItemAtFast(index);
-               return info.layout->LastOffsetOnLine(lineIndex);
+               return info.layout->LastOffsetOnLine(lineIndex) + 
paragraphOffset;
        }
 
        return 0;
@@ -213,7 +215,8 @@ void
 TextDocumentLayout::GetLineBounds(int32 lineIndex, float& x1, float& y1,
        float& x2, float& y2)
 {
-       int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex);
+       int32 paragraphOffset;
+       int32 index = _ParagraphLayoutIndexForLineIndex(lineIndex, 
paragraphOffset);
        if (index >= 0) {
                const ParagraphLayoutInfo& info = 
fParagraphLayouts.ItemAtFast(index);
                info.layout->GetLineBounds(lineIndex, x1, y1, x2, y2);
@@ -349,10 +352,12 @@ TextDocumentLayout::_ParagraphLayoutIndexForOffset(int32& 
textOffset)
 }
 
 int32
-TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex)
+TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex,
+       int32& paragraphOffset)
 {
        _ValidateLayout();
 
+       paragraphOffset = 0;
        int32 paragraphs = fParagraphLayouts.CountItems();
        for (int32 i = 0; i < paragraphs; i++) {
                const ParagraphLayoutInfo& info = 
fParagraphLayouts.ItemAtFast(i);
@@ -360,6 +365,7 @@ 
TextDocumentLayout::_ParagraphLayoutIndexForLineIndex(int32& lineIndex)
                int32 lineCount = info.layout->CountLines();
                if (lineIndex >= lineCount) {
                        lineIndex -= lineCount;
+                       paragraphOffset += info.layout->CountGlyphs();
                        continue;
                }
                
diff --git a/src/apps/haiku-depot/textview/TextDocumentLayout.h 
b/src/apps/haiku-depot/textview/TextDocumentLayout.h
index 89c5111..b7bcb86 100644
--- a/src/apps/haiku-depot/textview/TextDocumentLayout.h
+++ b/src/apps/haiku-depot/textview/TextDocumentLayout.h
@@ -116,7 +116,8 @@ private:
                        int32                           
_ParagraphLayoutIndexForOffset(
                                                                        int32& 
textOffset);
                        int32                           
_ParagraphLayoutIndexForLineIndex(
-                                                                       int32& 
lineIndex);
+                                                                       int32& 
lineIndex,
+                                                                       int32& 
paragraphOffset);
 
 private:
                        float                           fWidth;


Other related posts:

  • » [haiku-commits] haiku: hrev46745 - src/apps/haiku-depot/textview - superstippi