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