-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query history navigation shortcuts and functionality
- Loading branch information
1 parent
e53c6d0
commit f141dda
Showing
12 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
type queryHistoryType struct { | ||
history []string | ||
index int | ||
} | ||
|
||
var queryHistory queryHistoryType | ||
|
||
func (queryHistory *queryHistoryType) back() string { | ||
if queryHistory.getUpperIndex() > 0 && queryHistory.index > 0 { | ||
queryHistory.index-- | ||
return queryHistory.history[queryHistory.index] | ||
} | ||
queryHistory.index = 0 | ||
return "" | ||
} | ||
|
||
func (queryHistory *queryHistoryType) forward() string { | ||
if queryHistory.index < queryHistory.getUpperIndex() { | ||
queryHistory.index++ | ||
return queryHistory.history[queryHistory.index] | ||
} | ||
queryHistory.resetIndex() | ||
return "" | ||
} | ||
|
||
func (queryHistory *queryHistoryType) add(historyEntry string) { | ||
queryHistory.history = append(queryHistory.history, historyEntry) | ||
} | ||
|
||
func (queryHistory *queryHistoryType) getUpperIndex() int { | ||
return len(queryHistory.history) - 1 | ||
} | ||
|
||
func (queryHistory *queryHistoryType) resetIndex() { | ||
queryHistory.index = queryHistory.getUpperIndex() | ||
} |