summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cb8ac02)
raw | patch | inline | side by side (parent: cb8ac02)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Sun, 5 Feb 2006 21:30:12 +0000 (21:30 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Sun, 5 Feb 2006 21:30:12 +0000 (21:30 +0000) |
src/text-editing.cpp | patch | blob | history |
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index d5a53fc49c5b88482bc050af680a9ee1100094d7..f0cb4bd9da12967f29a32a30863485bc1154a367 100644 (file)
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
}
/** Recursively gets the length of all the SPStrings at or below the given
-\a item. Also adds 1 for each line break encountered. */
+\a item, before and not including \a upto. Also adds 1 for each line break encountered. */
unsigned sp_text_get_length_upto(SPObject const *item, SPObject const *upto)
{
unsigned length = 0;
- if (SP_IS_STRING(item)) return SP_STRING(item)->string.length();
- if (is_line_break_object(item)) length++;
+ if (SP_IS_STRING(item)) {
+ return SP_STRING(item)->string.length();
+ }
+ if (is_line_break_object(item) && !SP_IS_TEXT(item)) {
+ if (item != SP_OBJECT_PARENT(item)->firstChild()) {
+ // add 1 for each newline
+ length++;
+ }
+ }
for (SPObject const *child = item->firstChild() ; child ; child = SP_OBJECT_NEXT(child)) {
- if (child == upto)
+ if (upto && child == upto) {
+ // hit upto, return immediately
return length;
- if (SP_IS_STRING(child)) length += SP_STRING(child)->string.length();
+ }
+ if (SP_IS_STRING(child)) {
+ length += SP_STRING(child)->string.length();
+ }
else {
- if (child->isAncestorOf(upto)) {
- length += sp_text_get_length(child);
+ if (upto && child->isAncestorOf(upto)) {
+ // upto is below us, recurse and break loop
+ length += sp_text_get_length_upto(child, upto);
return length;
} else {
- length += sp_text_get_length(child);
+ // recurse and go to the next sibling
+ length += sp_text_get_length_upto(child, upto);
}
}
}