Skip to content

Commit

Permalink
Delegate Cursor Logic to cursor bubble (#181)
Browse files Browse the repository at this point in the history
* refactor: remove cursor logic from textinput
* chore: Add Deprecated Fields to avoid breaking changes
* fix: Ctrl+A and typing moves to end bug
  • Loading branch information
maaslalani authored Sep 14, 2022
1 parent 062b257 commit a99b55c
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 323 deletions.
36 changes: 18 additions & 18 deletions cursor/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ 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.
func New() Model {
return Model{
BlinkSpeed: defaultBlinkSpeed,

Blink: true,
cursorMode: CursorBlink,
Blink: true,
mode: CursorBlink,

blinkCtx: &blinkCtx{
ctx: context.Background(),
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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()
}
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit a99b55c

Please sign in to comment.