*
* The MIT License (MIT)
*
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*/
public class Document {
+ // ------------------------------------------------------------------------
+ // Variables --------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* The list of lines.
*/
*/
private Highlighter highlighter = new Highlighter();
+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Construct a new Document from an existing text string.
+ *
+ * @param str the text string
+ * @param defaultColor the color for unhighlighted text
+ */
+ public Document(final String str, final CellAttributes defaultColor) {
+ this.defaultColor = defaultColor;
+
+ // TODO: set different colors based on file extension
+ highlighter.setJavaColors();
+
+ String [] rawLines = str.split("\n");
+ for (int i = 0; i < rawLines.length; i++) {
+ lines.add(new Line(rawLines[i], this.defaultColor, highlighter));
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Document ---------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* Get the overwrite flag.
*
* @param cursor the new cursor position
*/
public void setCursor(final int cursor) {
- lines.get(lineNumber).setCursor(cursor);
- }
-
- /**
- * Construct a new Document from an existing text string.
- *
- * @param str the text string
- * @param defaultColor the color for unhighlighted text
- */
- public Document(final String str, final CellAttributes defaultColor) {
- this.defaultColor = defaultColor;
-
- // TODO: set different colors based on file extension
- highlighter.setJavaColors();
-
- String [] rawLines = str.split("\n");
- for (int i = 0; i < rawLines.length; i++) {
- lines.add(new Line(rawLines[i], this.defaultColor, highlighter));
+ if (cursor >= lines.get(lineNumber).getDisplayLength()) {
+ lines.get(lineNumber).end();
+ } else {
+ lines.get(lineNumber).setCursor(cursor);
}
}
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);
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);
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);
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);