Skip to content

Commit 90b1282

Browse files
important autocomplete fixes
1 parent 7b159ff commit 90b1282

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"title": "Cache WEB Terminal",
44
"description": "Web-based terminal emulator for Caché administering.",
55
"author": "ZitRo",
6-
"version": "2.0.0-beta.4",
7-
"releaseNumber": "6",
6+
"version": "2.0.0-beta.5",
7+
"releaseNumber": "7",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/intersystems-ru/webterminal.git"
@@ -13,8 +13,8 @@
1313
"grunt": ">=0.4.5",
1414
"grunt-contrib-clean": ">=0.6.0",
1515
"grunt-contrib-concat": ">=0.5.0",
16-
"grunt-contrib-copy": ">=0.5.0",
16+
"grunt-contrib-copy": "^0.7.0",
1717
"grunt-contrib-uglify": ">=0.6.0",
18-
"grunt-preprocess": ">=4.0.0"
18+
"grunt-preprocess": "^4.1.0"
1919
}
20-
}
20+
}

webSource/js/TerminalAutocomplete.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TerminalAutocomplete.prototype.TYPES = {
6161
},
6262
subclass: {
6363
regExp: /##class\((%?[a-zA-Z]*[a-zA-Z0-9\.]*)\)\.(%?[a-zA-Z]*[a-zA-Z0-9]*)$/,
64-
priority: 1
64+
priority: 2
6565
},
6666
globals: {
6767
regExp: /\^(%?[a-z0-9A-Z]*)/
@@ -141,11 +141,14 @@ TerminalAutocomplete.prototype.getEndings = function (string) {
141141

142142
MAX_LENGTH = 60; // limit the AC length for performance reasons
143143

144-
string = string.substr(string.length - MAX_LENGTH, MAX_LENGTH);
145-
146-
// skip strings
144+
// skip autocomplete in strings
147145
if ((string.match(/"/g) || []).length % 2 === 1) return [];
148146

147+
string = string.substr(
148+
Math.max(string.length - MAX_LENGTH, 0),
149+
Math.min(MAX_LENGTH, string.length)
150+
);
151+
149152
for (i in this.TYPES) {
150153
matcher = this.TYPES[i].regExp || this.TYPES.common.regExp;
151154
trieString = (string.match(matcher) || []).slice(1).join("\n");
@@ -154,7 +157,7 @@ TerminalAutocomplete.prototype.getEndings = function (string) {
154157
variants = {};
155158
priority = this.TYPES[i].priority;
156159
this._appendEndings(variants, trieString, this.TYPES[i]);
157-
} else if (this.TYPES[i].priority || 0 === priority) {
160+
} else if ((this.TYPES[i].priority || 0) === priority) {
158161
this._appendEndings(variants, trieString, this.TYPES[i]);
159162
} // else do not append
160163
}

webSource/js/TerminalInput.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ var TerminalInput = function (TERMINAL) {
7575
* Shows the input beginning position.
7676
*
7777
* @type {{line: number, position: number}}
78-
* @private
7978
*/
8079
this.INITIAL_POSITION = {
8180
line: 0,
@@ -133,13 +132,10 @@ TerminalInput.prototype.focus = function () {
133132
*/
134133
TerminalInput.prototype.set = function (text) {
135134

136-
var element = this.TERMINAL.elements.input,
137-
length;
135+
var element = this.TERMINAL.elements.input;
138136

139137
element.value = text;
140-
length = element.value.length;
141-
this.setCaretPosition(length);
142-
//setTimeout(function() { _._onInput(); }, 1);
138+
this.setCaretPosition(element.value.length);
143139
this._onInput();
144140

145141
};
@@ -229,7 +225,7 @@ TerminalInput.prototype._changeAutocompleteVariant = function (delta) {
229225
this._currentAutocompleteVariant = (this._currentAutocompleteVariant + delta)
230226
% this._autocompleteVariants.length || 0;
231227
if (this._currentAutocompleteVariant < 0) this._currentAutocompleteVariant
232-
+= this._autocompleteVariants.length;
228+
+= this._autocompleteVariants.length || 0;
233229
this._updateAutocompleteView();
234230

235231
};
@@ -262,6 +258,7 @@ TerminalInput.prototype._updateAutocompleteView = function () {
262258
TerminalInput.prototype.clearAutocompleteVariants = function () {
263259

264260
this._autocompleteVariants = [];
261+
this._currentAutocompleteVariant = 0;
265262

266263
};
267264

@@ -290,6 +287,7 @@ TerminalInput.prototype._onInput = function () {
290287
this.TERMINAL.autocomplete.getEndings(
291288
value.substring(0, this.getCaretPosition())
292289
);
290+
this._changeAutocompleteVariant(0);
293291
}
294292

295293
this.TERMINAL.output.printAtLine(

webSource/js/TerminalInputHistory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ TerminalInputHistory.prototype.initialize = function () {
4040
if (event.keyCode === 38) { // UP
4141
_this.seek(-1);
4242
_this.INPUT.set(_this.getCurrent());
43+
event.preventDefault();
44+
event.cancelBubble();
4345
} else if (event.keyCode === 40) { // DOWN
4446
_this.seek(1);
4547
_this.INPUT.set(_this.getCurrent());
48+
event.preventDefault();
49+
event.cancelBubble();
4650
}
4751
});
4852

0 commit comments

Comments
 (0)