|
From: SVN by r. <sv...@ca...> - 2008-02-19 20:02:29
|
Author: roy
Date: 2008-02-19 21:02:17 +0100 (Tue, 19 Feb 2008)
New Revision: 238
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
navigation fixes (end/home)
updates to ctrl-u
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-15 14:43:21 UTC (rev 237)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-19 20:02:17 UTC (rev 238)
@@ -241,21 +241,28 @@
});
actionKeys.put(Integer.toString(InputChar.KEY_END),new KeyAction() {
public void execute() {
- cursorPosition.y = commandLines.getLines().size()-1;
- CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
- cursorPosition.x = lineBuffer.length();
+ int curLineEnd = commandLines.getLines().get(cursorPosition.y).length();
+ if (cursorPosition.x == curLineEnd) {
+ cursorPosition.y = commandLines.getLines().size()-1;
+ CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
+ cursorPosition.x = lineBuffer.length();
+ } else {
+ cursorPosition.x = curLineEnd;
+ }
}
public CharSequence getHelp() {
- return "End:\tMove the cursor to the end of the command";
+ return "End:\tMove the cursor to the end of the line, of if already there at the end of the command";
}
});
actionKeys.put(Integer.toString(InputChar.KEY_HOME), new KeyAction() {
public void execute() {
- cursorPosition.y = 0;
+ if (cursorPosition.x == 0) {
+ cursorPosition.y = 0;
+ }
cursorPosition.x = 0;
}
public CharSequence getHelp() {
- return "Home:\tMove the cursor to the start of the command";
+ return "End:\tMove the cursor to the start of the line, of if already there at the start of the command";
}
});
actionKeys.put("", new KeyAction() {
@@ -271,9 +278,19 @@
});
actionKeys.put("", new KeyAction() { // ctrl+u
public void execute() {
- StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
- lineBuffer.delete(0, cursorPosition.x);
- cursorPosition.x = 0;
+ if (cursorPosition.x > 0) {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ lineBuffer.delete(0, cursorPosition.x);
+ cursorPosition.x = 0;
+ } else if (cursorPosition.y > 0) {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ if (lineBuffer.length() == 0) {
+ commandLines.getEditableLines().remove(cursorPosition.y);
+ }
+ cursorPosition.y--;
+ lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ lineBuffer.delete(0, lineBuffer.length());
+ }
}
public CharSequence getHelp() {
return "Control-U:\tRemove all characters before the cursor position";
|