New creates a new editor component
(hist *history.History, opts ...Option)
| 194 | |
| 195 | // New creates a new editor component |
| 196 | func New(hist *history.History, opts ...Option) Editor { |
| 197 | ta := textarea.New() |
| 198 | ta.SetStyles(styles.InputStyle) |
| 199 | ta.Placeholder = defaultPlaceholder |
| 200 | ta.Prompt = "" |
| 201 | ta.CharLimit = -1 |
| 202 | ta.SetWidth(50) |
| 203 | ta.SetHeight(3) // Set minimum 3 lines for multi-line input |
| 204 | ta.Focus() |
| 205 | ta.ShowLineNumbers = false |
| 206 | |
| 207 | si := textinput.New() |
| 208 | si.Prompt = "" |
| 209 | si.Placeholder = "Type to search..." |
| 210 | |
| 211 | // Customize styles for search input |
| 212 | s := styles.DialogInputStyle |
| 213 | s.Focused.Text = styles.MutedStyle |
| 214 | s.Focused.Placeholder = styles.MutedStyle |
| 215 | s.Blurred.Text = styles.MutedStyle |
| 216 | s.Blurred.Placeholder = styles.MutedStyle |
| 217 | si.SetStyles(s) |
| 218 | |
| 219 | e := &editor{ |
| 220 | textarea: ta, |
| 221 | searchInput: si, |
| 222 | hist: hist, |
| 223 | placeholder: defaultPlaceholder, |
| 224 | keyboardEnhancementsSupported: termfeatures.SupportsModifiedEnter(os.Getenv), |
| 225 | banner: newAttachmentBanner(), |
| 226 | } |
| 227 | |
| 228 | // Apply options |
| 229 | for _, opt := range opts { |
| 230 | opt(e) |
| 231 | } |
| 232 | |
| 233 | e.configureNewlineKeybinding() |
| 234 | |
| 235 | return e |
| 236 | } |
| 237 | |
| 238 | // Init initializes the component |
| 239 | func (e *editor) Init() tea.Cmd { |