mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-10-10 06:11:22 +03:00
Delegate Cursor Logic to cursor
bubble (#181)
* refactor: remove cursor logic from textinput * chore: Add Deprecated Fields to avoid breaking changes * fix: Ctrl+A and typing moves to end bug
This commit is contained in:
@@ -70,8 +70,8 @@ type Model struct {
|
||||
blinkCtx *blinkCtx
|
||||
// The ID of the blink message we're expecting to receive.
|
||||
blinkTag int
|
||||
// cursorMode determines the behavior of the cursor
|
||||
cursorMode Mode
|
||||
// mode determines the behavior of the cursor
|
||||
mode Mode
|
||||
}
|
||||
|
||||
// New creates a new model with default settings.
|
||||
@@ -79,8 +79,8 @@ func New() Model {
|
||||
return Model{
|
||||
BlinkSpeed: defaultBlinkSpeed,
|
||||
|
||||
Blink: true,
|
||||
cursorMode: CursorBlink,
|
||||
Blink: true,
|
||||
mode: CursorBlink,
|
||||
|
||||
blinkCtx: &blinkCtx{
|
||||
ctx: context.Background(),
|
||||
@@ -94,7 +94,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
case initialBlinkMsg:
|
||||
// We accept all initialBlinkMsgs generated by the Blink command.
|
||||
|
||||
if m.cursorMode != CursorBlink || !m.focus {
|
||||
if m.mode != CursorBlink || !m.focus {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
// only exactly when it should.
|
||||
|
||||
// Is this model blink-able?
|
||||
if m.cursorMode != CursorBlink || !m.focus {
|
||||
if m.mode != CursorBlink || !m.focus {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
if m.cursorMode == CursorBlink {
|
||||
if m.mode == CursorBlink {
|
||||
m.Blink = !m.Blink
|
||||
cmd = m.BlinkCmd()
|
||||
}
|
||||
@@ -128,18 +128,18 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// CursorMode returns the model's cursor mode. For available cursor modes, see
|
||||
// type CursorMode.
|
||||
func (m Model) CursorMode() Mode {
|
||||
return m.cursorMode
|
||||
// Mode returns the model's cursor mode. For available cursor modes, see
|
||||
// type Mode.
|
||||
func (m Model) Mode() Mode {
|
||||
return m.mode
|
||||
}
|
||||
|
||||
// SetCursorMode sets the model's cursor mode. This method returns a command.
|
||||
// SetMode sets the model's cursor mode. This method returns a command.
|
||||
//
|
||||
// For available cursor modes, see type CursorMode.
|
||||
func (m *Model) SetCursorMode(mode Mode) tea.Cmd {
|
||||
m.cursorMode = mode
|
||||
m.Blink = m.cursorMode == CursorHide || !m.focus
|
||||
func (m *Model) SetMode(mode Mode) tea.Cmd {
|
||||
m.mode = mode
|
||||
m.Blink = m.mode == CursorHide || !m.focus
|
||||
if mode == CursorBlink {
|
||||
return Blink
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (m *Model) SetCursorMode(mode Mode) tea.Cmd {
|
||||
|
||||
// BlinkCmd is an command used to manage cursor blinking.
|
||||
func (m *Model) BlinkCmd() tea.Cmd {
|
||||
if m.cursorMode != CursorBlink {
|
||||
if m.mode != CursorBlink {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -179,9 +179,9 @@ func Blink() tea.Msg {
|
||||
// Focus focuses the cursor to allow it to blink if desired.
|
||||
func (m *Model) Focus() tea.Cmd {
|
||||
m.focus = true
|
||||
m.Blink = m.cursorMode == CursorHide // show the cursor unless we've explicitly hidden it
|
||||
m.Blink = m.mode == CursorHide // show the cursor unless we've explicitly hidden it
|
||||
|
||||
if m.cursorMode == CursorBlink && m.focus {
|
||||
if m.mode == CursorBlink && m.focus {
|
||||
return m.BlinkCmd()
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user