public void TextRemoved(string text, MyEditor editor, TextPoint position) { AddEditorSignal(editor); redoList.Clear(); //If this and the two previous can be joined into 1 token, join them in 1 undo (if they follow eachother) UndoItem item = new UndoItem(text, editor, position, UndoType.TextRemoved); if (undoList.Count > 0) { UndoItem lastItem = undoList[undoList.Count - 1]; if (FollowEachother(item, lastItem)) { string joined = item.text + lastItem.text; Lexer lexer = new Lexer(new StringReader(joined)); List<Token> tokens = new List<Token>(); while (!(lexer.Peek() is EOF)) { tokens.Add(lexer.Next()); } if (tokens.Count == 1 || tokens.All(elm => elm is TWhiteSpace)) { lastItem.text = joined; lastItem.position = item.position; item = lastItem; if (undoList.Count > 1) { lastItem = undoList[undoList.Count - 2]; if (FollowEachother(item, lastItem)) { joined = item.text + lastItem.text; lexer = new Lexer(new StringReader(joined)); tokens = new List<Token>(); while (!(lexer.Peek() is EOF)) { tokens.Add(lexer.Next()); } if (tokens.Count == 1 || tokens.All(elm => elm is TWhiteSpace)) { lastItem.text = joined; lastItem.position = item.position; undoList.RemoveAt(undoList.Count - 1); } } } return; } } } undoList.Add(item); }