|
|
|
@ -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(); |
|
|
|
|