|
|
|
@ -14,6 +14,7 @@ import com.fr.design.gui.autocomplete.ParameterizedCompletionInsertionInfo.Repla
|
|
|
|
|
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.DocumentRange; |
|
|
|
|
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; |
|
|
|
|
import com.fr.design.gui.syntax.ui.rtextarea.ChangeableHighlightPainter; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.event.CaretEvent; |
|
|
|
@ -438,11 +439,9 @@ class ParameterizedCompletionContext {
|
|
|
|
|
* @see #uninstallKeyBindings() |
|
|
|
|
*/ |
|
|
|
|
private void installKeyBindings() { |
|
|
|
|
|
|
|
|
|
if (AutoCompletion.isDebug()) { |
|
|
|
|
System.out.println("CompletionContext: Installing keybindings"); |
|
|
|
|
FRLogger.getLogger().debug("CompletionContext: Installing keybindings"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JTextComponent tc = ac.getTextComponent(); |
|
|
|
|
InputMap im = tc.getInputMap(); |
|
|
|
|
ActionMap am = tc.getActionMap(); |
|
|
|
@ -489,7 +488,6 @@ class ParameterizedCompletionContext {
|
|
|
|
|
im.put(ks, IM_KEY_CLOSING); |
|
|
|
|
oldClosingAction = am.get(IM_KEY_CLOSING); |
|
|
|
|
am.put(IM_KEY_CLOSING, new ClosingAction()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -513,12 +511,7 @@ class ParameterizedCompletionContext {
|
|
|
|
|
List<Highlight> highlights = getParameterHighlights(); |
|
|
|
|
for (int i = 0; i < highlights.size(); i++) { |
|
|
|
|
Highlight hl = highlights.get(i); |
|
|
|
|
// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
|
|
|
|
|
// starting at one char AFTER the highlight starts, to work around
|
|
|
|
|
// Java issue. Thanks to Matthew Adereth!
|
|
|
|
|
if (currentNext == null || currentNext.getStartOffset() </*=*/dot || |
|
|
|
|
(hl.getStartOffset() > dot && |
|
|
|
|
hl.getStartOffset() <= currentNext.getStartOffset())) { |
|
|
|
|
if (needUpdate(currentNext, hl, dot)) { |
|
|
|
|
currentNext = hl; |
|
|
|
|
pos = i; |
|
|
|
|
} |
|
|
|
@ -538,6 +531,15 @@ class ParameterizedCompletionContext {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean needUpdate(Highlight currentNext, Highlight hl, int dot) { |
|
|
|
|
// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
|
|
|
|
|
// starting at one char AFTER the highlight starts, to work around
|
|
|
|
|
// Java issue. Thanks to Matthew Adereth!
|
|
|
|
|
return currentNext == null || currentNext.getStartOffset() </*=*/dot || |
|
|
|
|
(hl.getStartOffset() > dot && |
|
|
|
|
hl.getStartOffset() <= currentNext.getStartOffset()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Moves to and selects the previous parameter. |
|
|
|
@ -562,10 +564,7 @@ class ParameterizedCompletionContext {
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < highlights.size(); i++) { |
|
|
|
|
Highlight h = highlights.get(i); |
|
|
|
|
if (currentPrev == null || currentPrev.getStartOffset() >= dot || |
|
|
|
|
(h.getStartOffset() < selStart && |
|
|
|
|
(h.getStartOffset() > currentPrev.getStartOffset() || |
|
|
|
|
pos == lastSelectedParam))) { |
|
|
|
|
if (pos == lastSelectedParam || needUpdate(currentPrev, dot, h, selStart)) { |
|
|
|
|
currentPrev = h; |
|
|
|
|
pos = i; |
|
|
|
|
} |
|
|
|
@ -593,6 +592,12 @@ class ParameterizedCompletionContext {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean needUpdate(Highlight currentPrev, int dot, Highlight h, int selStart) { |
|
|
|
|
return currentPrev == null |
|
|
|
|
|| currentPrev.getStartOffset() >= dot |
|
|
|
|
|| (currentPrev.getStartOffset() < h.getStartOffset() && h.getStartOffset() < selStart); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void possiblyUpdateParamCopies(Document doc) { |
|
|
|
|
|
|
|
|
@ -734,7 +739,7 @@ class ParameterizedCompletionContext {
|
|
|
|
|
private void uninstallKeyBindings() { |
|
|
|
|
|
|
|
|
|
if (AutoCompletion.isDebug()) { |
|
|
|
|
System.out.println("CompletionContext Uninstalling keybindings"); |
|
|
|
|
FRLogger.getLogger().debug("CompletionContext Uninstalling keybindings"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JTextComponent tc = ac.getTextComponent(); |
|
|
|
@ -1037,7 +1042,6 @@ class ParameterizedCompletionContext {
|
|
|
|
|
* @see #uninstall() |
|
|
|
|
*/ |
|
|
|
|
public void install(JTextComponent tc) { |
|
|
|
|
|
|
|
|
|
boolean replaceTabs = false; |
|
|
|
|
if (tc instanceof RSyntaxTextArea) { |
|
|
|
|
RSyntaxTextArea textArea = (RSyntaxTextArea) tc; |
|
|
|
@ -1047,14 +1051,10 @@ class ParameterizedCompletionContext {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Highlighter h = tc.getHighlighter(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
// Insert the parameter text
|
|
|
|
|
ParameterizedCompletionInsertionInfo info = |
|
|
|
|
pc.getInsertionInfo(tc, replaceTabs); |
|
|
|
|
ParameterizedCompletionInsertionInfo info = pc.getInsertionInfo(tc, replaceTabs); |
|
|
|
|
tc.replaceSelection(info.getTextToInsert()); |
|
|
|
|
|
|
|
|
|
// Add highlights around the parameters.
|
|
|
|
|
final int replacementCount = info.getReplacementCount(); |
|
|
|
|
for (int i = 0; i < replacementCount; i++) { |
|
|
|
@ -1067,40 +1067,31 @@ class ParameterizedCompletionContext {
|
|
|
|
|
for (int i = 0; i < info.getReplacementCopyCount(); i++) { |
|
|
|
|
ReplacementCopy rc = info.getReplacementCopy(i); |
|
|
|
|
paramCopyInfos.add(new ParamCopyInfo(rc.getId(), |
|
|
|
|
(Highlight) h.addHighlight(rc.getStart(), rc.getEnd(), |
|
|
|
|
paramCopyP))); |
|
|
|
|
(Highlight) h.addHighlight(rc.getStart(), rc.getEnd(), paramCopyP))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Go back and start at the first parameter.
|
|
|
|
|
tc.setCaretPosition(info.getSelectionStart()); |
|
|
|
|
if (info.hasSelection()) { |
|
|
|
|
tc.moveCaretPosition(info.getSelectionEnd()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
minPos = info.getMinOffset(); |
|
|
|
|
maxPos = info.getMaxOffset(); |
|
|
|
|
try { |
|
|
|
|
defaultEndOffs = tc.getDocument().createPosition( |
|
|
|
|
info.getDefaultEndOffs()); |
|
|
|
|
defaultEndOffs = tc.getDocument().createPosition(info.getDefaultEndOffs()); |
|
|
|
|
} catch (BadLocationException ble) { |
|
|
|
|
// Never happens
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Listen for document events AFTER we insert
|
|
|
|
|
tc.getDocument().addDocumentListener(this); |
|
|
|
|
|
|
|
|
|
} catch (BadLocationException ble) { |
|
|
|
|
// Never happens
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add listeners to the text component, AFTER text insertion.
|
|
|
|
|
tc.addCaretListener(this); |
|
|
|
|
tc.addFocusListener(this); |
|
|
|
|
installKeyBindings(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void removeUpdate(DocumentEvent e) { |
|
|
|
|
handleDocumentEvent(e); |
|
|
|
|
} |
|
|
|
|