fix code completion bug

This commit is contained in:
hyb1996
2017-07-22 09:35:51 +08:00
parent 6d62b40b21
commit 11b87d9a51
6 changed files with 24 additions and 27 deletions

2
.idea/misc.xml generated
View File

@@ -48,7 +48,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@@ -9,8 +9,8 @@ android {
applicationId "com.stardust.scriptdroid" applicationId "com.stardust.scriptdroid"
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 23 targetSdkVersion 23
versionCode 154 versionCode 155
versionName "2.0.15 Alpha2" versionName "2.0.15 Alpha3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk { ndk {

View File

@@ -89,15 +89,15 @@ loop();
返回触摸事件的最小时间间隔。 返回触摸事件的最小时间间隔。
### events.onTouch(listener) ### events.onTouch(listener)
* listener \<Function\> 参数为(x, y)的函数 * listener \<Function\> 参数为Point的函数
注册一个触摸监听函数。 注册一个触摸监听函数。
例如: 例如:
``` ```
events.observeTouch(); events.observeTouch();
events.onTouch(function(x, y){ events.onTouch(function(p){
log(x + ", " + y); log(p.x + ", " + p.y);
}); });
events.loop(); events.loop();
``` ```
@@ -106,21 +106,6 @@ events.loop();
删除所有事件监听函数。 删除所有事件监听函数。
### events.setTimeout(callback, delay)
* callback \<Function\> 回调函数
* delay \<Number\> 延迟
延迟大约delay毫秒后执行callback。该函数只有在events.loop()被使用时才有效。
返回一个整数表示这个设置的timeout, 可由clearTimeout取消。
### events.clearTimeout(id)
* id \<Number\> 由 setTimeout() 返回的 ID 值。该值标识要取消的延迟执行回调。
取消由 setTimeout() 方法设置的 timeout。
### key事件 ### key事件
当有按键被按下或弹起时会触发该事件。 当有按键被按下或弹起时会触发该事件。

View File

@@ -95,7 +95,6 @@ public class CodeCompletion implements TextWatcher {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
int position = mEditText.getSelectionStart(); int position = mEditText.getSelectionStart();
String[] str = parseWordBefore(s, position); String[] str = parseWordBefore(s, position);
if (str != null) { if (str != null) {
if (str[1] != null) { if (str[1] != null) {
@@ -163,8 +162,13 @@ public class CodeCompletion implements TextWatcher {
private boolean searchCodeCompletionForVariable(String variable, String str) { private boolean searchCodeCompletionForVariable(String variable, String str) {
List<String> properties = getPropertiesForVariable(variable); List<String> properties = getPropertiesForVariable(variable);
Collection<CodeCompletionItem> c = searchCodeCompletion(str, properties); Collection<CodeCompletionItem> c = searchCodeCompletion(str, properties);
mOnCodeCompletionChangeListener.OnCodeCompletionChange(c, Collections.<CodeCompletionItem>emptyList()); if (c.isEmpty()) {
return !c.isEmpty(); mOnCodeCompletionChangeListener.OnCodeCompletionChange(DEFAULT_CODE_COMPLETION_LIST, Collections.<CodeCompletionItem>emptyList());
return false;
} else {
mOnCodeCompletionChangeListener.OnCodeCompletionChange(c, Collections.<CodeCompletionItem>emptyList());
return true;
}
} }
private List<String> getPropertiesForVariable(String str) { private List<String> getPropertiesForVariable(String str) {

View File

@@ -109,7 +109,11 @@ public class InputMethodEnhanceBar extends RecyclerView implements CodeCompletio
mCodeCompletion.setVariableProperties(variables); mCodeCompletion.setVariableProperties(variables);
} }
}); });
}else {
mCodeCompletion.setGlobal(global);
mCodeCompletion.setVariableProperties(variables);
} }
} }
public void setEditTextBridge(EditTextBridge editTextBridge) { public void setEditTextBridge(EditTextBridge editTextBridge) {

View File

@@ -22,14 +22,14 @@ public class Timers {
mBridges = bridges; mBridges = bridges;
} }
public int setTimeout(final Object listener, long delay, final Object... args) { public int setTimeout(final Object callback, long delay, final Object... args) {
prepareLoopIfNeeded(); prepareLoopIfNeeded();
mCallbackMaxId++; mCallbackMaxId++;
final int id = mCallbackMaxId; final int id = mCallbackMaxId;
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
mBridges.callFunction(listener, null, args); mBridges.callFunction(callback, null, args);
mHandlerCallbacks.remove(id); mHandlerCallbacks.remove(id);
} }
}; };
@@ -98,7 +98,11 @@ public class Timers {
if (Looper.myLooper() != null) if (Looper.myLooper() != null)
return; return;
Looper.prepare(); Looper.prepare();
sLoopers.put(Thread.currentThread(), Looper.myLooper()); Looper looper = Looper.myLooper();
if (looper != null) {
// null check is not necessary, just to make Android Studio happy
sLoopers.put(Thread.currentThread(), looper);
}
mHandler = new Handler(); mHandler = new Handler();
} }