mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
if a user types a char occurring in a lookup string of the currently selected lookup item, insert everything that's before that occurrence
This commit is contained in:
@@ -1130,29 +1130,27 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
myInitialPrefix = null;
|
||||
}
|
||||
|
||||
final String finalCommonPrefix = commonPrefix;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
doInsertCommonPrefix(presentPrefix, finalCommonPrefix);
|
||||
}
|
||||
};
|
||||
performGuardedChange(runnable);
|
||||
replacePrefix(presentPrefix, commonPrefix);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void doInsertCommonPrefix(String presentPrefix, String newPrefix) {
|
||||
EditorModificationUtil.deleteSelectedText(myEditor);
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
final int start = offset - presentPrefix.length();
|
||||
myEditor.getDocument().replaceString(start, offset, newPrefix);
|
||||
public void replacePrefix(final String presentPrefix, final String newPrefix) {
|
||||
performGuardedChange(new Runnable() {
|
||||
public void run() {
|
||||
EditorModificationUtil.deleteSelectedText(myEditor);
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
final int start = offset - presentPrefix.length();
|
||||
myEditor.getDocument().replaceString(start, offset, newPrefix);
|
||||
|
||||
Map<LookupElement, PrefixMatcher> newItems = myModel.retainMatchingItems(newPrefix, this);
|
||||
myMatchers.clear();
|
||||
myMatchers.putAll(newItems);
|
||||
Map<LookupElement, PrefixMatcher> newItems = myModel.retainMatchingItems(newPrefix, LookupImpl.this);
|
||||
myMatchers.clear();
|
||||
myMatchers.putAll(newItems);
|
||||
|
||||
myAdditionalPrefix = "";
|
||||
myAdditionalPrefix = "";
|
||||
|
||||
myEditor.getCaretModel().moveToOffset(start + newPrefix.length());
|
||||
myEditor.getCaretModel().moveToOffset(start + newPrefix.length());
|
||||
}
|
||||
});
|
||||
refreshUi();
|
||||
}
|
||||
|
||||
|
||||
+28
-1
@@ -92,7 +92,11 @@ public class LookupTypedHandler extends TypedHandlerDelegate {
|
||||
|
||||
if (result == CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP && lookup.isFocused()) {
|
||||
LookupElement item = lookup.getCurrentItem();
|
||||
if (item != null){
|
||||
if (item != null) {
|
||||
if (completeTillTypedCharOccurrence(charTyped, lookup, item)) {
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
inside = false;
|
||||
((CommandProcessorEx)CommandProcessor.getInstance()).enterModal();
|
||||
try {
|
||||
@@ -117,6 +121,29 @@ public class LookupTypedHandler extends TypedHandlerDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean completeTillTypedCharOccurrence(char charTyped, LookupImpl lookup, LookupElement item) {
|
||||
PrefixMatcher matcher = lookup.itemMatcher(item);
|
||||
final String oldPrefix = matcher.getPrefix() + lookup.getAdditionalPrefix();
|
||||
PrefixMatcher expanded = matcher.cloneWithPrefix(oldPrefix + charTyped);
|
||||
if (expanded.prefixMatches(item)) {
|
||||
for (String s : item.getAllLookupStrings()) {
|
||||
if (matcher.prefixMatches(s)) {
|
||||
int i = -1;
|
||||
while (true) {
|
||||
i = s.indexOf(charTyped, i + 1);
|
||||
if (i < 0) break;
|
||||
final String newPrefix = s.substring(0, i + 1);
|
||||
if (expanded.prefixMatches(newPrefix)) {
|
||||
lookup.replacePrefix(oldPrefix, newPrefix);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void finishLookup(final char charTyped, @NotNull final LookupImpl lookup, final Runnable baseChange) {
|
||||
Editor editor = lookup.getEditor();
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_DOT_ETC);
|
||||
|
||||
Reference in New Issue
Block a user