From: Kevin Lamonte Date: Wed, 27 Dec 2017 23:36:33 +0000 (-0500) Subject: #25 fix OOB on mouse down X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=4297b49b4f9f66a75d98c0d5e326a471e94cf404;p=fanfix-jexer.git #25 fix OOB on mouse down --- diff --git a/src/jexer/TEditorWidget.java b/src/jexer/TEditorWidget.java index 5ab7a23..dcf5e9e 100644 --- a/src/jexer/TEditorWidget.java +++ b/src/jexer/TEditorWidget.java @@ -164,7 +164,7 @@ public class TEditorWidget extends TWidget { document.setLineNumber(newLine); setCursorY(mouse.getY()); - if (newX > document.getCurrentLine().getDisplayLength()) { + if (newX >= document.getCurrentLine().getDisplayLength()) { document.end(); alignCursor(); } else { diff --git a/src/jexer/teditor/Document.java b/src/jexer/teditor/Document.java index c84c207..e1a28a0 100644 --- a/src/jexer/teditor/Document.java +++ b/src/jexer/teditor/Document.java @@ -185,7 +185,11 @@ public class Document { * @param cursor the new cursor position */ public void setCursor(final int cursor) { - lines.get(lineNumber).setCursor(cursor); + if (cursor >= lines.get(lineNumber).getDisplayLength()) { + lines.get(lineNumber).end(); + } else { + lines.get(lineNumber).setCursor(cursor); + } } /** @@ -215,7 +219,7 @@ public class Document { if (lineNumber < lines.size() - 1) { int x = lines.get(lineNumber).getCursor(); lineNumber++; - if (x > lines.get(lineNumber).getDisplayLength()) { + if (x >= lines.get(lineNumber).getDisplayLength()) { lines.get(lineNumber).end(); } else { lines.get(lineNumber).setCursor(x); @@ -239,7 +243,7 @@ public class Document { if (lineNumber > lines.size() - 1) { lineNumber = lines.size() - 1; } - if (x > lines.get(lineNumber).getDisplayLength()) { + if (x >= lines.get(lineNumber).getDisplayLength()) { lines.get(lineNumber).end(); } else { lines.get(lineNumber).setCursor(x); @@ -258,7 +262,7 @@ public class Document { if (lineNumber > 0) { int x = lines.get(lineNumber).getCursor(); lineNumber--; - if (x > lines.get(lineNumber).getDisplayLength()) { + if (x >= lines.get(lineNumber).getDisplayLength()) { lines.get(lineNumber).end(); } else { lines.get(lineNumber).setCursor(x); @@ -282,7 +286,7 @@ public class Document { if (lineNumber < 0) { lineNumber = 0; } - if (x > lines.get(lineNumber).getDisplayLength()) { + if (x >= lines.get(lineNumber).getDisplayLength()) { lines.get(lineNumber).end(); } else { lines.get(lineNumber).setCursor(x);