turbo-editors/turbo-corepublic Fork 0
v0.9.0
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

example_test.go · 66 lines · 1.3 KBGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 18h ago1package buffer_test
2
3import (
4 "fmt"
5
6 "codeberg.org/turbo-editors/turbo-core/buffer"
7)
8
9// Typing into a buffer and reading the result back.
10func ExampleBuffer_Insert() {
11 b := buffer.New()
12 b.Insert("package main")
13 b.InsertNewlineAndIndent()
14 b.Insert("\nfunc main() {}")
15
16 fmt.Println(b.Text())
17 // Output:
18 // package main
19 //
20 // func main() {}
21}
22
23// A run of typed characters is one undo step, not one per keystroke.
24func ExampleBuffer_Undo() {
25 b := buffer.NewFromString("var ")
26 b.MoveBufferEnd()
27 for _, r := range "count" {
28 b.InsertRune(r)
29 }
30 fmt.Println(b.Text())
31
32 b.Undo()
33 fmt.Println(b.Text())
34 // Output:
35 // var count
36 // var
37}
38
39// Selecting a span and replacing it in one go.
40func ExampleBuffer_SelectedText() {
41 b := buffer.NewFromString("hello world")
42 b.SetCursor(buffer.Position{Line: 0, Col: 6})
43 b.StartSelection()
44 b.Extend(b.MoveLineEnd)
45
46 fmt.Println(b.SelectedText())
47
48 b.Insert("gophers")
49 fmt.Println(b.Text())
50 // Output:
51 // world
52 // hello gophers
53}
54
55// Tabs occupy several screen columns, so rune columns and screen columns are
56// not the same thing.
57func ExampleBuffer_DisplayColumn() {
58 b := buffer.NewFromString("\tif err != nil {")
59 b.SetTabWidth(4)
60
61 fmt.Println(b.DisplayColumn(0, 1)) // just after the tab
62 fmt.Println(b.RuneColumn(0, 4)) // back from the screen column
63 // Output:
64 // 4
65 // 1
66}