[jbosstools-commits] JBoss Tools SVN: r43869 - in trunk: vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util and 2 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Sep 20 12:47:42 EDT 2012
Author: yradtsevich
Date: 2012-09-20 12:47:41 -0400 (Thu, 20 Sep 2012)
New Revision: 43869
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe.docbook/src/org/jboss/tools/vpe/docbook/template/DocbookTextTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-11588 : Open-on of EL from Visual Page Editor works incorrectly
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2012-09-20 16:18:44 UTC (rev 43868)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractEditableJsfTemplate.java 2012-09-20 16:47:41 UTC (rev 43869)
@@ -37,17 +37,6 @@
*/
public abstract class AbstractEditableJsfTemplate extends VpeAbstractTemplate {
- /**
- * Gets the output attribute node.
- *
- * @param element the element
- *
- * @return the output attribute node
- */
- public Attr getOutputAttributeNode(Element element) {
- return null;
- }
-
// general jsf attributes
/**
* Contains JSF attributes and appropriate HTML attributes
@@ -101,7 +90,7 @@
public IRegion getSourceRegionForOpenOn(VpePageContext pageContext, Node sourceNode ,nsIDOMNode domNode) {
final Attr attr= getOutputAttributeNode((Element) sourceNode);
- int offset = TextUtil.getStartELDocumentPosition(attr);
+ int offset = TextUtil.getPositionForOpenOn(attr, pageContext);
if(offset!=-1){
return new Region(offset, 0);
} else {
@@ -109,4 +98,21 @@
}
}
+
+ /**
+ * Gets the output attribute node.
+ * This method may be overridden in subclasses.
+ *
+ * @param element the element
+ *
+ * @return the output attribute node
+ */
+ public Attr getOutputAttributeNode(Element element) {
+ if (element.hasAttribute(JSF.ATTR_VALUE)) {
+ return element.getAttributeNode(JSF.ATTR_VALUE);
+ } else if (element.hasAttribute(JSF.ATTR_BINDING)) {
+ return element.getAttributeNode(JSF.ATTR_BINDING);
+ }
+ return null;
+ }
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2012-09-20 16:18:44 UTC (rev 43868)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/AbstractOutputJsfTemplate.java 2012-09-20 16:47:41 UTC (rev 43869)
@@ -42,16 +42,6 @@
*/
protected String escapeAttributeName = JSF.ATTR_ESCAPE;
- @Override
- public Attr getOutputAttributeNode(Element element) {
- if (element.hasAttribute(JSF.ATTR_VALUE)) {
- return element.getAttributeNode(JSF.ATTR_VALUE);
- } else if (element.hasAttribute(JSF.ATTR_BINDING)) {
- return element.getAttributeNode(JSF.ATTR_BINDING);
- }
- return null;
- }
-
/**
* copy outputAttributes
*
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java 2012-09-20 16:18:44 UTC (rev 43868)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/TextUtil.java 2012-09-20 16:47:41 UTC (rev 43869)
@@ -12,15 +12,19 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
-import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.swt.graphics.Point;
import org.jboss.tools.jst.jsp.util.NodesManagingUtil;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.mozilla.interfaces.nsIDOMKeyEvent;
import org.w3c.dom.Node;
@@ -41,7 +45,8 @@
private final static char CHR_ESC_STOP = ';';
private final static char CHR_HEX_FLAG = 'x';
private final static String SPCHARS = "\f\n\r\t\u0020\u2028\u2029"; //$NON-NLS-1$
- private static final Pattern elPattern = Pattern.compile("(#|\\$)\\{\\s*([^\\s])"); //$NON-NLS-1$
+ private static final Pattern EL_START_PATTERN = Pattern.compile("(#|\\$)\\{\\s*([^\\s])"); //$NON-NLS-1$
+ private static final String EL_END_PATTERN = "}"; //$NON-NLS-1$
private final static Map<Character, String> textSet = new HashMap<Character, String>();
static {
@@ -456,24 +461,47 @@
}
/**
* @author mareshkau
+ * @author Yahor Radtsevich (yradtsevich)
* @param node or attribute for which we want calculate position start el position
*
* @return position if we can find position
* -1 if we can't find pisition, <document_offcet>'#{el}', return start position of el
*/
- public static int getStartELDocumentPosition(Node node) {
-
+ @SuppressWarnings("restriction")
+ public static int getPositionForOpenOn(Node node, VpePageContext pageContext) {
if (node != null && node.getNodeValue() != null
&& node.getNodeValue().length() > 0) {
- int elPosition = 0;
- Matcher beginELExpresion = elPattern.matcher(node.getNodeValue());
- if (beginELExpresion.find()) {
- // +1 becouse we should have position of first symbol
- elPosition = beginELExpresion.start(2) + 1;
+ List<Integer> elStarts = new ArrayList<Integer>();
+ Matcher beginELExpresion = EL_START_PATTERN.matcher(node.getNodeValue());
+ while (beginELExpresion.find()) {
+ elStarts.add(beginELExpresion.start(2));
}
- int offset = NodesManagingUtil.getStartOffsetNode(node)
- + elPosition;
- return offset;
+
+ final int startOffsetNode = NodesManagingUtil.getStartOffsetNode(node);
+ final int endOffsetNode = startOffsetNode + node.getNodeValue().length();
+ int openOnOffset = startOffsetNode;
+ if (!elStarts.isEmpty()) {
+ // +1 because we should have position of first symbol
+ openOnOffset += elStarts.get(0) + 1;
+ }
+
+ // Fix for the cases when a part of node value is already selected in the source viewer (JBIDE-11588).
+ // If yes, than check if it is an el-expression and return position of the selection end.
+ Point selection = pageContext.getSourceBuilder().getSelectionRange();
+ int selectionStart = selection.x;
+ int selectionEnd = selectionStart + selection.y;
+ if (selectionStart >= startOffsetNode && selectionEnd <= endOffsetNode) {
+ for (int elStart : elStarts) {
+ int elEnd = node.getNodeValue().indexOf(EL_END_PATTERN, elStart);
+ if (selectionEnd >= elStart + startOffsetNode && selectionEnd <= elEnd + startOffsetNode) {
+ if (selectionStart != selectionEnd) {
+ openOnOffset = selectionEnd - 1;
+ }
+ }
+ }
+ }
+
+ return openOnOffset;
}
return -1;
}
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.docbook/src/org/jboss/tools/vpe/docbook/template/DocbookTextTemplate.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.docbook/src/org/jboss/tools/vpe/docbook/template/DocbookTextTemplate.java 2012-09-20 16:18:44 UTC (rev 43868)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.docbook/src/org/jboss/tools/vpe/docbook/template/DocbookTextTemplate.java 2012-09-20 16:47:41 UTC (rev 43869)
@@ -70,7 +70,7 @@
Point selection = pageContext.getSourceBuilder().getSelectionRange();
//processing for el expressions
- int offset = TextUtil.getStartELDocumentPosition(sourceNode);
+ int offset = TextUtil.getPositionForOpenOn(sourceNode, pageContext);
IRegion resultRegion;
if(offset >= 0) {
resultRegion = new Region(offset,0);
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java 2012-09-20 16:18:44 UTC (rev 43868)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.html/src/org/jboss/tools/vpe/html/template/HtmlTextTemplate.java 2012-09-20 16:47:41 UTC (rev 43869)
@@ -67,7 +67,7 @@
Point selection = pageContext.getSourceBuilder().getSelectionRange();
//processing for el expressions
- int offset = TextUtil.getStartELDocumentPosition(sourceNode);
+ int offset = TextUtil.getPositionForOpenOn(sourceNode, pageContext);
IRegion resultRegion;
if(offset >= 0) {
resultRegion = new Region(offset,0);
More information about the jbosstools-commits
mailing list