Document method to return document instance from the current text and cursor position.
()
| 23 | |
| 24 | // Document method to return document instance from the current text and cursor position. |
| 25 | func (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. |