mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Additional refactoring and code cleanup
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
5
tns-core-modules/text/span.d.ts
vendored
5
tns-core-modules/text/span.d.ts
vendored
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user