*** flat_review.py	2006-11-07 14:14:01.000000000 -0500
--- orca/src/orca/flat_review.py	2006-12-03 15:44:39.000000000 -0500
***************
*** 434,449 ****
              zoneIndex   = currentZoneIndex
              caretOffset = zone.accessible.text.caretOffset
              foundZoneWithCaret = False
              while lineIndex < len(self.lines):
                  line = self.lines[lineIndex]
                  while zoneIndex < len(line.zones):
                      zone = line.zones[zoneIndex]
                      if zone.accessible == accessible:
!                         if (caretOffset >= zone.startOffset) \
!                                and (caretOffset \
                                      < (zone.startOffset + zone.length)):
!                             foundZoneWithCaret = True
!                             break
                      zoneIndex += 1
                  if foundZoneWithCaret:
                      currentLineIndex = lineIndex
--- 434,455 ----
              zoneIndex   = currentZoneIndex
              caretOffset = zone.accessible.text.caretOffset
              foundZoneWithCaret = False
+             checkForEOF = False
              while lineIndex < len(self.lines):
                  line = self.lines[lineIndex]
                  while zoneIndex < len(line.zones):
                      zone = line.zones[zoneIndex]
                      if zone.accessible == accessible:
!                         if (caretOffset >= zone.startOffset):
!                             if (caretOffset \
                                      < (zone.startOffset + zone.length)):
!                                 foundZoneWithCaret = True
!                                 break
!                             elif (caretOffset \
!                                     == (zone.startOffset + zone.length)):
!                                 checkForEOF = True
!                                 lineToCheck = lineIndex
!                                 zoneToCheck = zoneIndex
                      zoneIndex += 1
                  if foundZoneWithCaret:
                      currentLineIndex = lineIndex
***************
*** 463,468 ****
--- 469,487 ----
                  else:
                      zoneIndex = 0
                      lineIndex += 1
+             atEOF = not foundZoneWithCaret and checkForEOF
+             if atEOF:
+                 # JD - HACK: The caret is on a character to which we
+                 # cannot flat review. Set wordIndex to be one greater
+                 # than the wordIndex of the final word in this zone.
+                 # Then be sure that getCurrent handles it appropriately.
+                 #
+                 line = self.lines[lineToCheck]
+                 zone = line.zones[zoneToCheck]
+                 currentLineIndex = lineToCheck
+                 currentZoneIndex = zoneToCheck
+                 currentWordIndex = len(zone.words)
+                 currentCharIndex = 0
  
          self.lineIndex = currentLineIndex
          self.zoneIndex = currentZoneIndex
***************
*** 1193,1208 ****
              if isinstance(zone, TextZone):
                  words = zone.words
                  if words:
!                     chars = zone.words[self.wordIndex].chars
!                     if chars:
                          char = chars[self.charIndex]
                          return [char.string,
                                  char.x,
                                  char.y,
                                  char.width,
                                  char.height]
                      else:
-                         word = words[self.wordIndex]
                          return [word.string,
                                  word.x,
                                  word.y,
--- 1212,1232 ----
              if isinstance(zone, TextZone):
                  words = zone.words
                  if words:
!                     try:
!                         word = words[self.wordIndex]
!                         chars = word.chars
                          char = chars[self.charIndex]
+                     except:
+                         word = words[self.wordIndex-1]
+                         chars = word.chars
+                         char = chars[word.length-1]
+                     if char:
                          return [char.string,
                                  char.x,
                                  char.y,
                                  char.width,
                                  char.height]
                      else:
                          return [word.string,
                                  word.x,
                                  word.y,
***************
*** 1213,1219 ****
              if isinstance(zone, TextZone):
                  words = zone.words
                  if words:
!                     word = words[self.wordIndex]
                      return [word.string,
                              word.x,
                              word.y,
--- 1237,1246 ----
              if isinstance(zone, TextZone):
                  words = zone.words
                  if words:
!                     try:
!                         word = words[self.wordIndex]
!                     except:
!                         word = words[self.wordIndex-1]
                      return [word.string,
                              word.x,
                              word.y,
***************
*** 1505,1518 ****
          elif type == Context.CHAR:
              zone = self.lines[self.lineIndex].zones[self.zoneIndex]
              if zone.words:
!                 chars = zone.words[self.wordIndex].chars
!                 if chars:
!                     if self.charIndex < (len(chars) - 1):
!                         self.charIndex += 1
!                         moved = True
!                     else:
!                         moved = self.goNext(Context.WORD, wrap, False)
!                 else:
                      moved = self.goNext(Context.WORD, wrap)
              else:
                  moved = self.goNext(Context.ZONE, wrap)
--- 1532,1548 ----
          elif type == Context.CHAR:
              zone = self.lines[self.lineIndex].zones[self.zoneIndex]
              if zone.words:
!                 try:
!                     word = zone.words[self.wordIndex]
!                     chars = word.chars
!                     char = chars[self.charIndex]
!                     if chars:
!                         if self.charIndex < (len(chars) - 1):
!                             self.charIndex += 1
!                             moved = True
!                         else:
!                             moved = self.goNext(Context.WORD, wrap, False)
!                 except:
                      moved = self.goNext(Context.WORD, wrap)
              else:
                  moved = self.goNext(Context.ZONE, wrap)
