fix: editor whitespaces
This commit is contained in:
@@ -308,6 +308,65 @@ func TestEditorKeepsWrappedRowsAndContextRailsVisible(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditorWordWrapHidesSoftWrapSpacesWithoutChangingText(t *testing.T) {
|
||||
const value = "abcdefghij hello"
|
||||
visual := editorVisualLines(value, 10)
|
||||
if len(visual) != 2 || visual[0].text != "abcdefghij" || visual[1].text != "hello" {
|
||||
t.Fatalf("word-wrapped lines = %#v", visual)
|
||||
}
|
||||
if visual[1].start != 10 || visual[1].displayStart != 11 {
|
||||
t.Fatalf("wrapped separator offsets = %#v", visual[1])
|
||||
}
|
||||
|
||||
editor := newTextEditor(value, true)
|
||||
editor.Cursor = len([]rune(value))
|
||||
rendered := renderTextEditor(editor, 10, false)
|
||||
if got := ansi.Strip(rendered[1].text); got != "hello" {
|
||||
t.Fatalf("wrapped row begins with separator space: %q", got)
|
||||
}
|
||||
if editor.Text != value {
|
||||
t.Fatalf("word wrapping changed stored text: %q", editor.Text)
|
||||
}
|
||||
|
||||
visual = editorVisualLines("hello world", 10)
|
||||
if len(visual) != 2 || visual[0].text != "hello" || visual[1].text != "world" {
|
||||
t.Fatalf("overflowing word was split instead of moved: %#v", visual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditorBoundarySpaceCreatesEmptyVisualRow(t *testing.T) {
|
||||
const value = "abcdefghij "
|
||||
visual := editorVisualLines(value, 10)
|
||||
if len(visual) != 2 || visual[0].text != "abcdefghij" || visual[1].text != "" {
|
||||
t.Fatalf("boundary-space lines = %#v", visual)
|
||||
}
|
||||
if visual[1].start != 10 || visual[1].displayStart != 11 || visual[1].end != 11 {
|
||||
t.Fatalf("boundary-space offsets = %#v", visual[1])
|
||||
}
|
||||
editor := newTextEditor(value, true)
|
||||
editor.Cursor = len([]rune(value))
|
||||
if line, column := editorCursorVisualPosition(editor, 10); line != 1 || column != 0 {
|
||||
t.Fatalf("boundary-space cursor = row %d column %d, want row 1 column 0", line, column)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditorWordWrapHardWrapsWordsWiderThanViewport(t *testing.T) {
|
||||
const value = "hi abcdefghijklmnopqrstuv"
|
||||
visual := editorVisualLines(value, 10)
|
||||
want := []string{"hi", "abcdefghij", "klmnopqrst", "uv"}
|
||||
if len(visual) != len(want) {
|
||||
t.Fatalf("long-word rows = %#v, want %q", visual, want)
|
||||
}
|
||||
for index, line := range visual {
|
||||
if line.text != want[index] {
|
||||
t.Fatalf("long-word row %d = %q, want %q", index, line.text, want[index])
|
||||
}
|
||||
if ansi.StringWidth(line.text) > 10 {
|
||||
t.Fatalf("long-word row %d exceeds viewport: %q", index, line.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVimEditorTreatsSoftWrapsAsVisualLinesWithoutChangingText(t *testing.T) {
|
||||
const value = "abcdefghijklmnopqrstuv"
|
||||
editor := newTextEditor(value, true)
|
||||
|
||||
Reference in New Issue
Block a user