X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fteditor%2FDocument.java;h=e1a28a0d37f39504c482da627c880110e3d1a9d8;hb=0525b2ed026e0d510fdf23f6d8f4cb4562a17e0b;hp=c8ab746096f20971871fe8da99efbe67dd4fcade;hpb=df602ccf5e32585c26dc618dd3b4a759b6820943;p=nikiroo-utils.git diff --git a/src/jexer/teditor/Document.java b/src/jexer/teditor/Document.java index c8ab746..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); @@ -456,4 +460,13 @@ public class Document { return n; } + /** + * Get the current line length. + * + * @return the number of cells needed to display the current line + */ + public int getLineLength() { + return lines.get(lineNumber).getDisplayLength(); + } + }