|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.fr.design.gui.autocomplete; |
|
|
|
|
|
|
|
|
|
import com.fr.design.formula.FormulaPane; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.text.Caret; |
|
|
|
|
import javax.swing.text.JTextComponent; |
|
|
|
@ -68,14 +69,13 @@ public class FormulaPaneAutoCompletion extends AutoCompletionWithExtraRefresh {
|
|
|
|
|
caret.moveDot(dot); |
|
|
|
|
if (FormulaPane.containsParam(replacement)) { |
|
|
|
|
String selectedText = textComp.getSelectedText(); |
|
|
|
|
//当前文本总长度大于选中文本时,考虑到文本段有其他类似补全文本的字符串,因此找到选择文本进行补全
|
|
|
|
|
//找到选择文本(光标输入位置dot)进行补全
|
|
|
|
|
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会返回$,不存在返回""
|
|
|
|
|
//获取replacement的前缀,replacement是不带前缀的,例如变量$$page_number,获取到的replacement是page_number
|
|
|
|
|
String paramPrefix = FormulaPane.getParamPrefix(replacement); |
|
|
|
|
//如果前缀和字符对不上需要补上,相同时直接补全字符串本身即可
|
|
|
|
|
//当选择文本之前有和param前缀相同大小的字符串时,截取对比一下,如果内容相同,则前缀已经存在,不用再拼接了
|
|
|
|
|
String prefix = (index >= paramPrefix.length()) ? text.substring(index - paramPrefix.length(), index) : StringUtils.EMPTY; |
|
|
|
|
if (!FormulaPane.getParamPrefix(replacement).equals(prefix)) { |
|
|
|
|
replacement = paramPrefix + replacement; |
|
|
|
|
} |
|
|
|
|