diff options
author | pspjuth <peter.spjuth@gmail.com> | 2012-08-26 17:07:19 (GMT) |
---|---|---|
committer | pspjuth <peter.spjuth@gmail.com> | 2012-08-26 17:07:19 (GMT) |
commit | 2c2a2e6522dcfc11aaa8017b47bc14485313349b (patch) | |
tree | d0cf2a1e6e56525333957dd5fe2aab36bf174a4c /generic/tkTextBTree.c | |
parent | fc0e57edc8cb5ad99ea9540032237367f8b0a777 (diff) | |
parent | e4c7ef5bdf6375e1860418b1ec92c07f88660cc8 (diff) | |
download | tk-pspjuth_canvas.zip tk-pspjuth_canvas.tar.gz tk-pspjuth_canvas.tar.bz2 |
merge trunkpspjuth_canvas
Diffstat (limited to 'generic/tkTextBTree.c')
-rw-r--r-- | generic/tkTextBTree.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c index 925fcc4..e34dae7 100644 --- a/generic/tkTextBTree.c +++ b/generic/tkTextBTree.c @@ -10,8 +10,6 @@ * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. - * - * RCS: @(#) $Id: tkTextBTree.c,v 1.32 2010/11/19 14:48:00 nijtmans Exp $ */ #include "tkInt.h" @@ -660,12 +658,12 @@ AdjustStartEndRefs( if (textPtr->start != NULL) { count--; treePtr->startEnd[count] = textPtr->start; - treePtr->startEndRef[count] = treePtr->sharedTextPtr->peers; + treePtr->startEndRef[count] = textPtr; } if (textPtr->end != NULL) { count--; treePtr->startEnd[count] = textPtr->end; - treePtr->startEndRef[count] = treePtr->sharedTextPtr->peers; + treePtr->startEndRef[count] = textPtr; } } } @@ -1608,7 +1606,7 @@ TkBTreeFindLine( } /* - * Check for the any start/end offset for this text widget. + * Check for any start/end offset for this text widget. */ if (textPtr != NULL) { @@ -1990,12 +1988,37 @@ TkBTreeLinesTo( index += nodePtr2->numLines; } } - if (textPtr != NULL && textPtr->start != NULL) { - index -= TkBTreeLinesTo(NULL, textPtr->start); + if (textPtr != NULL) { + /* + * The index to return must be relative to textPtr, not to the entire + * tree. Take care to never return a negative index when linePtr + * denotes a line before -startline, or an index larger than the + * number of lines in textPtr when linePtr is a line past -endline. + */ + + int indexStart, indexEnd; + + if (textPtr->start != NULL) { + indexStart = TkBTreeLinesTo(NULL, textPtr->start); + } else { + indexStart = 0; + } + if (textPtr->end != NULL) { + indexEnd = TkBTreeLinesTo(NULL, textPtr->end); + } else { + indexEnd = TkBTreeNumLines(textPtr->sharedTextPtr->tree, NULL); + } + if (index < indexStart) { + index = 0; + } else if (index > indexEnd) { + index = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr); + } else { + index -= indexStart; + } } return index; } - + /* *---------------------------------------------------------------------- * |