From: SVN by r. <sv...@ca...> - 2008-07-27 11:27:41
|
Author: roy Date: 2008-07-27 13:27:29 +0200 (Sun, 27 Jul 2008) New Revision: 269 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java src/main/java/nl/improved/sqlclient/SQLUtil.java Log: fixes in 'autobreak' to nextline code Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-07-23 20:57:12 UTC (rev 268) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-07-27 11:27:29 UTC (rev 269) @@ -503,6 +503,7 @@ if (currentLine.length() > MAX_LINE_LENGTH) { // TODO search for lastspace that is not between '' ?? int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" "); + int lastChar = currentLine.charAt(lastSpace); if (lastSpace == -1) { lastSpace = currentLine.length(); } @@ -522,16 +523,20 @@ // fetch the next line StringBuilder nextLine = editableLines.get(cursorPosition.y+1); // if the nextline already has some text.. add a space in front of it - if (nextLine.length() > 0) { + // if there is not already a 'breaking character' there + if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) { nextLine.insert(0, ' '); } // insert the new text at the beginning - nextLine.insert(0, currentLine.subSequence(lastSpace+1, currentLine.length())); + nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length())); currentLine.delete(lastSpace, currentLine.length()); + if (lastChar == ' ') { + nextLine.deleteCharAt(0); + } // check if the cursor postition > the new line length // calculate new x and go to nextline if (cursorPosition.x >= lastSpace) { - cursorPosition.x = cursorPosition.x - (lastSpace+1); + cursorPosition.x = cursorPosition.x - (lastSpace); cursorPosition.y++; } } Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-07-23 20:57:12 UTC (rev 268) +++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-07-27 11:27:29 UTC (rev 269) @@ -26,6 +26,7 @@ */ public class SQLUtil { + final static char[] breakCharacters = new char[]{' ', '\t', '.', ','}; /** * A regular expression statement for name chars. */ @@ -293,13 +294,21 @@ } + public static boolean isBreakCharacter(char c) { + for (char breakChar : breakCharacters) { + if (c == breakChar) { + return true; + } + } + return false; + } + /** * Returns the index of last spacing in the string. * this method is used for clearing or breaking lines. */ public static int getLastBreakIndex(String s) { int spaceIndex = 0; - char[] breakCharacters = new char[]{' ', '\t', '.', ','}; for (int i = 0; i < breakCharacters.length; i++) { int tmpIndex = s.lastIndexOf(breakCharacters[i]); if (tmpIndex > 0 && tmpIndex > spaceIndex) { |