input history

This commit is contained in:
Evert Prants 2016-09-25 22:58:28 +03:00
parent f05fcef7db
commit 4adfb7e79c
3 changed files with 58 additions and 0 deletions

View File

@ -654,6 +654,18 @@ body {
.topicbar .irc-fg15 {
color: #d3d3d3;
}
.message .irc-bold,
.topicbar .irc-bold {
font-weight: bold;
}
.message .irc-italic,
.topicbar .irc-italic {
font-style: italic;
}
.message .irc-underline,
.topicbar .irc-underline {
text-decoration: underline;
}
@media all and (max-width: 600px) {
.vnicks .nicklist {
display: none !important;

View File

@ -957,6 +957,7 @@ class IRCConnector {
class InputHandler {
constructor() {
this.history = [];
this.historyCaret = 0;
clientdom.input.onkeyup = (evt) => {
let key = evt.keyCode || evt.which || evt.charCode || 0;
@ -965,6 +966,44 @@ class InputHandler {
}
}
clientdom.input.onkeydown = (evt) => {
let key = evt.keyCode || evt.which || evt.charCode || 0;
if(key == 38) {
if(this.historyCaret <= 0) {
this.historyCaret = 0;
} else {
this.historyCaret -= 1;
}
let selection = this.history[this.historyCaret];
if(selection) {
clientdom.input.value = selection;
clientdom.input.selectionStart = selection.length;
clientdom.input.selectionEnd = selection.length;
}
return false;
} else if(key == 40) {
if(this.historyCaret >= this.history.length) {
this.historyCaret = this.history.length;
} else {
this.historyCaret += 1;
}
let selection = this.history[this.historyCaret]
if(!this.history[this.historyCaret])
selection = '';
clientdom.input.selectionStart = selection.length;
clientdom.input.selectionEnd = selection.length;
clientdom.input.value = selection;
return false;
}
}
clientdom.send.onclick = (e) => {
this.handleInput();
}
@ -1063,6 +1102,7 @@ class InputHandler {
}
this.history.push(inp);
this.historyCaret = this.history.length;
clientdom.input.value = "";
}

View File

@ -472,6 +472,12 @@ body
color: grey
.irc-fg15
color: lightgrey
.irc-bold
font-weight: bold
.irc-italic
font-style: italic
.irc-underline
text-decoration: underline
@media all and (max-width: 600px)
.vnicks