From 76a9b8ffe19a91c4c03d8ba71ae2aeeecf1c7df4 Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 15 Dec 2005 23:44:30 +0000 Subject: [PATCH] use tabs to auto-indent particular lines (ala emacs) bug #22 --- app/EditorListener.java | 30 ++++++++++++++++++++++++------ todo.txt | 14 ++++++++------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/EditorListener.java b/app/EditorListener.java index 63c6ea1d1..da0b81f93 100644 --- a/app/EditorListener.java +++ b/app/EditorListener.java @@ -104,7 +104,6 @@ public class EditorListener { switch ((int) c) { case 9: - tabsExpand = false; if (tabsExpand) { // expand tabs textarea.setSelectedText(tabString); event.consume(); @@ -119,21 +118,40 @@ public class EditorListener { // now find the start of this line int lineStart = calcLineStart(prevCharIndex, contents); - int indent = calcBraceIndent(lineStart, contents); //, 0); + 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 - //System.out.println("no indent"); indent = 0; } else { - //System.out.println("indent found at " + indent); indent += tabSize; } // and the number of spaces it has int spaceCount = calcSpaceCount(prevCharIndex, contents); - System.out.println(indent + " " + lineStart + " " + spaceCount); - textarea.setSelectionStart(lineStart); textarea.setSelectionEnd(lineStart + spaceCount); textarea.setSelectedText(Editor.EMPTY.substring(0, indent)); diff --git a/todo.txt b/todo.txt index b5b8cce90..d155dfca5 100644 --- a/todo.txt +++ b/todo.txt @@ -28,7 +28,15 @@ X mark temp build folder for deletion on exit X properly remove console files on exit X in previous releases this was filling up the temp dir with a lotta garbage X bug where hiddenCount/codeCount weren't being set to zero on load() + +tab handling X indent/outdent with curly braces +X tab to just indent lines properly, +X rather than having it convert to spaces +X need a smarter handler (rather than the editor listener) +X could look at previous line for its indent +X and when hitting } do a proper outdent (if only spaces before it) +X http://dev.processing.org/bugs/show_bug.cgi?id=22 _ unchecking 'use external editor' sketch should not set modified _ dangerous if a version that hasn't been re-loaded has possibility @@ -273,12 +281,6 @@ PDE / Editor _ when running with external editor, hide the editor text area _ http://dev.processing.org/bugs/show_bug.cgi?id=20 -_ tab to just indent lines properly, -_ rather than having it convert to spaces -_ need a smarter handler (rather than the editor listener) -_ could look at previous line for its indent -_ and when hitting } do a proper outdent (if only spaces before it) -_ http://dev.processing.org/bugs/show_bug.cgi?id=22 _ horizontal scroller gets weird sometimes _ http://dev.processing.org/bugs/show_bug.cgi?id=23 _ mouse wheel broken in the text editor? (windows jdk 1.5?)