Merge branch 'scriptEditor' of lightning-dev/lightning_launcher into 14.3-beta7

This commit is contained in:
Pierrot 2019-06-24 09:08:08 +02:00 committed by Gogs
commit 6b92a716a3
4 changed files with 27 additions and 11 deletions

View file

@ -535,6 +535,20 @@ public class AdvancedEditText extends EditText implements OnKeyListener, OnGestu
} }
} }
/**
* Like {@link EditText#getSelectionStart()} but returns the real start, even with a 'negative' selection.
*/
public int getTrueSelectionStart() {
return Math.min(super.getSelectionStart(), super.getSelectionEnd());
}
/**
* Like {@link EditText#getSelectionEnd()} but returns the real end, even with a 'negative' selection.
*/
public int getTrueSelectionEnd() {
return Math.max(super.getSelectionStart(), super.getSelectionEnd());
}
/** The line numbers paint */ /** The line numbers paint */
protected Paint mPaintNumbers; protected Paint mPaintNumbers;
/** The line numbers paint */ /** The line numbers paint */

View file

@ -621,12 +621,12 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
if(event.isShiftPressed()){ if(event.isShiftPressed()){
// Shift tab, decrease indent // Shift tab, decrease indent
Pair<Integer, Integer> selectionI = Pair<Integer, Integer> selectionI =
Indentation.modifyIndent(mScriptText.getSelectionStart(), mScriptText.getSelectionEnd(), false, mScriptText.getEditableText()); Indentation.modifyIndent(mScriptText.getTrueSelectionStart(), mScriptText.getTrueSelectionEnd(), false, mScriptText.getEditableText());
mScriptText.setSelection(selectionI.first, selectionI.second); mScriptText.setSelection(selectionI.first, selectionI.second);
}else if(mScriptText.hasSelection()){ }else if(mScriptText.hasSelection()){
// No shift tab && selection, increase indent // No shift tab && selection, increase indent
Pair<Integer, Integer> selectionI = Pair<Integer, Integer> selectionI =
Indentation.modifyIndent(mScriptText.getSelectionStart(), mScriptText.getSelectionEnd(), true, mScriptText.getEditableText()); Indentation.modifyIndent(mScriptText.getTrueSelectionStart(), mScriptText.getTrueSelectionEnd(), true, mScriptText.getEditableText());
mScriptText.setSelection(selectionI.first, selectionI.second); mScriptText.setSelection(selectionI.first, selectionI.second);
}else { }else {
// No shift tab && no selection, add tab char // No shift tab && no selection, add tab char
@ -1359,8 +1359,8 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
@Override @Override
public void apply(AdvancedEditText editText) { public void apply(AdvancedEditText editText) {
int start = editText.getSelectionStart(); int start = editText.getTrueSelectionStart();
int end = editText.getSelectionEnd(); int end = editText.getTrueSelectionEnd();
editText.getEditableText().replace(start, end, preText+postText); editText.getEditableText().replace(start, end, preText+postText);
editText.setSelection(start + preText.length()); editText.setSelection(start + preText.length());
} }
@ -1407,12 +1407,12 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
switch (action) { switch (action) {
case DEC_TAB: case DEC_TAB:
Pair<Integer, Integer> selectionD = Pair<Integer, Integer> selectionD =
Indentation.modifyIndent(editText.getSelectionStart(), editText.getSelectionEnd(), false, editText.getEditableText()); Indentation.modifyIndent(editText.getTrueSelectionStart(), editText.getTrueSelectionEnd(), false, editText.getEditableText());
editText.setSelection(selectionD.first, selectionD.second); editText.setSelection(selectionD.first, selectionD.second);
break; break;
case INC_TAB: case INC_TAB:
Pair<Integer, Integer> selectionI = Pair<Integer, Integer> selectionI =
Indentation.modifyIndent(editText.getSelectionStart(), editText.getSelectionEnd(), true, editText.getEditableText()); Indentation.modifyIndent(editText.getTrueSelectionStart(), editText.getTrueSelectionEnd(), true, editText.getEditableText());
editText.setSelection(selectionI.first, selectionI.second); editText.setSelection(selectionI.first, selectionI.second);
break; break;
case SEARCH: case SEARCH:

View file

@ -374,7 +374,9 @@ public class BindingEditDialog extends AlertDialog implements DialogInterface.On
} else { } else {
name = mUserVariables.get(childPosition).name; name = mUserVariables.get(childPosition).name;
} }
mFormulaEditText.getText().replace(mFormulaEditText.getSelectionStart(), mFormulaEditText.getSelectionEnd(), "$"+name); int selstart = mFormulaEditText.getSelectionStart();
int selend = mFormulaEditText.getSelectionEnd();
mFormulaEditText.getText().replace(Math.min(selstart,selend), Math.max(selstart, selend), "$"+name);
dismiss(); dismiss();
return true; return true;
} }

View file

@ -75,8 +75,8 @@ public class Search {
Matcher matcher = pattern.matcher(text); Matcher matcher = pattern.matcher(text);
if(!mChkBackwards.isChecked()) { if(!mChkBackwards.isChecked()) {
// search fordwards // search fordwards
int from = mEditText.getSelectionStart(); int from = mEditText.getTrueSelectionStart();
if (from != mEditText.getSelectionEnd()) from++; // avoids returning the current selection if (from != mEditText.getTrueSelectionEnd()) from++; // avoids returning the current selection
if( matcher.find(from) || matcher.find(0)){ if( matcher.find(from) || matcher.find(0)){
// found one just after the selection or from the beginning // found one just after the selection or from the beginning
start = matcher.start(); start = matcher.start();
@ -85,7 +85,7 @@ public class Search {
}else{ }else{
// search backwards // search backwards
int until = mEditText.getSelectionEnd(); int until = mEditText.getTrueSelectionEnd();
while( matcher.find() && matcher.end() < until){ while( matcher.find() && matcher.end() < until){
// found match before cursor, save // found match before cursor, save
start = matcher.start(); start = matcher.start();