Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TextBox.prototype.addCharacter = function (chr) {
- var startStr = "";
- if (this.caretPos > 0) {
- startStr = this.curText.substr(0, this.caretPos);
- }
- var endStr = "";
- if (this.caretPos < this.curText.length) {
- endStr = this.curText.substr(this.caretPos, (this.curText.length - this.caretPos));
- }
- this.curText = startStr + chr + endStr;
- this.caretPos += 1;
- var curTotalLength = UI.measureString(this.curText);
- if (curTotalLength <= 230) {
- this.visibleText = this.curText;
- this.visibleTextStart = 0;
- } else {
- if (this.caretPos === this.curText.length) {
- this.visibleText += chr;
- while (UI.measureString(this.visibleText) > 230) {
- this.visibleText = this.visibleText.substr(1, this.visibleText.length - 1);
- this.visibleTextStart += 1;
- }
- } else if ((this.caretPos - this.visibleTextStart) >= this.visibleText.length) {
- var add = Math.min(this.curText.length - this.visibleTextStart - this.visibleText.length, 3);
- var endIndex = this.visibleTextStart + this.visibleText.length + add;
- this.visibleText = this.curText.substr(this.visibleTextStart, endIndex - this.visibleTextStart);
- while (UI.measureString(this.visibleText) > 230) {
- this.visibleTextStart += 1;
- this.visibleText = this.curText.substr(this.visibleTextStart, endIndex - this.visibleTextStart);
- }
- } else {
- this.visibleText = this.curText.substr(this.visibleTextStart, Math.min(this.curText.length - this.visibleTextStart, this.visibleText.length + 5));
- while (UI.measureString(this.visibleText) > 230) {
- this.visibleText = this.visibleText.substr(0, this.visibleText.length - 1);
- }
- }
- }
- this.updatecaret();
- }
Advertisement
Add Comment
Please, Sign In to add comment