opt: functions keyboard auto insert brackets

This commit is contained in:
hyb1996
2017-12-10 01:06:47 +08:00
parent 4f8c2d1f35
commit 0c83d4d96a
2 changed files with 10 additions and 3 deletions

View File

@@ -257,6 +257,12 @@ public class CodeMirrorEditor extends FrameLayout {
" {line: editor.getCursor().line + 1, ch: 0});"); " {line: editor.getCursor().line + 1, ch: 0});");
} }
public void moveCursor(int dLine, int dCh) {
evalJavaScript(String.format(Locale.getDefault(),
"editor.setCursor({line: editor.getCursor().line + (%d), ch: editor.getCursor().ch + (%d)});",
dLine, dCh));
}
public void copyLine() { public void copyLine() {
getLine() getLine()
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@@ -561,7 +567,7 @@ public class CodeMirrorEditor extends FrameLayout {
post(CodeMirrorEditor.this::selectAll); post(CodeMirrorEditor.this::selectAll);
return true; return true;
} }
if(id == android.R.id.startSelectingText){ if (id == android.R.id.startSelectingText) {
evalJavaScript("editor.setSelection(editor.getCursor(), {line: editor.getCursor().line, ch: editor.getCursor().ch - 1});"); evalJavaScript("editor.setSelection(editor.getCursor(), {line: editor.getCursor().line, ch: editor.getCursor().ch - 1});");
} }
return super.performContextMenuAction(id); return super.performContextMenuAction(id);

View File

@@ -428,10 +428,11 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
@Override @Override
public void onPropertyClick(Module m, Property property) { public void onPropertyClick(Module m, Property property) {
if (property.isGlobal()) { if (property.isGlobal()) {
mEditor.insert(property.getKey()); mEditor.insert(property.getKey() + "()");
} else { } else {
mEditor.insert(m.getName() + "." + property.getKey()); mEditor.insert(m.getName() + "." + property.getKey() + "()");
} }
mEditor.moveCursor(0, -1);
mFunctionsKeyboardHelper.hideFunctionsLayout(true); mFunctionsKeyboardHelper.hideFunctionsLayout(true);
} }