[GH-ISSUE #176] inputfield: unable to enter : (colon) #141

Closed
opened 2026-03-04 01:02:18 +03:00 by kerem · 5 comments
Owner

Originally created by @joegrasse on GitHub (Oct 29, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/176

After the 990bc2ebcf commit to allow navigation in input fileds, I can no longer enter a colon. I have traced it down to the code starting here.

			modifiers := event.Modifiers()
			if modifiers == tcell.ModNone {
				ch := string(event.Rune())
				newText := i.text[:i.cursorPos] + ch + i.text[i.cursorPos:]
				if i.accept != nil {
					if !i.accept(newText, event.Rune()) {
						break
					}
				}
				i.text = newText
				i.cursorPos += len(ch)
			} else if modifiers&tcell.ModAlt > 0 {
				// We accept some Alt- key combinations.
				switch event.Rune() {
				case 'a': // Home.
					home()
				case 'e': // End.
					end()
				case 'b': // Move word left.
					moveWordLeft()
				case 'f': // Move word right.
					moveWordRight()
				}
			}

I changed it to the following and it works again.

			ch := string(event.Rune())
			newText := i.text[:i.cursorPos] + ch + i.text[i.cursorPos:]
			if i.accept != nil {
				if !i.accept(newText, event.Rune()) {
					break
				}
			}
			i.text = newText
			i.cursorPos += len(ch)

I suspect the : (colon) key has a modifier in windows.

Originally created by @joegrasse on GitHub (Oct 29, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/176 After the 990bc2ebcf815c84073a4fb08c08144808befa7f commit to allow navigation in input fileds, I can no longer enter a colon. I have traced it down to the code starting [here](https://github.com/rivo/tview/blob/990bc2ebcf815c84073a4fb08c08144808befa7f/inputfield.go#L365). ``` modifiers := event.Modifiers() if modifiers == tcell.ModNone { ch := string(event.Rune()) newText := i.text[:i.cursorPos] + ch + i.text[i.cursorPos:] if i.accept != nil { if !i.accept(newText, event.Rune()) { break } } i.text = newText i.cursorPos += len(ch) } else if modifiers&tcell.ModAlt > 0 { // We accept some Alt- key combinations. switch event.Rune() { case 'a': // Home. home() case 'e': // End. end() case 'b': // Move word left. moveWordLeft() case 'f': // Move word right. moveWordRight() } } ``` I changed it to the following and it works again. ``` ch := string(event.Rune()) newText := i.text[:i.cursorPos] + ch + i.text[i.cursorPos:] if i.accept != nil { if !i.accept(newText, event.Rune()) { break } } i.text = newText i.cursorPos += len(ch) ``` I suspect the : (colon) key has a modifier in windows.
kerem closed this issue 2026-03-04 01:02:19 +03:00
Author
Owner

@rivo commented on GitHub (Oct 29, 2018):

Thanks for letting me know. I couldn't replicate this on my Mac but I made a change that will hopefully fix this for you. If it still doesn't work, let me know.

<!-- gh-comment-id:433980283 --> @rivo commented on GitHub (Oct 29, 2018): Thanks for letting me know. I couldn't replicate this on my Mac but I made a change that will hopefully fix this for you. If it still doesn't work, let me know.
Author
Owner

@joegrasse commented on GitHub (Oct 29, 2018):

That didn't seem to fix it. What fixed it for me after your latest change was adding the following here.

			} else {
				if !add(event.Rune()) {
					break
				}
			}
<!-- gh-comment-id:434022437 --> @joegrasse commented on GitHub (Oct 29, 2018): That didn't seem to fix it. What fixed it for me after your latest change was adding the following [here](https://github.com/rivo/tview/blob/60a1c63fa9ae3540276aeb26d85b84ac37f713c7/inputfield.go#L398). ``` } else { if !add(event.Rune()) { break } } ```
Author
Owner

@joegrasse commented on GitHub (Oct 30, 2018):

@rivo I just created pull request #177 to fix this.

<!-- gh-comment-id:434343246 --> @joegrasse commented on GitHub (Oct 30, 2018): @rivo I just created pull request #177 to fix this.
Author
Owner

@rivo commented on GitHub (Nov 5, 2018):

It looks like the problem is not the Alt key but some other modifier. So I opted for a slightly different solution. Let me know if it works for you now.

<!-- gh-comment-id:435822656 --> @rivo commented on GitHub (Nov 5, 2018): It looks like the problem is not the Alt key but some other modifier. So I opted for a slightly different solution. Let me know if it works for you now.
Author
Owner

@joegrasse commented on GitHub (Nov 5, 2018):

Yes, it works. Thank you.

<!-- gh-comment-id:435934194 --> @joegrasse commented on GitHub (Nov 5, 2018): Yes, it works. Thank you.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#141
No description provided.