Skip to content

Implemented rangeLimit for input / And NoErase#151

Merged
elcritch merged 4 commits into
elcritch:mainfrom
derek-v-s:rangelimit
May 25, 2025
Merged

Implemented rangeLimit for input / And NoErase#151
elcritch merged 4 commits into
elcritch:mainfrom
derek-v-s:rangelimit

Conversation

@derek-v-s

Copy link
Copy Markdown
Collaborator

Issue #149

  • implemented rangeLimit as an int parameter for the insert proc
  • implemented overWrite as a boolean parameter for the insert proc
  • added NoErase to the delete/backspace logic of the input widget
  • fixed the updateInput override in tinput2.nim
  • ensured all tests pass in ttextboxes.nim

Issue elcritch#149

- implemented rangeLimit as an int parameter for the insert proc
- implemented overWrite as a boolean parameter for the insert proc
- added NoErase to the delete/backspace logic of the input widget
- fixed the updateInput override in tinput2.nim
- ensured all tests pass in ttextboxes.nim
Comment thread tests/tinput2.nim
Comment on lines 82 to +93
proc overrideUpdateInput(this: Input, rune: Rune) {.slot.} =
let isDigit = rune <=% Rune('9') and rune.char in {'0'..'9'}
template currCharColon(): bool = this.text.runeAtCursor() == Rune(':')
this.skipSelectedRune()
if isDigit:
this.updateInput(rune)
this.text.insert(rune, overWrite = true, rangeLimit = 8)
onInit:
this.activate()

disconnect(this, doUpdateInput, this, updateInput)
connect(this, doUpdateInput, this, overrideUpdateInput)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting double input per key press from the original code. This probably isn't the optimal solution, but I figured you could help with that.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting double input per key press from the original code. This probably isn't the optimal solution, but I figured you could help with that.

Ah yep that's the bit related to moving the connect's into initialize. This might not be a bad way to do it. It's more explicit for widget user, but maybe that's not bad.

Basically we just need to come up with a pattern that's fairly easy to follow.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the bit related to moving the connect's into initialize.

Ahh right... too obvious. ;-]

Basically we just need to come up with a pattern that's fairly easy to follow.

Agreed. I think the before and after signals as proposed in #150 serves as a much more powerful pattern than what I've done here. That said, this seems to work as a temporary fix for tinput2.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points, looks good for now. Let's see how it plays out. There's might be benefits to modifying the connect's like this. It's essentially just storing the state in a table in the input object. It's not a huge overhead.

@elcritch elcritch merged commit 4228ad6 into elcritch:main May 25, 2025
2 checks passed
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.

2 participants