Skip to content

Commit

Permalink
Issue #18: Add Option to bring cursor at middle of pair auto complete…
Browse files Browse the repository at this point in the history
… characters
  • Loading branch information
AmrDeveloper committed Mar 20, 2022
1 parent f0acc14 commit 21cb1a9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class CodeView extends AppCompatMultiAutoCompleteTextView implements Find
private int autoCompleteItemHeightInDp = (int) (50 * Resources.getSystem().getDisplayMetrics().density);

private boolean enablePairComplete = false;
private boolean enablePairCompleteCenterCursor = false;
private final Map<Character, Character> mPairCompleteMap = new HashMap<>();

private final Handler mUpdateHandler = new Handler();
Expand Down Expand Up @@ -616,6 +617,15 @@ public void enablePairComplete(boolean enable) {
enablePairComplete = enable;
}

/**
* Enable or disable moving the cursor to the center after insert pair complete
* @param enable Flag to enable or disable pair complete center cursor
* @since 1.3.4
*/
public void enablePairCompleteCenterCursor(boolean enable) {
enablePairCompleteCenterCursor = enable;
}

/**
* Set the pairs for auto pairs complete feature
* @param map Map of pairs of characters
Expand Down Expand Up @@ -756,7 +766,9 @@ else if (indentationEnds.contains(currentChar))
Character pairValue = mPairCompleteMap.get(currentChar);
if (pairValue != null) {
modified = false;
getText().insert(getSelectionEnd(), pairValue.toString());
int selectionEnd = getSelectionEnd();
getText().insert(selectionEnd, pairValue.toString());
if (enablePairCompleteCenterCursor) setSelection(selectionEnd);
if (enableAutoIndentation) {
if (indentationStarts.contains(pairValue))
currentIndentation += tabLength;
Expand Down

0 comments on commit 21cb1a9

Please sign in to comment.