Additional refactoring and code cleanup

This commit is contained in:
Rossen Hristov
2016-07-28 14:48:03 +03:00
parent 15d891cc08
commit 21926a95ea
8 changed files with 70 additions and 184 deletions

View File

@@ -6,22 +6,20 @@ global.moduleMerge(formattedStringCommon, exports);
export class FormattedString extends formattedStringCommon.FormattedString {
public createFormattedStringCore() {
var mas = NSMutableAttributedString.alloc().init();
var i;
var spanStart = 0;
var spanLength = 0;
var spanText = "";
for (i = 0; i < this.spans.length; i++) {
var span = <spanModule.Span>this.spans.getItem(i);
let mas = NSMutableAttributedString.alloc().init();
let spanStart = 0;
let spanLength = 0;
let spanText = "";
for (let i = 0; i < this.spans.length; i++) {
let span = <spanModule.Span>this.spans.getItem(i);
spanText = types.toUIString(span.text);
spanLength = spanText.length;
span.updateSpanModifiers(this);
var attrDict = NSMutableDictionary.alloc().init();
var p;
for (p = 0; p < span.spanModifiers.length; p++) {
let attrDict = NSMutableDictionary.alloc().init();
for (let p = 0; p < span.spanModifiers.length; p++) {
attrDict.setObjectForKey(span.spanModifiers[p].value, span.spanModifiers[p].key);
}
var nsAttributedString = NSMutableAttributedString.alloc().initWithStringAttributes(String(spanText), attrDict);
let nsAttributedString = NSMutableAttributedString.alloc().initWithStringAttributes(String(spanText), attrDict);
mas.insertAttributedStringAtIndex(nsAttributedString, spanStart);
spanStart += spanLength;
}
@@ -34,7 +32,8 @@ export class FormattedString extends formattedStringCommon.FormattedString {
for (let i = 0; i < this.spans.length; i++) {
let span = <spanModule.Span>this.spans.getItem(i);
if (currentLocation <= rangeLocation && rangeLocation < (currentLocation + span.text.length)){
(<any>span)._text = splice(span.text, rangeLocation - currentLocation, deletingText ? rangeLength : 0, replacementString);
let newText = splice(span.text, rangeLocation - currentLocation, deletingText ? rangeLength : 0, replacementString);
span._setTextInternal(newText);
//console.log(`>>> ${span.text}`);
return;
}

View File

@@ -140,11 +140,15 @@ export class Span extends bindable.Bindable implements definition.Span, view.App
set text(value: string) {
if (this._text !== value) {
this._text = value;
this._setTextInternal(value);
this.updateAndNotify();
}
}
_setTextInternal(value: string): void {
this._text = value;
}
get parentFormattedString(): formattedString.FormattedString {
return this._parentFormattedString;
}

View File

@@ -72,5 +72,10 @@
* Ends the process previously initiated by beginEdit and updates the span modifiers collection.
*/
public endEdit(): void;
//@private
_setTextInternal(value: string): void;
//@endprivate
}
}