attach last key stroke to document
This commit is contained in:
parent
0f95e1d1de
commit
1002d440a3
@ -13,6 +13,7 @@ type Buffer struct {
|
||||
cursorPosition int
|
||||
cacheDocument *Document
|
||||
preferredColumn int // Remember the original column for the next up/down movement.
|
||||
lastKeyStroke Key
|
||||
}
|
||||
|
||||
// Text returns string of the current line.
|
||||
@ -30,6 +31,7 @@ func (b *Buffer) Document() (d *Document) {
|
||||
cursorPosition: b.cursorPosition,
|
||||
}
|
||||
}
|
||||
b.cacheDocument.lastKey = b.lastKeyStroke
|
||||
return b.cacheDocument
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ type Document struct {
|
||||
// So if Document is "日本(cursor)語", cursorPosition is 2.
|
||||
// But DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
|
||||
cursorPosition int
|
||||
lastKey Key
|
||||
}
|
||||
|
||||
// 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.
|
||||
// So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
|
||||
func (d *Document) DisplayCursorPosition() int {
|
||||
|
@ -98,7 +98,7 @@ func (p *Prompt) Run() {
|
||||
|
||||
func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
|
||||
key := GetKey(b)
|
||||
|
||||
p.buf.lastKeyStroke = key
|
||||
// completion
|
||||
completing := p.completion.Completing()
|
||||
p.handleCompletionKeyBinding(key, completing)
|
||||
|
Loading…
Reference in New Issue
Block a user