[PR #927] [CLOSED] fix remove dropdown option index out of range #1078

Closed
opened 2026-03-04 01:09:20 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/rivo/tview/pull/927
Author: @7yyo
Created: 12/7/2023
Status: Closed

Base: masterHead: drop_down_index_out_of_range


📝 Commits (2)

  • 5f2dcc8 fix remove dropdown option index out of range
  • d27f9f4 fix remove dropdown option index out of range

📊 Changes

1 file changed (+7 additions, -2 deletions)

View changed files

📝 dropdown.go (+7 -2)

📄 Description

@rivo

Hi, when setSelectFunc of dropdown to remove current option, if the last option is selected, index out of range will panic. I tried to fix this bug.

The code below will reproduce this bug if select the last option Fifth.

package main

import "github.com/rivo/tview"

func main() {
	app := tview.NewApplication()
	dropdown := tview.NewDropDown()
	dropdown.SetLabel("Select an option (hit Enter): ")
	selectFunc := func(text string, index int) {
		dropdown.RemoveOption(index)
	}
	dropdown.SetOptions([]string{"First", "Second", "Third", "Fourth", "Fifth"}, selectFunc)
	if err := app.SetRoot(dropdown, true).EnableMouse(true).Run(); err != nil {
		panic(err)
	}
}


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/rivo/tview/pull/927 **Author:** [@7yyo](https://github.com/7yyo) **Created:** 12/7/2023 **Status:** ❌ Closed **Base:** `master` ← **Head:** `drop_down_index_out_of_range` --- ### 📝 Commits (2) - [`5f2dcc8`](https://github.com/rivo/tview/commit/5f2dcc8d92349c3ec0faab11c83d46a5cb6c9f0f) fix remove dropdown option index out of range - [`d27f9f4`](https://github.com/rivo/tview/commit/d27f9f4dc92e54e07785b000e907e65ff417589d) fix remove dropdown option index out of range ### 📊 Changes **1 file changed** (+7 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `dropdown.go` (+7 -2) </details> ### 📄 Description @rivo Hi, when setSelectFunc of dropdown to remove current option, if the last option is selected, index out of range will panic. I tried to fix this bug. The code below will reproduce this bug if select the last option `Fifth`. ```go package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() dropdown := tview.NewDropDown() dropdown.SetLabel("Select an option (hit Enter): ") selectFunc := func(text string, index int) { dropdown.RemoveOption(index) } dropdown.SetOptions([]string{"First", "Second", "Third", "Fourth", "Fifth"}, selectFunc) if err := app.SetRoot(dropdown, true).EnableMouse(true).Run(); err != nil { panic(err) } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 01:09:20 +03:00
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#1078
No description provided.