Skip to content

Commit 4d8e5f9

Browse files
committed
Fix for DebugStyledText errors resulting from a negative cursor position.
1 parent a12d7e9 commit 4d8e5f9

File tree

1 file changed

+14
-9
lines changed
  • brailleblaster-core/src/main/java/org/brailleblaster/perspectives/braille/views/wp

1 file changed

+14
-9
lines changed

brailleblaster-core/src/main/java/org/brailleblaster/perspectives/braille/views/wp/BrailleView.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ class BrailleView(manager: Manager, sash: Composite) : WPView(manager, sash) {
250250
val arr = getIndexArray(e)
251251
if (arr == null) {
252252
pos = if (lastPositon == 0) stateObj.currentStart else stateObj.currentEnd
253-
} else {
254-
if (lastPositon < 0 && stateObj.currentStart > 0)
253+
}
254+
else {
255+
if (lastPositon < 0 && stateObj.currentStart > 0) {
255256
pos = stateObj.currentStart + lastPositon
256-
else if (lastPositon == 99999)
257+
}
258+
else if (lastPositon == 99999) {
257259
pos = stateObj.currentEnd + offsetFromTMEStart
260+
}
258261
else {
259262
pos = stateObj.currentStart + findCurrentPosition(arr, offsetFromTMEStart)
260263
pos += plusLineBreaks(stateObj.currentStart, pos)
@@ -263,11 +266,11 @@ class BrailleView(manager: Manager, sash: Composite) : WPView(manager, sash) {
263266
}
264267
if (pos <= view.charCount) {
265268
/*
266-
* RT4647
267-
* check line break on windows gets the line from offset from the view.
268-
* this can be called with a position > the charcount due to a blank page
269-
* with a pagenum at the bottom at the end of the document and throw an exception
270-
*/
269+
* RT4647
270+
* check line break on windows gets the line from offset from the view.
271+
* this can be called with a position > the charcount due to a blank page
272+
* with a pagenum at the bottom at the end of the document and throw an exception
273+
*/
271274
if (checkLineBreakOnWindows(pos)) pos++
272275
}
273276
view.caretOffset = pos
@@ -306,7 +309,9 @@ class BrailleView(manager: Manager, sash: Composite) : WPView(manager, sash) {
306309

307310
private fun findCurrentPosition(indexes: IntArray, textPos: Int): Int {
308311
for (i in indexes.indices) {
309-
if (textPos == indexes[i]) return i else if (textPos < indexes[i]) return i - 1
312+
if (textPos == indexes[i]) return i
313+
else if (textPos < indexes[i]) return (i - 1).coerceAtLeast(0)
314+
//Don't return -1, this causes DebugStyledText to throw exceptions and messes up cursor position
310315
}
311316
return indexes.size
312317
}

0 commit comments

Comments
 (0)