help system
[fanfix.git] / src / jexer / TEditorWidget.java
index 9236da2a89a57afd06cd62e3463c800bcd573df2..6ff39e61308b04b2a9171e8e4aaa7517314a8ed3 100644 (file)
@@ -164,8 +164,15 @@ public class TEditorWidget extends TWidget implements EditMenuUser {
 
         if (mouse.isMouse1()) {
             // Selection.
+            int newLine = topLine + mouse.getY();
+            int newX = leftColumn + mouse.getX();
+
             inSelection = true;
-            selectionLine0 = topLine + mouse.getY();
+            if (newLine > document.getLineCount() - 1) {
+                selectionLine0 = document.getLineCount() - 1;
+            } else {
+                selectionLine0 = topLine + mouse.getY();
+            }
             selectionColumn0 = leftColumn + mouse.getX();
             selectionColumn0 = Math.max(0, Math.min(selectionColumn0,
                     document.getLine(selectionLine0).getDisplayLength() - 1));
@@ -173,8 +180,6 @@ public class TEditorWidget extends TWidget implements EditMenuUser {
             selectionLine1 = selectionLine0;
 
             // Set the row and column
-            int newLine = topLine + mouse.getY();
-            int newX = leftColumn + mouse.getX();
             if (newLine > document.getLineCount() - 1) {
                 // Go to the end
                 document.setLineNumber(document.getLineCount() - 1);
@@ -307,6 +312,12 @@ public class TEditorWidget extends TWidget implements EditMenuUser {
                 // Non-shifted navigation keys disable selection.
                 inSelection = false;
             }
+            if ((selectionColumn0 == selectionColumn1)
+                && (selectionLine0 == selectionLine1)
+            ) {
+                // The user clicked a spot and started typing.
+                inSelection = false;
+            }
         }
 
         if (keypress.equals(kbLeft)