Browse Source

REPORT-99850 公式面板 在参数后按任意字母都会变成$符号

bugfix/11.0
obo 1 year ago
parent
commit
d41730efa0
  1. 8
      designer-base/src/main/java/com/fr/design/gui/autocomplete/AbstractCompletionProvider.java
  2. 19
      designer-base/src/main/java/com/fr/design/gui/autocomplete/FormulaPaneAutoCompletion.java

8
designer-base/src/main/java/com/fr/design/gui/autocomplete/AbstractCompletionProvider.java

@ -8,12 +8,14 @@
*/
package com.fr.design.gui.autocomplete;
import com.fr.stable.StringUtils;
import javax.swing.text.JTextComponent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.swing.text.JTextComponent;
/**
@ -186,7 +188,9 @@ public abstract class AbstractCompletionProvider
while (index<completions.size()) {
Completion c = completions.get(index);
if (Util.startsWithIgnoreCase(c.getInputText(), text)) {
String inputText = c.getInputText();
//当输入文本和补全项相等时,不再添加到补全项到窗口中
if (Util.startsWithIgnoreCase(inputText, text) && !StringUtils.equals(inputText, text)) {
retVal.add(c);
index++;
}

19
designer-base/src/main/java/com/fr/design/gui/autocomplete/FormulaPaneAutoCompletion.java

@ -2,11 +2,8 @@ package com.fr.design.gui.autocomplete;
import com.fr.design.formula.FormulaPane;
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
import javax.swing.text.Caret;
import javax.swing.text.JTextComponent;
import java.awt.Window;
/**
* @author Hoky
@ -70,9 +67,19 @@ public class FormulaPaneAutoCompletion extends AutoCompletionWithExtraRefresh {
caret.setDot(start);
caret.moveDot(dot);
if (FormulaPane.containsParam(replacement)) {
textComp.replaceSelection(FormulaPane.getParamPrefix(replacement) + replacement);
int caretPosition = textComp.getCaretPosition();
textComp.setCaretPosition(caretPosition);
String selectedText = textComp.getSelectedText();
//当前文本总长度大于选中文本时,考虑到文本段有其他类似补全文本的字符串,因此找到选择文本进行补全
String text = textComp.getText().substring(0, dot);
int index = text.lastIndexOf(selectedText);
//获取选中文本的前一个字符,以参数为例$par,则prefix就是$
String prefix = (index > 0) ? text.substring(index - 1, index) : "";
//补全内容在FormulaPane中的前缀,例如参数para1会返回$,不存在返回""
String paramPrefix = FormulaPane.getParamPrefix(replacement);
//如果前缀和字符对不上需要补上,相同时直接补全字符串本身即可
if (!FormulaPane.getParamPrefix(replacement).equals(prefix)) {
replacement = paramPrefix + replacement;
}
textComp.replaceSelection(replacement);
} else {
textComp.replaceSelection(replacement + "()");
int caretPosition = textComp.getCaretPosition();

Loading…
Cancel
Save