mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
IDEA-98818 Cyclic expand word doesn't work as expected for newly defined variables
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.completion
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class HippieCompletionTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void testDollars() {
|
||||
myFixture.configureByText "a.txt", '''
|
||||
$some_long_variable_name = Obj::instance();
|
||||
$some_lon<caret>
|
||||
'''
|
||||
myFixture.performEditorAction("HippieCompletion")
|
||||
myFixture.checkResult '''
|
||||
$some_long_variable_name = Obj::instance();
|
||||
$some_long_variable_name<caret>
|
||||
'''
|
||||
}
|
||||
|
||||
}
|
||||
@@ -237,25 +237,26 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler {
|
||||
}
|
||||
|
||||
private static CompletionData computeData(final Editor editor, final CharSequence charsSequence) {
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
|
||||
while (offset > 1 && Character.isJavaIdentifierPart(charsSequence.charAt(offset - 1))) offset--;
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
|
||||
final CompletionData data = new CompletionData();
|
||||
|
||||
int endOffset = offset;
|
||||
data.startOffset = offset;
|
||||
while (charsSequence.length() > endOffset && Character.isJavaIdentifierPart(charsSequence.charAt(endOffset)) &&
|
||||
endOffset < editor.getDocument().getTextLength()) {
|
||||
if (endOffset == editor.getCaretModel().getOffset()) {
|
||||
data.myPrefix = charsSequence.subSequence(offset, endOffset).toString();
|
||||
IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() {
|
||||
@Override
|
||||
public void run(final CharSequence chars, @Nullable char[] charsArray, final int start, final int end) {
|
||||
if (start <= offset && end >= offset) {
|
||||
data.myPrefix = charsSequence.subSequence(start, offset).toString();
|
||||
data.myWordUnderCursor = charsSequence.subSequence(start, end).toString();
|
||||
data.startOffset = start;
|
||||
}
|
||||
}
|
||||
endOffset++;
|
||||
}, charsSequence, 0, charsSequence.length());
|
||||
|
||||
if (data.myPrefix == null) {
|
||||
data.myPrefix = "";
|
||||
data.myWordUnderCursor = "";
|
||||
data.startOffset = offset;
|
||||
}
|
||||
|
||||
data.myWordUnderCursor = charsSequence.subSequence(offset, endOffset).toString();
|
||||
if (data.myPrefix == null) data.myPrefix = data.myWordUnderCursor;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user