devexpress-richedit
Version:
DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.
42 lines (41 loc) • 1.79 kB
JavaScript
import { Pair } from '@devexpress/utils/lib/class/pair';
import { BaseFormatter, StdProps } from './base-formatter';
import { SpanElement } from './elements';
export class ShortString {
constructor(str, shortLen = ShortString.SHORT_LEN) {
this.str = str;
this.setLen(shortLen);
}
get fullString() { return new SpanElement().setText("\"" + this.str + "\"").setColor(BaseFormatter.stringColor); }
get shortString() {
if (!this.canShowAsShort())
return this.fullString;
return new SpanElement()
.setNode(new SpanElement().setText("\"" + this.str.substr(0, this.halfOfShortLen) + "").setColor(BaseFormatter.stringColor))
.setNode(new SpanElement().setText("~").setColor(BaseFormatter.blackColor))
.setNode(new SpanElement().setText(this.str.substring(this.str.length - this.halfOfShortLen) + "\"").setColor(BaseFormatter.stringColor));
}
setLen(shortLen) {
this.halfOfShortLen = Math.floor(shortLen / 2);
return this;
}
canShowAsShort() {
return this.str.length > this.halfOfShortLen * 2;
}
}
ShortString.SHORT_LEN = 14;
export class CCF_ShortString extends BaseFormatter {
isHandleObject(obj) {
return obj instanceof ShortString;
}
getShortDescription(_config) {
return this.stdShow(new StdProps([new Pair("", this.curr.shortString)]).showAsLine().setBoundChars("", ""));
}
availableFullDescription(_config) {
return this.curr.canShowAsShort();
}
getFullDescription(_config) {
return this.stdShow(new StdProps([new Pair("", this.curr.fullString)]).showAsColumn());
}
}
CCF_ShortString._foo = BaseFormatter.addToFormattersList(new CCF_ShortString());