MCPcopy
hub / github.com/c-bata/go-prompt / Document

Method Document

buffer.go:25–36  ·  view source on GitHub ↗

Document method to return document instance from the current text and cursor position.

()

Source from the content-addressed store, hash-verified

23
24// Document method to return document instance from the current text and cursor position.
25func (b *Buffer) Document() (d *Document) {
26 if b.cacheDocument == nil ||
27 b.cacheDocument.Text != b.Text() ||
28 b.cacheDocument.cursorPosition != b.cursorPosition {
29 b.cacheDocument = &Document{
30 Text: b.Text(),
31 cursorPosition: b.cursorPosition,
32 }
33 }
34 b.cacheDocument.lastKey = b.lastKeyStroke
35 return b.cacheDocument
36}
37
38// DisplayCursorPosition returns the cursor position on rendered text on terminal emulators.
39// So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.

Callers 15

TestBuffer_CursorUpFunction · 0.95
TestBuffer_CursorDownFunction · 0.95
DisplayCursorPositionMethod · 0.95
CursorLeftMethod · 0.95
CursorRightMethod · 0.95
CursorUpMethod · 0.95
CursorDownMethod · 0.95
NewLineMethod · 0.95
DeleteMethod · 0.95
JoinNextLineMethod · 0.95
RunMethod · 0.80

Calls 1

TextMethod · 0.95

Tested by 3

TestBuffer_CursorUpFunction · 0.76
TestBuffer_CursorDownFunction · 0.76