summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-04-10 16:49:51 +0000
committerhallgren <hallgren@chalmers.se>2012-04-10 16:49:51 +0000
commit89b415ac37dd510dd5ca3cd7735707c87662d69b (patch)
tree48e015091840a4b710797f6031c43b134154721d /src
parent500daf3bd4bbefa64b80d9920e4288f89abc8cfe (diff)
minibar_input.js: internal state simplification
Get rid of list of previous states, which was only used to delete the last word.
Diffstat (limited to 'src')
-rw-r--r--src/www/minibar/minibar_input.js14
-rw-r--r--src/www/minibar/minibar_support.js4
2 files changed, 11 insertions, 7 deletions
diff --git a/src/www/minibar/minibar_input.js b/src/www/minibar/minibar_input.js
index a5a169cc7..88a410114 100644
--- a/src/www/minibar/minibar_input.js
+++ b/src/www/minibar/minibar_input.js
@@ -40,7 +40,6 @@ function Input(server,translations,opts) { // Input object constructor
/* --- Input client state initialization --- */
this.current={from: null, input: ""};
- this.previous=null;
this.from_menu.onchange=bind(this.change_language,this);
this.startcat_menu.onchange=bind(this.change_startcat,this);
@@ -90,7 +89,6 @@ Input.prototype.clear_all2=function() {
with(this) {
current.input="";
local.put("current",current)
- previous=null;
clear(surface)
if(surface.typed) surface.appendChild(surface.typed)
}
@@ -125,7 +123,8 @@ Input.prototype.show_completions=function(complete_output) {
//debug("show_completions ");
var completions=complete_output[0].completions;
var emptycnt=add_completions(completions)
- if(true/*emptycnt>0*/) translations.translateFrom(current,startcat_menu.value);
+ if(true/*emptycnt>0*/)
+ translations.translateFrom(current,startcat_menu.value);
else translations.clear();
if(surface.typed && emptycnt==completions.length) {
if(surface.typed.value=="") remove_typed_input();
@@ -281,7 +280,6 @@ Input.prototype.add_word=function(s) {
Input.prototype.add_word1=function(s) {
with(this) {
- previous={ input: current.input, previous: previous };
current.input+=s;
local.put("current",current)
var w=span_class("word",text(s));
@@ -294,10 +292,12 @@ Input.prototype.delete_last=function() {
with(this) {
if(surface.typed && surface.typed.value!="")
surface.typed.value="";
- else if(previous) {
- current.input=previous.input;
+ else if(current.input.length>1) {
+ var ws=gf_lex(current.input)
+ var w=ws.pop();
+ if(w=="") { ws.pop(); ws.push(""); }
+ current.input=gf_unlex(ws);
local.put("current",current)
- previous=previous.previous;
if(surface.typed) {
surface.removeChild(surface.typed.previousSibling);
surface.typed.focus();
diff --git a/src/www/minibar/minibar_support.js b/src/www/minibar/minibar_support.js
index a3fc078f7..f5919fa05 100644
--- a/src/www/minibar/minibar_support.js
+++ b/src/www/minibar/minibar_support.js
@@ -5,6 +5,10 @@ function langpart(conc,abs) { // langpart("FoodsEng","Foods") == "Eng"
return hasPrefix(conc,abs) ? conc.substr(abs.length) : conc;
}
+// Words are separated by spaces (for now). GF has other lexers/unlexers.
+function gf_lex(s) { return s.split(" "); }
+function gf_unlex(ws) { return ws.join(" "); }
+
function update_language_menu(menu,grammar) {
// Replace the options in the menu with the languages in the grammar
var lang=grammar.languages;