Skip to content

Commit

Permalink
XECLIPSE-144: Unable to edit long texts
Browse files Browse the repository at this point in the history
Applied patch by Clemens Fuchslocher. Thanks!
  • Loading branch information
Clemens Fuchslocher authored and Fabio Mancinelli committed Nov 8, 2011
1 parent 0cf567c commit 8952bb5
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 58 deletions.
Expand Up @@ -26,9 +26,34 @@
public class Constants
{
public static final String LIST_BULLET_PATTERN =
"\\*+ |11*\\. |1\\**\\. |a\\. |A\\. |i\\. |I\\. |g\\. |h\\. |k\\. ";
// Bulleted list
"^\\*+ |"
// Numbered list
+ "^1+\\. |"
// Mixed list
+ "^1+\\*+\\. |"
// Square list
+ "^- |"
// Lowercase Alphabetical list
+ "^a\\. |"
// Uppercase Roman list
+ "^A\\. |"
// Lowercase Greek list
+ "^g\\. |"
// Uppercase Greek list
+ "^G\\. |"
// Hiragana list
+ "^h\\. |"
// Hiragana Iroah list
+ "^H\\. |"
// Katakana list
+ "^k\\. |"
// Katakana Iroha list
+ "^K\\. |"
// Hebrew list
+ "^j\\. ";

public static final String DEFINITION_TERM_PATTERN = ":*; .+|:+ .+";
public static final String DEFINITION_TERM_PATTERN = ":*; |:+ ";

public static final String API_DATA_DIRECTORY = "xwikiApi";
}
Expand Up @@ -31,6 +31,9 @@
import org.xwiki.eclipse.ui.editors.Constants;
import org.xwiki.eclipse.ui.editors.Preferences;
import org.xwiki.eclipse.ui.editors.scanners.rules.BalancedParenthesisRule;
import org.xwiki.eclipse.ui.editors.scanners.rules.DefinitionListRule;
import org.xwiki.eclipse.ui.editors.scanners.rules.HeaderRule;
import org.xwiki.eclipse.ui.editors.scanners.rules.ListRule;
import org.xwiki.eclipse.ui.editors.scanners.rules.RegExRule;

/**
Expand Down Expand Up @@ -66,63 +69,16 @@ public XWikiMarkupScanner()

List<IRule> rules = new ArrayList<IRule>();

/* RegEx rules work better with respect to SingleLineRules */
RegExRule regExRule = new RegExRule("1 .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("= .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("1.1 .*\n?", heading2Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("== .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("1.1.1 .*\n?", heading3Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("=== .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("1.1.1.1 .*\n?", heading4Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("==== .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("1.1.1.1.1 .*\n?", heading5Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("===== .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("1.1.1.1.1.1 .*\n?", heading6Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule("====== .*\n?", heading1Token);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule(Constants.LIST_BULLET_PATTERN, listBulletToken);
regExRule.setColumnConstraint(0);
rules.add(regExRule);

regExRule = new RegExRule(Constants.DEFINITION_TERM_PATTERN, definitionTermToken);
regExRule.setColumnConstraint(0);
rules.add(regExRule);
HeaderRule headers = new HeaderRule();
headers.add("^= .|^1 .", heading1Token);
headers.add("^== .|^1\\.1 .", heading2Token);
headers.add("^=== .|^1\\.1\\.1 .", heading3Token);
headers.add("^==== .|^1\\.1\\.1\\.1 .", heading4Token);
headers.add("^===== .|^1\\.1\\.1\\.1\\.1 .", heading5Token);
headers.add("^====== .|^1\\.1\\.1\\.1\\.1\\.1 .", heading6Token);

rules.add(new ListRule(Constants.LIST_BULLET_PATTERN, listBulletToken));
rules.add(new DefinitionListRule(Constants.DEFINITION_TERM_PATTERN, definitionTermToken));
rules.add(new SingleLineRule("**", "**", boldToken, '\\'));
rules.add(new SingleLineRule("*", "*", boldToken, '\\'));
rules.add(new SingleLineRule("~~", "~~", italicToken, '\\'));
Expand Down
@@ -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;
}
}
@@ -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);
}
}
@@ -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;
}
}

0 comments on commit 8952bb5

Please sign in to comment.