attach last key stroke to document

This commit is contained in:
Deniz Cakan 2019-12-22 21:18:48 +01:00
parent 0f95e1d1de
commit 1002d440a3
3 changed files with 9 additions and 1 deletions

@ -13,6 +13,7 @@ type Buffer struct {
cursorPosition int cursorPosition int
cacheDocument *Document cacheDocument *Document
preferredColumn int // Remember the original column for the next up/down movement. preferredColumn int // Remember the original column for the next up/down movement.
lastKeyStroke Key
} }
// Text returns string of the current line. // Text returns string of the current line.
@ -30,6 +31,7 @@ func (b *Buffer) Document() (d *Document) {
cursorPosition: b.cursorPosition, cursorPosition: b.cursorPosition,
} }
} }
b.cacheDocument.lastKey = b.lastKeyStroke
return b.cacheDocument return b.cacheDocument
} }

@ -16,6 +16,7 @@ type Document struct {
// So if Document is "日本(cursor)語", cursorPosition is 2. // So if Document is "日本(cursor)語", cursorPosition is 2.
// But DisplayedCursorPosition returns 4 because '日' and '本' are double width characters. // But DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
cursorPosition int cursorPosition int
lastKey Key
} }
// NewDocument return the new empty document. // NewDocument return the new empty document.
@ -26,6 +27,11 @@ func NewDocument() *Document {
} }
} }
// LastKeyStroke return the last key pressed in this document.
func (d *Document) LastKeyStroke() Key {
return d.lastKey
}
// DisplayCursorPosition returns the cursor position on rendered text on terminal emulators. // DisplayCursorPosition returns the cursor position on rendered text on terminal emulators.
// So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters. // So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
func (d *Document) DisplayCursorPosition() int { func (d *Document) DisplayCursorPosition() int {

@ -98,7 +98,7 @@ func (p *Prompt) Run() {
func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) { func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
key := GetKey(b) key := GetKey(b)
p.buf.lastKeyStroke = key
// completion // completion
completing := p.completion.Completing() completing := p.completion.Completing()
p.handleCompletionKeyBinding(key, completing) p.handleCompletionKeyBinding(key, completing)