* 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:
parent
bd2253aec0
commit
62da937bf0
|
@ -27,6 +27,10 @@ function TextView(options) {
|
|||
this.justify = options.justify || 'right';
|
||||
this.resizable = miscUtil.valueWithDefault(options.resizable, true);
|
||||
this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true);
|
||||
|
||||
if(_.isString(options.textOverflow)) {
|
||||
this.textOverflow = options.textOverflow;
|
||||
}
|
||||
|
||||
if(_.isString(options.textMaskChar) && 1 === options.textMaskChar.length) {
|
||||
this.textMaskChar = options.textMaskChar;
|
||||
|
@ -50,8 +54,22 @@ function TextView(options) {
|
|||
// XXXXXXXXXXXXXXXXX
|
||||
// this is the text but too long
|
||||
// text but too long
|
||||
if(this.horizScroll) {
|
||||
textToDraw = textToDraw.substr(textToDraw.length - this.dimens.width, textToDraw.length);
|
||||
if(this.hasFocus) {
|
||||
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();
|
||||
|
||||
// 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());
|
||||
};
|
||||
|
||||
|
|
|
@ -188,6 +188,7 @@ function ViewController(options) {
|
|||
setViewProp('focusTextStyle');
|
||||
setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); });
|
||||
setViewProp('justify');
|
||||
setViewProp('textOverflow');
|
||||
|
||||
setViewProp('maxLength');
|
||||
|
||||
|
|
|
@ -272,7 +272,8 @@
|
|||
},
|
||||
"ET2" : {
|
||||
"width" : 20,
|
||||
"maxLength" : 40
|
||||
"maxLength" : 40,
|
||||
"textOverflow" : "..."
|
||||
},
|
||||
"ET3" : {
|
||||
"width" : 20,
|
||||
|
|
Loading…
Reference in New Issue