From 1002d440a3aa8a1608dbc66ed89ce3fdd3d6face Mon Sep 17 00:00:00 2001 From: Deniz Cakan Date: Sun, 22 Dec 2019 21:18:48 +0100 Subject: [PATCH] attach last key stroke to document --- buffer.go | 2 ++ document.go | 6 ++++++ prompt.go | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/buffer.go b/buffer.go index e4ba6f0..4b94af2 100644 --- a/buffer.go +++ b/buffer.go @@ -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 } diff --git a/document.go b/document.go index 54b7a37..2a47f52 100644 --- a/document.go +++ b/document.go @@ -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 { diff --git a/prompt.go b/prompt.go index 4e3ef43..c9bd68d 100644 --- a/prompt.go +++ b/prompt.go @@ -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)