From f90b8ca7f77023d38ad932e12ca534bf7b2d1a90 Mon Sep 17 00:00:00 2001 From: handa Date: Tue, 23 Feb 2010 23:45:30 +0000 Subject: [PATCH] *** empty log message *** --- xex.js | 144 +++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 87 insertions(+), 57 deletions(-) diff --git a/xex.js b/xex.js index c76fce3..157f521 100644 --- a/xex.js +++ b/xex.js @@ -2,35 +2,6 @@ var Xex = {}; -Xex.Alist = function () -{ - this.count = 0; -} - -Xex.Alist.prototype.put = function (key, val) -{ - this.count++; - return (this[key] = val); -} -Xex.Alist.prototype.clone = function () -{ - var alist = new Xex.Alist (); - for (key in this) - alist[key] = this[key]; - return alist; -} -Xex.Alist.prototype.toString = function () -{ - var str = 'alist:'; - for (key in this) - str += '"' + key + '"'; - return str; -} - -// Xex.alist = new Xex.Alist (); -// Xex.alist.put ('abc', "ABC"); -// alert (Xex.alist['abc']); - Xex.Error = { UnknownError: "unknown-error", WrongArgument: "wrong-argument", @@ -374,6 +345,12 @@ Xex.Domain.prototype = { }, Defvar: function (name) { + if (name instanceof Xex.Variable) + { + name = name.Clone (this); + this.variables[name.name] = name; + return name; + } var vari = this.variables[name]; if (vari) { @@ -1423,10 +1400,8 @@ MIM.im_domain.DefType (MIM.State.prototype); { var ic = domain.context; var candidates = new Candidates (args, column); - var candidate = candidates.Current (); - - if ( - + ic.insert (candidates.Current (), candidates); + return args[0]; } im_domain.DefSubr (Finsert, "insert", false, 1, 1); @@ -1438,6 +1413,19 @@ MIM.im_domain.DefType (MIM.State.prototype); { this.description = node.firstChild.nodeValue; } + parses['variable-list'] = function (node) + { + for (node = node.firstChild; node; node = node.nextSibling) + { + if (node.nodeType != 1) + continue; + var name = node.attributes['vname'].nodeValue; + var vari = get_global_bar (name); + if (vari != null) + domain.Defvar (name); + Xex.Parse (domain, node); + } + } parsers['title'] = function (node) { this.title = node.firstChild.nodeValue; @@ -1649,8 +1637,7 @@ MIM.im_domain.DefType (MIM.State.prototype); { if (this.column > 0) { - var nitems = this.group.length; - var start = this.index - (this.index % nitems); + var start = this.index - (this.index % this.column); return (start + this.column <= this.total ? this.column : this.total - start); } @@ -1686,7 +1673,7 @@ MIM.im_domain.DefType (MIM.State.prototype); else { this.row = this.row > 0 ? this.row - 1 : this.blocks.length - 1; - nitems = this.blocks[this.row].Count; + nitems = this.blocks[this.row].Count (); this.index = (this.blocks[this.row].Index + (col < nitems ? col : nitems - 1)); } @@ -1724,7 +1711,7 @@ MIM.im_domain.DefType (MIM.State.prototype); else { this.row = this.row < this.blocks.length - 1 ? this.row + 1 : 0; - nitems = this.blocks[this.row].Count; + nitems = this.blocks[this.row].Count (); this.index = (this.blocks[this.row].Index + (col < nitems ? col : nitems - 1)); } @@ -1733,36 +1720,55 @@ MIM.im_domain.DefType (MIM.State.prototype); Candidates.prototype.Prev = function () { - var col = this.Column (); - - if (col == 0) + if (this.index == 0) { - int nitems = this.PrevGroup (); - this.index += col < nitems - 1 ? col : nitems - 1; + this.index = this.total - 1; + this.row = this.blocks.length - 1; } else - this.index--; - } + { + this.index--; + if (this.blocks[this.row].Index > this.index) + this.row--; + } + } Candidates.prototype.Next = function () { - int col = this.Column (); - int nitems = this.GroupLength (); - - if (col == nitems - 1) + this.index++; + if (this.index == this.total) { - nitems = this.NextGroup (); - this.index -= this.Column (); + this.index = 0; + this.row = 0; } else - this.index++; + { + var b = this.blocks[this.row]; + if (this.index == b.Index + b.Count ()) + this.row++; + } } - Candidates.prototype.First = function () { this.index -= this.Column (); } + Candidates.prototype.First = function () + { + this.index -= this.Column (); + while (this.blocks[this.row].Index > this.index) + this.row--; + } Candidates.prototype.Last = function () { - this.index += this.GroupLength () - (this.Column + 1); + var b = this.blocks[this.row]; + if (this.column > 0) + { + if (this.index + 1 < this.total) + { + this.index += this.column - this.Column () + 1; + while (b.Index + b.Count () <= this.index) + b = this.blocks[++this.row]; + } + else + this.index = b.Index + b.Count () - 1; } Candidates.prototype.Select = funciton (selector) @@ -1781,10 +1787,34 @@ MIM.im_domain.DefType (MIM.State.prototype); } return this.Current (); } - var maxcol = this.GroupLength () - 1; - if (selector > maxcol) - selector = maxcol; - this.index = this.index - this.Column () + selector; + var col, start, end + if (this.column > 0) + { + col = this.index % this.column; + start = this.index - col; + end = start + this.column; + } + else + { + start = this.blocks[this.row].Index; + col = this.index - start; + end = start + this.blocks[this.row].Count; + } + if (end > this.total) + end = this.total; + this.index += selector - col; + if (this.index >= end) + this.index = end - 1; + if (this.column > 0) + { + if (selector > col) + while (this.blocks[this.row].Index + this.blocks[this.row].Count + < this.index) + this.row++; + else + while (this.blocks[this.row].Index > this.index) + this.row--; + } return this.Current (); } -- 1.7.10.4