fix shift-tab quirk (issue #458)

This commit is contained in:
benfry
2011-04-16 20:28:23 +00:00
parent 05aa42c313
commit 708bf83f1d
4 changed files with 39 additions and 84 deletions

View File

@@ -213,70 +213,19 @@ public class PdeKeyListener {
switch ((int) c) {
case 9: // TAB
if (textarea.isSelectionActive()) {
if ((event.getModifiers() & KeyEvent.SHIFT_MASK) == 0) {
editor.handleIndent();
} else {
editor.handleOutdent();
}
if ((event.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {
// if shift is down, the user always expects an outdent
// http://code.google.com/p/processing/issues/detail?id=458
editor.handleOutdent();
} else if (textarea.isSelectionActive()) {
editor.handleIndent();
} else if (Preferences.getBoolean("editor.tabs.expand")) {
int tabSize = Preferences.getInteger("editor.tabs.size");
textarea.setSelectedText(spaces(tabSize));
event.consume();
return true;
// } else if (tabsIndent) {
// // this code is incomplete
//
// // if this brace is the only thing on the line, outdent
// //char contents[] = getCleanedContents();
// char contents[] = textarea.getText().toCharArray();
// // index to the character to the left of the caret
// int prevCharIndex = textarea.getCaretPosition() - 1;
//
// // now find the start of this line
// int lineStart = calcLineStart(prevCharIndex, contents);
//
// int lineEnd = lineStart;
// while ((lineEnd < contents.length - 1) &&
// (contents[lineEnd] != 10)) {
// lineEnd++;
// }
//
// // get the number of braces, to determine whether this is an indent
// int braceBalance = 0;
// int index = lineStart;
// while ((index < contents.length) &&
// (contents[index] != 10)) {
// if (contents[index] == '{') {
// braceBalance++;
// } else if (contents[index] == '}') {
// braceBalance--;
// }
// index++;
// }
//
// // if it's a starting indent, need to ignore it, so lineStart
// // will be the counting point. but if there's a closing indent,
// // then the lineEnd should be used.
// int where = (braceBalance > 0) ? lineStart : lineEnd;
// int indent = calcBraceIndent(where, contents);
// if (indent == -1) {
// // no braces to speak of, do nothing
// indent = 0;
// } else {
// indent += tabSize;
// }
//
// // and the number of spaces it has
// int spaceCount = calcSpaceCount(prevCharIndex, contents);
//
// textarea.setSelectionStart(lineStart);
// textarea.setSelectionEnd(lineStart + spaceCount);
// textarea.setSelectedText(Editor.EMPTY.substring(0, indent));
//
// event.consume();
// return true;
}
break;