mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-01-11 22:41:03 +03:00
Don't allow word-based deletion when input is masked in textinput
alt+d and ctrl+w will now delete all the way to the beginning and end, respectively, if EchoMode is not EchoNormal.
This commit is contained in:
parent
58a177394e
commit
9449cc7e41
@ -311,6 +311,22 @@ func (m *Model) handleOverflow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deleteBeforeCursor deletes all text before the cursor. Returns whether or
|
||||||
|
// not the cursor blink should be reset.
|
||||||
|
func (m *Model) deleteBeforeCursor() bool {
|
||||||
|
m.value = m.value[m.pos:]
|
||||||
|
m.offset = 0
|
||||||
|
return m.setCursor(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteAfterCursor deletes all text after the cursor. Returns whether or not
|
||||||
|
// the cursor blink should be reset. If input is masked delete everything after
|
||||||
|
// the cursor so as not to reveal word breaks in the masked input.
|
||||||
|
func (m *Model) deleteAfterCursor() bool {
|
||||||
|
m.value = m.value[:m.pos]
|
||||||
|
return m.setCursor(len(m.value))
|
||||||
|
}
|
||||||
|
|
||||||
// deleteWordLeft deletes the word left to the cursor. Returns whether or not
|
// deleteWordLeft deletes the word left to the cursor. Returns whether or not
|
||||||
// the cursor blink should be reset.
|
// the cursor blink should be reset.
|
||||||
func (m *Model) deleteWordLeft() bool {
|
func (m *Model) deleteWordLeft() bool {
|
||||||
@ -318,6 +334,10 @@ func (m *Model) deleteWordLeft() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.EchoMode != EchoNormal {
|
||||||
|
return m.deleteBeforeCursor()
|
||||||
|
}
|
||||||
|
|
||||||
i := m.pos
|
i := m.pos
|
||||||
blink := m.setCursor(m.pos - 1)
|
blink := m.setCursor(m.pos - 1)
|
||||||
for unicode.IsSpace(m.value[m.pos]) {
|
for unicode.IsSpace(m.value[m.pos]) {
|
||||||
@ -347,12 +367,17 @@ func (m *Model) deleteWordLeft() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deleteWordRight deletes the word right to the cursor. Returns whether or not
|
// deleteWordRight deletes the word right to the cursor. Returns whether or not
|
||||||
// the cursor blink should be reset.
|
// the cursor blink should be reset. If input is masked delete everything after
|
||||||
|
// the cursor so as not to reveal word breaks in the masked input.
|
||||||
func (m *Model) deleteWordRight() bool {
|
func (m *Model) deleteWordRight() bool {
|
||||||
if m.pos >= len(m.value) || len(m.value) == 0 {
|
if m.pos >= len(m.value) || len(m.value) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.EchoMode != EchoNormal {
|
||||||
|
return m.deleteAfterCursor()
|
||||||
|
}
|
||||||
|
|
||||||
i := m.pos
|
i := m.pos
|
||||||
m.setCursor(m.pos + 1)
|
m.setCursor(m.pos + 1)
|
||||||
for unicode.IsSpace(m.value[m.pos]) {
|
for unicode.IsSpace(m.value[m.pos]) {
|
||||||
@ -509,12 +534,9 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
case tea.KeyCtrlE, tea.KeyEnd: // ^E, go to end
|
case tea.KeyCtrlE, tea.KeyEnd: // ^E, go to end
|
||||||
resetBlink = m.cursorEnd()
|
resetBlink = m.cursorEnd()
|
||||||
case tea.KeyCtrlK: // ^K, kill text after cursor
|
case tea.KeyCtrlK: // ^K, kill text after cursor
|
||||||
m.value = m.value[:m.pos]
|
resetBlink = m.deleteAfterCursor()
|
||||||
resetBlink = m.setCursor(len(m.value))
|
|
||||||
case tea.KeyCtrlU: // ^U, kill text before cursor
|
case tea.KeyCtrlU: // ^U, kill text before cursor
|
||||||
m.value = m.value[m.pos:]
|
resetBlink = m.deleteBeforeCursor()
|
||||||
resetBlink = m.setCursor(0)
|
|
||||||
m.offset = 0
|
|
||||||
case tea.KeyCtrlV: // ^V paste
|
case tea.KeyCtrlV: // ^V paste
|
||||||
return m, Paste
|
return m, Paste
|
||||||
case tea.KeyRunes: // input regular characters
|
case tea.KeyRunes: // input regular characters
|
||||||
|
Loading…
Reference in New Issue
Block a user