浏览代码

Merge pull request #342 from wglios/dev

add WhitelistingTextInputFormatter
/main
GitHub 5 年前
当前提交
bca05469
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. 26
      Runtime/service/text_formatter.cs

26
Runtime/service/text_formatter.cs


}
}
public class WhitelistingTextInputFormatter : TextInputFormatter {
public WhitelistingTextInputFormatter(Regex whitelistedPattern) {
D.assert(whitelistedPattern != null);
this.whitelistedPattern = whitelistedPattern;
}
readonly Regex whitelistedPattern;
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
return Util._selectionAwareTextManipulation(
value: newValue,
substringManipulation: substring => {
string groups = "";
foreach (Match match in this.whitelistedPattern.Matches(input: substring)) {
groups += match.Groups[0].Value;
}
return groups;
}
);
}
public static readonly WhitelistingTextInputFormatter digitsOnly
= new WhitelistingTextInputFormatter(new Regex(@"\d+"));
}
static class Util {
internal static TextEditingValue _selectionAwareTextManipulation(TextEditingValue value,
Func<string, string> substringManipulation) {

正在加载...
取消
保存