* Support for textOverflow (e.g. "...") in TextView/EditTextView

* Show text starting from the begining when non-focus for long EditTextView
This commit is contained in:
Bryan Ashby 2015-05-07 22:13:12 -06:00
parent bd2253aec0
commit 62da937bf0
3 changed files with 25 additions and 4 deletions

View File

@ -28,6 +28,10 @@ function TextView(options) {
this.resizable = miscUtil.valueWithDefault(options.resizable, true); this.resizable = miscUtil.valueWithDefault(options.resizable, true);
this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true); this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true);
if(_.isString(options.textOverflow)) {
this.textOverflow = options.textOverflow;
}
if(_.isString(options.textMaskChar) && 1 === options.textMaskChar.length) { if(_.isString(options.textMaskChar) && 1 === options.textMaskChar.length) {
this.textMaskChar = options.textMaskChar; this.textMaskChar = options.textMaskChar;
} }
@ -50,8 +54,22 @@ function TextView(options) {
// XXXXXXXXXXXXXXXXX // XXXXXXXXXXXXXXXXX
// this is the text but too long // this is the text but too long
// text but too long // text but too long
if(this.horizScroll) { if(this.hasFocus) {
textToDraw = textToDraw.substr(textToDraw.length - this.dimens.width, textToDraw.length); if(this.horizScroll) {
textToDraw = textToDraw.substr(textToDraw.length - this.dimens.width, textToDraw.length);
}
} else {
// :TODO: support configurable textOverflow (default="")
if(textToDraw.length > this.dimens.width) {
if(this.textOverflow &&
this.dimens.width > this.textOverflow.length &&
textToDraw.length - this.textOverflow.length >= this.textOverflow.length)
{
textToDraw = textToDraw.substr(0, this.dimens.width - this.textOverflow.length) + this.textOverflow;
} else {
textToDraw = textToDraw.substr(0, this.dimens.width);
}
}
} }
} }
@ -82,7 +100,8 @@ TextView.prototype.setFocus = function(focused) {
this.redraw(); this.redraw();
// position & SGR for cursor // position & SGR for cursor
this.client.term.write(ansi.goto(this.position.x, this.position.y + this.text.length)); var offset = Math.min(this.text.length, this.dimens.width);
this.client.term.write(ansi.goto(this.position.x, this.position.y + offset));
this.client.term.write(this.getFocusSGR()); this.client.term.write(this.getFocusSGR());
}; };

View File

@ -188,6 +188,7 @@ function ViewController(options) {
setViewProp('focusTextStyle'); setViewProp('focusTextStyle');
setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); }); setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); });
setViewProp('justify'); setViewProp('justify');
setViewProp('textOverflow');
setViewProp('maxLength'); setViewProp('maxLength');

View File

@ -272,7 +272,8 @@
}, },
"ET2" : { "ET2" : {
"width" : 20, "width" : 20,
"maxLength" : 40 "maxLength" : 40,
"textOverflow" : "..."
}, },
"ET3" : { "ET3" : {
"width" : 20, "width" : 20,