Skip to content

Conversation

@KyrieCheng-China
Copy link

problem: there is no check with input value. for example, user can input 00,012,00000012, like these impossible values.

solution: add check when there is a change of text, if it's first two characters are match 0[0-9],the input will be rejected, means it will keep "0" instead of "00".

Fixes #41

problem: there is no check with input value. for example, user can input 00,012,00000012, like these impossible values.

solution: add check when there is a change of text, if it's first two characters are match 0[0-9],the input will be rejected, means it will keep "0" instead of "00".

Fixes forzzzzz#41
@forzzzzz
Copy link
Owner

Hi, there is a class that is responsible for entering characters app/src/main/java/com/forz/calculator/utils/InsertInExpression.kt

    fun enterDigit(digit: String, inputEditText: ExpressionEditText) {
        val string = inputEditText.text.toString()

        deleteSelection(inputEditText, inputEditText.selectionStart, inputEditText.selectionEnd)

        val cursorPositionStart = inputEditText.selectionStart

        val stringAfterCursor: String = stringAfterPosition(string, cursorPositionStart)
        val operatorAfterDigit: String = if (afterDigitArray.any { stringAfterCursor.startsWith(it) }) DefaultOperator.Multiply.text else ""

        val stringBeforeCursor: String = stringBeforePosition(string, cursorPositionStart)
        val operatorBeforeDigit: String = if (beforeDigitArray.any { stringBeforeCursor.endsWith(it) }) DefaultOperator.Multiply.text else ""

        val textInsert = "$operatorBeforeDigit$digit$operatorAfterDigit"
        inputEditText.text?.insert(cursorPositionStart, textInsert)

        correctPositionIfOperatorAfterNumberIsSpace(operatorAfterDigit, inputEditText)
    }

function for entering digits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zero million

2 participants