BUG: Created some SQL which hangs Toad Editor

I wrote some string processing code for an app in SSMS, where it works fine. Deployed to the server - fine. Runs fine in production. Tried to open / edit it in Toad/SS - editor hangs. Tried to create a forum post containing the code in Toad/SS - editor hangs!

Some unexpectedly evil code! Creating this post in Chrome, where the code does not hang the editor:

USE [zcus]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

CREATE FUNCTION [dbo].[Iatric_TextCleaner]
(
@cString VARCHAR(MAX),
@cFont VARCHAR(50)
)
RETURNS VARCHAR(MAX)
AS

BEGIN;

DECLARE @position int, @newstring VARCHAR(MAX);
-- Initialize the variables.
SET @position = 1;
SET @newstring = ''

WHILE @position <= DATALENGTH(@cString)
BEGIN
SET @newstring = @newstring +
CASE
WHEN ASCII(SUBSTRING(@cString, @position, 1)) < 32 THEN ''
ELSE CHAR(ASCII(SUBSTRING(@cString, @position, 1)))
END
SET @position = @position + 1
END;
SET @newstring = RTRIM(LTRIM(
REPLACE(
REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE
(REPLACE(@newstring,@cFont+'4Bd','')
,@cFont+'4d',''),@cFont+'4Id',''),@cFont+'4Ud','')
,@cFont+'4B',''),@cFont+'4C','')
,'}',''),'{','')
,'|',''),@cFont+' 4d',''),@cFont+' 4Bd',''),@cFont+' 4Bg','')
,@cFont+' 4Id',''),@cFont+' 4Ud',''),@cFont+' 4BUb',''),@cFont+' 4C','')
,@cFont+' 5Id',''),@cFont+' 5Ud','')
,@cFont+' 4B','')
,@cFont+' 5d','')
))
;

RETURN @newstring ;

END ;
GO