mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
parent
9f8c5b8c36
commit
c1dce24645
@ -285,7 +285,7 @@ private fun Ready(
|
||||
clearSymbols = clearSymbols,
|
||||
deleteSymbol = deleteSymbol,
|
||||
toggleAngleMode = toggleAngleMode,
|
||||
equal = equal,
|
||||
equal = { focusManager.clearFocus(); equal() },
|
||||
middleZero = uiState.middleZero,
|
||||
acButton = uiState.acButton,
|
||||
addBracket = addBracket
|
||||
|
@ -116,16 +116,16 @@ internal class CalculatorViewModel @Inject constructor(
|
||||
.stateIn(viewModelScope, CalculatorUIState.Loading)
|
||||
|
||||
fun addTokens(tokens: String) = _input.update {
|
||||
var newValue = if (_equalClicked.value and Token.Digit.allWithDot.contains(tokens)) {
|
||||
val isClearInputNeeded = _equalClicked.value and Token.Digit.allWithDot.contains(tokens)
|
||||
|
||||
var newValue = when {
|
||||
// Clean input after clicking "=" and any token that is a Digit
|
||||
TextFieldValue().addTokens(tokens)
|
||||
} else {
|
||||
it.addTokens(tokens)
|
||||
}
|
||||
// Cursor is set to 0 when equal is clicked
|
||||
if (_equalClicked.value) {
|
||||
newValue = newValue.copy(selection = TextRange(it.text.length))
|
||||
isClearInputNeeded -> TextFieldValue()
|
||||
_equalClicked.value -> it.copy(selection = TextRange(it.text.length))
|
||||
else -> it
|
||||
}
|
||||
newValue = newValue.addTokens(tokens)
|
||||
|
||||
_equalClicked.update { false }
|
||||
_fractionJob?.cancel()
|
||||
savedStateHandle[_inputKey] = newValue.text
|
||||
@ -133,11 +133,14 @@ internal class CalculatorViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun addBracket() = _input.update {
|
||||
var newValue = it.addBracket()
|
||||
var newValue = if (_equalClicked.value) {
|
||||
// Cursor is set to 0 when equal is clicked
|
||||
if (_equalClicked.value) {
|
||||
newValue = newValue.copy(selection = TextRange(it.text.length))
|
||||
it.copy(selection = TextRange(it.text.length))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
newValue = newValue.addBracket()
|
||||
|
||||
_equalClicked.update { false }
|
||||
_fractionJob?.cancel()
|
||||
savedStateHandle[_inputKey] = newValue.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user