Files
NativeScript/tns-core-modules/text/formatted-string.ios.ts
Panayot Cankov 1236f66f44 Add npm script that generates ios .d.ts-es from the tests app
Less than 30 erros left, let's hope it still works

Added lib.*.d.ts from typescript, removed lib and dom stuff, added by hand XHR, alert etc. .d.ts-es for polyfills

Roll back some changes involved in separating UIEvent for dom and ios

Test combined dts-es will now use lib, while internally we will not to avoid UIEvent conflict with dom stuff
2016-08-29 09:58:17 +03:00

54 lines
2.6 KiB
TypeScript

import formattedStringCommon = require("./formatted-string-common");
import spanModule = require("text/span");
import types = require("utils/types");
global.moduleMerge(formattedStringCommon, exports);
export class FormattedString extends formattedStringCommon.FormattedString {
public createFormattedStringCore() {
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);
let attrDict = NSMutableDictionary.alloc<string, any>().init();
for (let p = 0; p < span.spanModifiers.length; p++) {
attrDict.setObjectForKey(span.spanModifiers[p].value, span.spanModifiers[p].key);
}
let nsAttributedString = NSMutableAttributedString.alloc().initWithStringAttributes(String(spanText), attrDict);
mas.insertAttributedStringAtIndex(nsAttributedString, spanStart);
spanStart += spanLength;
}
this._formattedText = mas;
}
public _updateCharactersInRangeReplacementString(rangeLocation: number, rangeLength: number, replacementString: string): void {
let deletingText = !replacementString;
let currentLocation = 0;
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)){
let newText = splice(span.text, rangeLocation - currentLocation, deletingText ? rangeLength : 0, replacementString);
span._setTextInternal(newText);
//console.log(`>>> ${span.text}`);
return;
}
currentLocation += span.text.length;
}
}
}
/*
* @param {String} value The string to splice.
* @param {number} start Index at which to start changing the string.
* @param {number} delCount An integer indicating the number of old chars to remove.
* @param {string} newSubStr The String that is spliced in.
* @return {string} A new string with the spliced substring.function splice(value: string, start: number, delCount: number, newSubStr: string) {
*/
function splice(value: string, start: number, delCount: number, newSubStr: string) {
return value.slice(0, start) + newSubStr + value.slice(start + Math.abs(delCount));
};