mirror of
https://github.com/TrianguloY/LightningLauncher.git
synced 2024-12-26 09:58:20 +01:00
Merge branch 'scriptEditor' of lightning-dev/lightning_launcher into 14.3-beta7
This commit is contained in:
commit
6b92a716a3
4 changed files with 27 additions and 11 deletions
|
@ -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 */
|
||||
protected Paint mPaintNumbers;
|
||||
/** The line numbers paint */
|
||||
|
|
|
@ -621,12 +621,12 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
|
|||
if(event.isShiftPressed()){
|
||||
// Shift tab, decrease indent
|
||||
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);
|
||||
}else if(mScriptText.hasSelection()){
|
||||
// No shift tab && selection, increase indent
|
||||
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);
|
||||
}else {
|
||||
// No shift tab && no selection, add tab char
|
||||
|
@ -1359,8 +1359,8 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
|
|||
|
||||
@Override
|
||||
public void apply(AdvancedEditText editText) {
|
||||
int start = editText.getSelectionStart();
|
||||
int end = editText.getSelectionEnd();
|
||||
int start = editText.getTrueSelectionStart();
|
||||
int end = editText.getTrueSelectionEnd();
|
||||
editText.getEditableText().replace(start, end, preText+postText);
|
||||
editText.setSelection(start + preText.length());
|
||||
}
|
||||
|
@ -1407,12 +1407,12 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
|
|||
switch (action) {
|
||||
case DEC_TAB:
|
||||
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);
|
||||
break;
|
||||
case INC_TAB:
|
||||
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);
|
||||
break;
|
||||
case SEARCH:
|
||||
|
|
|
@ -374,7 +374,9 @@ public class BindingEditDialog extends AlertDialog implements DialogInterface.On
|
|||
} else {
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -75,8 +75,8 @@ public class Search {
|
|||
Matcher matcher = pattern.matcher(text);
|
||||
if(!mChkBackwards.isChecked()) {
|
||||
// search fordwards
|
||||
int from = mEditText.getSelectionStart();
|
||||
if (from != mEditText.getSelectionEnd()) from++; // avoids returning the current selection
|
||||
int from = mEditText.getTrueSelectionStart();
|
||||
if (from != mEditText.getTrueSelectionEnd()) from++; // avoids returning the current selection
|
||||
if( matcher.find(from) || matcher.find(0)){
|
||||
// found one just after the selection or from the beginning
|
||||
start = matcher.start();
|
||||
|
@ -85,7 +85,7 @@ public class Search {
|
|||
}else{
|
||||
// search backwards
|
||||
|
||||
int until = mEditText.getSelectionEnd();
|
||||
int until = mEditText.getTrueSelectionEnd();
|
||||
while( matcher.find() && matcher.end() < until){
|
||||
// found match before cursor, save
|
||||
start = matcher.start();
|
||||
|
|
Loading…
Reference in a new issue