5 Commits

Author SHA1 Message Date
Christian Rocha
7ecce3fb97 Ignore width/height settings in viewport's style settings
The Lip Gloss width and height settings compete with the main
width/height settings and can result in funny rendering and generally
cause confusion.
2022-01-20 13:23:58 -05:00
Christian Rocha
746834a7ce Add safety check in textinput's clamp 2022-01-20 13:23:58 -05:00
Christian Rocha
fd306528f9 Rename var in deleteWordRight in textinput for additional clarity 2022-01-20 13:23:58 -05:00
Christian Rocha
a4dc540f3d Re-add panic guard in deleteWordLeft in textinput, just in case 2022-01-20 13:23:58 -05:00
IllusionMan1212
151d1026dd fix(textinput): use old cursor pos and simplify logic 2022-01-19 18:31:55 -05:00
2 changed files with 18 additions and 7 deletions

View File

@@ -412,6 +412,11 @@ func (m *Model) deleteWordLeft() bool {
return m.deleteBeforeCursor()
}
// Linter note: it's critical that we acquire the initial cursor position
// here prior to altering it via SetCursor() below. As such, moving this
// call into the corresponding if clause does not apply here.
oldPos := m.pos //nolint:ifshort
blink := m.setCursor(m.pos - 1)
for unicode.IsSpace(m.value[m.pos]) {
if m.pos <= 0 {
@@ -433,10 +438,10 @@ func (m *Model) deleteWordLeft() bool {
}
}
if m.pos > len(m.value) {
if oldPos > len(m.value) {
m.value = m.value[:m.pos]
} else {
m.value = append(m.value[:m.pos], m.value[m.pos:]...)
m.value = append(m.value[:m.pos], m.value[oldPos:]...)
}
return blink
@@ -454,7 +459,7 @@ func (m *Model) deleteWordRight() bool {
return m.deleteAfterCursor()
}
i := m.pos
oldPos := m.pos
m.setCursor(m.pos + 1)
for unicode.IsSpace(m.value[m.pos]) {
// ignore series of whitespace after cursor
@@ -474,12 +479,12 @@ func (m *Model) deleteWordRight() bool {
}
if m.pos > len(m.value) {
m.value = m.value[:i]
m.value = m.value[:oldPos]
} else {
m.value = append(m.value[:i], m.value[m.pos:]...)
m.value = append(m.value[:oldPos], m.value[m.pos:]...)
}
return m.setCursor(i)
return m.setCursor(oldPos)
}
// wordLeft moves the cursor one word to the left. Returns whether or not the
@@ -795,6 +800,9 @@ func Paste() tea.Msg {
}
func clamp(v, low, high int) int {
if high < low {
low, high = high, low
}
return min(high, max(low, v))
}

View File

@@ -358,7 +358,10 @@ func (m Model) View() string {
extraLines = strings.Repeat("\n", max(0, m.Height-len(lines)))
}
return m.Style.Render(strings.Join(lines, "\n") + extraLines)
return m.Style.Copy().
UnsetWidth().
UnsetHeight().
Render(strings.Join(lines, "\n") + extraLines)
}
func clamp(v, low, high int) int {