Skip to main content

Bug fixes around undo/redo and copy/paste

I found a report of a case recently where Regex Hero would sporadically cause Chrome to crash. It was in a comment on StackOverflow, and I'm lucky to have found it. I didn't have much to go on, but I take reports like this seriously.

First of all, I had never seen this actually happen before. But I began by banging on things trying to make anything and everything break that I possibly could. My method is perhaps a bit crude and it simply takes time and some knowledge of what's going on in the code to get anywhere.

Here's what I managed to fix, in order of discovery:
  1. There was a layout problem involving the minimum vertical height of Regex Hero. After you shrink the window beyond a certain point a scroll bar appears so as not to fold the UI on top of itself. Well there was a logic problem in this calculation which could actually throw an error in certain circumstances. The error was being trapped though, and couldn't have caused the crash.
  2. The expand/collapse options button along the right hand side of the app had an unusual bug where, after clicking, the tooltip would be reused for other UI elements. I fixed it by using just one button rather than hiding/showing two different ones. Again, this was a weird bug but not one that could've caused the crash.
  3. Whenever you right click text and choose Cut/Copy/Paste, Regex Hero accesses the clipboard programmatically. On first use, this will throw a security warning from Silverlight (there's no way around that). The trouble is that if you choose not to allow Regex Hero access to the clipboard, Regex Hero would kind of fall on its face and not handle that condition gracefully. Again, an exception would be thrown, but it was caught and couldn't have caused anything to crash. I improved this process a bit and I now provide a follow up dialog.
  4. I took a couple days and came back to this. And just yesterday I finally reproduced the problem. The problem, it turns out, comes from another bug in the RichTextBox. And it's not isolated to Chrome. The same behavior occurs in IE9. Regex Hero was programmatically replacing line feeds with carriage returns when loading your previously stored text from isolated storage. I do this to ensure consistent behavior within the app. A separate string variable assigned to the text value of each textbox is then reshaped as necessary depending on if you have the CrLf option checked within Regex Hero. However, if you have more than 10 lines of text, then cut the top 9, then hit undo, the built-in undo functionality fails. The RichTextBox undo system seems to have a serious problem with carriage returns. It can't seem to fully restore from its history, only actually rendering 3 lines of text. The rendering pipeline then seems to be out of sync with what the text value actually equals. It's odd. And it causes Silverlight to freeze, sometimes bringing the whole browser down. I'm reporting this to Microsoft. My solution is to now replace all carriage returns with line feeds instead. Behind the scenes we have the same effect and the app works as it should, but it effectively avoids this bug.

Comments

Popular posts from this blog

Regex Hero for Windows 10 is Underway

Awhile back I began working on an HTML5 / JavaScript version of Regex Hero . However, it was a huge undertaking essentially requiring a complete rewrite of the entire application. I have not had enough time to dedicate to this lately. So I've begun again, this time rewriting Regex Hero to work in WPF. It'll be usable in Windows 10 and downloadable from the Microsoft Store. This is a much easier task that also has the advantage of running the .NET regex library from the application itself. This will allow for the same speedy experience of testing your regular expressions and getting instant feedback that Regex Hero users have always enjoyed. I expect the first release to be ready in Q4 of 2019.

Optimizing Your Regular Expressions

Regular expressions will backtrack.  That's an unfortunate thing about them because backtracking can be slow.    And in certain (rare) cases the performance can become so awful that executing the regular expression against a relatively short string could take over a minute.  There's a good article about catastrophic backtracking over at regular-expressions.info . And today I created a video about all of this called  Regex Lesson 5: Optimization .  In the video I start with a very poorly written regular expression and make several improvements to it, using the benchmarking feature along the way.  By the end of the video I make the regular expression over 3 million times faster. In addition, today's update to Regex Hero provides a little message in the event that you encounter a regular expression that takes over 10 seconds to evaluate... And then last of all, I changed the benchmarking feature a bit.  In the past it would simply test your regular expression against

Silverlight 4 Coming in April, or Maybe Sooner

The exact release date has not been announced. But Visual Studio 2010 RTM is coming out in April and I think it's safe to assume that Silverlight 4 will be released no later than that. Each release of Silverlight has brought massive improvements over the previous version. And once again, Silverlight 4 does not disappoint. There is a long list of improvements but the ones that I think that will affect Regex Hero are as follows: RichTextBox My plan is to use this in place of all 4 major textboxes in Regex Hero. The new RichTextBox has built-in multiple undos & redos, so I can ditch my home-brewed code. It should be nice to use for syntax highlighting for the regular expressions I intend to create. It also has a built-in API to determine the pixel position of the text. I should be able to use this API and build a new highlighting scheme based off of it. This should do a couple things. First, I should be able to finally fix the problem I had with the ScrollViewer and