Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XECLIPSE-144: Unable to edit long texts
Applied patch by Clemens Fuchslocher. Thanks!
- Loading branch information
Clemens Fuchslocher
authored and
Fabio Mancinelli
committed
Nov 8, 2011
1 parent
0cf567c
commit 8952bb5
Showing
6 changed files
with
334 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ipse.ui/src/main/java/org/xwiki/eclipse/ui/editors/scanners/rules/DefinitionListRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
* | ||
*/ | ||
package org.xwiki.eclipse.ui.editors.scanners.rules; | ||
|
||
import org.eclipse.jface.text.rules.ICharacterScanner; | ||
import org.eclipse.jface.text.rules.IToken; | ||
import org.eclipse.jface.text.rules.Token; | ||
|
||
public class DefinitionListRule extends ListRule | ||
{ | ||
public DefinitionListRule(String regex, IToken token) | ||
{ | ||
super(regex, token); | ||
} | ||
|
||
@Override | ||
public IToken evaluate(ICharacterScanner scanner) | ||
{ | ||
IToken token = super.evaluate(scanner); | ||
// Is there a definition list? | ||
if (token == Token.UNDEFINED) { | ||
// No. | ||
return token; | ||
} | ||
|
||
// Yes. Consume the rest of the line. | ||
readLine(scanner); | ||
return token; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...wiki.eclipse.ui/src/main/java/org/xwiki/eclipse/ui/editors/scanners/rules/HeaderRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
* | ||
*/ | ||
package org.xwiki.eclipse.ui.editors.scanners.rules; | ||
|
||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.eclipse.jface.text.rules.ICharacterScanner; | ||
import org.eclipse.jface.text.rules.IToken; | ||
import org.eclipse.jface.text.rules.Token; | ||
|
||
public class HeaderRule extends Rule | ||
{ | ||
private Map<Pattern, IToken> tokenLookup = new LinkedHashMap<Pattern, IToken>(); | ||
|
||
public IToken evaluate(ICharacterScanner scanner) | ||
{ | ||
if (scanner.getColumn() != 0) { | ||
return Token.UNDEFINED; | ||
} | ||
|
||
// Consume all leading spaces. | ||
StringBuffer spaces = readLeadingSpaces(scanner); | ||
|
||
// Consume the first two words. | ||
StringBuffer text = readWord(scanner); | ||
text.append(readWord(scanner)); | ||
|
||
Iterator<Pattern> patterns = tokenLookup.keySet().iterator(); | ||
while (patterns.hasNext()) { | ||
Pattern pattern = patterns.next(); | ||
if (pattern == null) { | ||
continue; | ||
} | ||
|
||
// Is there a headline? | ||
Matcher matcher = pattern.matcher(text); | ||
if (matcher.lookingAt()) { | ||
// Yes. Consume the rest of the line. | ||
readLine(scanner); | ||
return tokenLookup.get(pattern); | ||
} | ||
} | ||
|
||
// There is no headline. Rewind the scanner. | ||
unread(scanner, spaces.length() + text.length()); | ||
return Token.UNDEFINED; | ||
} | ||
|
||
public void add(String regex, IToken token) | ||
{ | ||
tokenLookup.put(Pattern.compile(regex), token); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
....xwiki.eclipse.ui/src/main/java/org/xwiki/eclipse/ui/editors/scanners/rules/ListRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
* | ||
*/ | ||
package org.xwiki.eclipse.ui.editors.scanners.rules; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.eclipse.jface.text.rules.ICharacterScanner; | ||
import org.eclipse.jface.text.rules.IToken; | ||
import org.eclipse.jface.text.rules.Token; | ||
|
||
public class ListRule extends Rule | ||
{ | ||
private Pattern pattern; | ||
private IToken token; | ||
|
||
public ListRule(String regex, IToken token) | ||
{ | ||
this.pattern = Pattern.compile(regex); | ||
this.token = token; | ||
} | ||
|
||
public IToken evaluate(ICharacterScanner scanner) | ||
{ | ||
if (scanner.getColumn() != 0) { | ||
return Token.UNDEFINED; | ||
} | ||
|
||
// Consume all leading spaces. | ||
StringBuffer spaces = readLeadingSpaces(scanner); | ||
|
||
// Consume the first word. | ||
StringBuffer text = readWord(scanner); | ||
|
||
// Is there a list? | ||
Matcher matcher = pattern.matcher(text); | ||
if (matcher.lookingAt()) { | ||
// Yes. | ||
return token; | ||
} | ||
|
||
// There is no list. Rewind the scanner. | ||
unread(scanner, spaces.length() + text.length()); | ||
return Token.UNDEFINED; | ||
} | ||
} |
Oops, something went wrong.