|
From: <caw...@us...> - 2007-06-13 13:29:16
|
Revision: 2613
http://svn.sourceforge.net/rubyeclipse/?rev=2613&view=rev
Author: cawilliams
Date: 2007-06-13 06:29:14 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
Fix Trac # 4822 - Pressing enter after class definition doesn't indent automatically (on an already closed block, we should still indent)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyAutoIndentStrategy.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyAutoIndentStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyAutoIndentStrategy.java 2007-06-13 13:10:38 UTC (rev 2612)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyAutoIndentStrategy.java 2007-06-13 13:29:14 UTC (rev 2613)
@@ -94,13 +94,14 @@
ITypedRegion region= TextUtilities.getPartition(d, fPartitioning, start, true);
// if (IRubyPartitions.RUBY_DOC.equals(region.getType()))
// start= d.getLineInformationOfOffset(region.getOffset()).getOffset();
-
- // insert closing "end" on new line after an unclosed block
- if (closeBlock() && unclosedBlock(d, start, c.offset)) {
+ // If we're hitting return at the end of the line of a new block, add indent
+ if (atStartOfBlock(getTrimmedLine(d, start, c.offset))) {
buf.append(CodeFormatterUtil.createIndentString(1, fProject));
c.caretOffset= c.offset + buf.length();
c.shiftsCaret= false;
-
+ }
+ // insert closing "end" on new line after an unclosed block
+ if (closeBlock() && unclosedBlock(d, start, c.offset)) {
// copy old content of line behind insertion point to new line
if (c.offset == 0) {
if (lineEnd - contentStart > 0) {
@@ -123,10 +124,7 @@
private boolean unclosedBlock(IDocument d, int start, int offset) {
// FIXME wow is this ugly! There has to be an easier way to tell if there's an unclosed block besides parsing and catching a syntaxError!
try {
- String line = d.get(start, offset - start);
- line = line.trim();
- if (!line.startsWith("class ") && !line.startsWith("if ") && !line.startsWith("module ") && !line.startsWith("unless ")
- && !line.startsWith("def ") && !line.equals("begin") && !openBlockPattern.matcher(line).matches()) {
+ if (!atStartOfBlock(getTrimmedLine(d, start, offset))) {
return false;
}
} catch (BadLocationException e1) {
@@ -152,6 +150,18 @@
return false;
}
+ private String getTrimmedLine(IDocument d, int start, int offset) throws BadLocationException {
+ String line = d.get(start, offset - start);
+ line = line.trim();
+ return line;
+ }
+
+ private boolean atStartOfBlock(String line) {
+ return line.startsWith("class ") || line.startsWith("if ") || line.startsWith("module ")
+ || line.startsWith("unless ") || line.startsWith("def ") || line.equals("begin")
+ || openBlockPattern.matcher(line).matches();
+ }
+
private boolean closeBlock() {
return endStatements;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|