deleteOne method

dynamic deleteOne()

删除一个字符,一般用于键盘的删除键

Implementation

deleteOne(){
  realText = realText.length == 0 ? (value.text == hideChar * value.text.length ? CoolKeyboard.text: value.text):realText;
  if(selection.baseOffset == 0)
    return;
  String newText = '';
  if(selection.baseOffset != selection.extentOffset)
  {
    newText = selection.textBefore(text)  + selection.textAfter(text);
    realText = selection.textBefore(realText)  + selection.textAfter(realText);
    value = TextEditingValue(
        text: newText,
        selection: selection.copyWith(
            baseOffset:selection.baseOffset,
            extentOffset: selection.baseOffset)
    );
  }else{
    newText = text.substring(0,selection.baseOffset - 1) + selection.textAfter(text);
    realText = realText.substring(0,selection.baseOffset - 1) + selection.textAfter(realText);
    value = TextEditingValue(
        text: newText,
        selection: selection.copyWith(
            baseOffset:selection.baseOffset - 1,
            extentOffset: selection.baseOffset - 1)
    );
  }
}