package buffer_test import ( "fmt" "rickub.com/turbo-editors/turbo-core/buffer" ) // Typing into a buffer and reading the result back. func ExampleBuffer_Insert() { b := buffer.New() b.Insert("package main") b.InsertNewlineAndIndent() b.Insert("\nfunc main() {}") fmt.Println(b.Text()) // Output: // package main // // func main() {} } // A run of typed characters is one undo step, not one per keystroke. func ExampleBuffer_Undo() { b := buffer.NewFromString("var ") b.MoveBufferEnd() for _, r := range "count" { b.InsertRune(r) } fmt.Println(b.Text()) b.Undo() fmt.Println(b.Text()) // Output: // var count // var } // Selecting a span and replacing it in one go. func ExampleBuffer_SelectedText() { b := buffer.NewFromString("hello world") b.SetCursor(buffer.Position{Line: 0, Col: 6}) b.StartSelection() b.Extend(b.MoveLineEnd) fmt.Println(b.SelectedText()) b.Insert("gophers") fmt.Println(b.Text()) // Output: // world // hello gophers } // Tabs occupy several screen columns, so rune columns and screen columns are // not the same thing. func ExampleBuffer_DisplayColumn() { b := buffer.NewFromString("\tif err != nil {") b.SetTabWidth(4) fmt.Println(b.DisplayColumn(0, 1)) // just after the tab fmt.Println(b.RuneColumn(0, 4)) // back from the screen column // Output: // 4 // 1 }