Merge pull request #13 from ethereum/fixHistory

fix history
pull/1/head
Alexander Praetorius 7 years ago committed by GitHub
commit 8a1c897332
  1. 24
      src/app/panels/terminal.js

@ -399,6 +399,7 @@ class Terminal {
} }
self._cmdHistory = [] self._cmdHistory = []
self._cmdIndex = -1
self._cmdTemp = '' self._cmdTemp = ''
return self._view.el return self._view.el
@ -411,31 +412,34 @@ class Terminal {
putCursor2End(self._view.input) putCursor2End(self._view.input)
self.scroll2bottom() self.scroll2bottom()
} else { // <enter> } else { // <enter>
self._cmdIndex = -1
self._cmdTemp = ''
event.preventDefault() event.preventDefault()
var script = self._view.input.innerText.trim() var script = self._view.input.innerText.trim()
self._view.input.innerText = '\n' self._view.input.innerText = '\n'
if (script.length) { if (script.length) {
self._cmdHistory.push(script) self._cmdHistory.unshift(script)
self.commands.script(script) self.commands.script(script)
} }
} }
} else if (event.which === 38) { // <arrowUp> } else if (event.which === 38) { // <arrowUp>
var len = self._cmdHistory.length var len = self._cmdHistory.length
if (len === 0) return event.preventDefault() if (len === 0) return event.preventDefault()
if (self._cmdIndex === undefined) { if (self._cmdHistory.length - 1 > self._cmdIndex) {
self._cmdIndex = len - 1 self._cmdIndex++
self._cmdTemp = self._view.input.innerText }
} else if (self._cmdIndex === 0) return
else self._cmdIndex -= 1
self._view.input.innerText = self._cmdHistory[self._cmdIndex] self._view.input.innerText = self._cmdHistory[self._cmdIndex]
putCursor2End(self._view.input)
self.scroll2bottom() self.scroll2bottom()
} else if (event.which === 40) { // <arrowDown> } else if (event.which === 40) { // <arrowDown>
if (self._cmdIndex === undefined) return if (self._cmdIndex > -1) {
else if (self._cmdIndex === self._cmdHistory.length - 1) self._cmdIndex = undefined self._cmdIndex--
else self._cmdIndex += 1 }
self._view.input.innerText = self._cmdHistory[self._cmdIndex] || self._cmdTemp self._view.input.innerText = self._cmdIndex >= 0 ? self._cmdHistory[self._cmdIndex] : self._cmdTemp
putCursor2End(self._view.input) putCursor2End(self._view.input)
self.scroll2bottom() self.scroll2bottom()
} else {
self._cmdTemp = self._view.input.innerText
} }
} }
function putCursor2End (editable) { function putCursor2End (editable) {

Loading…
Cancel
Save